format.html {
@scroll = @item
if @operators.author
- @new_panel_items = assist_items('panel', 'private_list')
+ @new_panel_items = assist_items('panel', 'private')
#@new_panel_filer = assist_filer 'panel', @new_panel_items
end
}
def show_html_format format
format.html {
if @operators.author
- @new_panel_items = assist_items('panel', 'private_list')
+ @new_panel_items = assist_items('panel', 'private')
#new_panel_filer = assist_filer 'panel', @new_panel_items
- @new_story_items = assist_items('story', 'private_list')
+ @new_story_items = assist_items('story', 'private')
#new_story_filer = assist_filer 'story', @new_story_items
- @fresh_story_items = assist_items('story_sheet', 'private_list').map {|ss| ss.story}
+ @fresh_story_items = assist_items('story_sheet', 'private').map {|ss| ss.story}
#@fresh_story_filer = assist_filer 'story', @fresh_story_items
end
}
def show_html_format format
format.html {
if @operators.author
- @new_sheet_items = assist_items('sheet', 'private_list')
+ @new_sheet_items = assist_items('sheet', 'private')
#@new_sheet_filer = assist_filer 'sheet', @new_sheet_items
end
}
class Artist < Peta::Owner
+ load_manifest
belongs_to :user
has_many :original_pictures
has_many :pictures
validates :user_id, :numericality => true, :existence => {:both => false}
validates :provider_id, :numericality => {:allow_nil => true}
- def self.valid_encode_columns
- super + ['name']
- end
-
def self.visible_count_options
{:conditions => ['artists.author_id is not null']}
end
class Author < Peta::Owner
+ load_manifest
belongs_to :user
has_many :scrolls
has_many :comics
validates :working_panel_id, :numericality => {:allow_nil => true}
validates :user_id, :numericality => true, :existence => {:both => false}
- def self.valid_encode_columns
- super + ['name']
- end
-
def supply_default
self.name = 'no name' if self.name.blank?
end
class Balloon < Peta::Content
+ load_manifest
include Peta::ElementPart
belongs_to :speech_balloon
belongs_to :system_picture
# validates :caption, :presence => true
validates :settings, :extend_balloon => true
- def owner_model
- self.speech_balloon.panel
- end
-
- def self.valid_encode_columns
- super + ['settings']
- end
-
def self.colum_structures
@@colum_structures ||= {
:r => {
{:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}}
end
+ def style
+ {
+ 'width' => self.width.to_s + 'px','height' => self.height.to_s + 'px',
+ 'top' => self.y.to_s + 'px','left' => self.x.to_s + 'px'
+ }
+ end
+
def copy_attributes
r = self.attributes
r.delete 'id'
#コミック
class Comic < Peta::Content
+ load_manifest
has_many :stories, :order => 't'
belongs_to :author
validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
- def self.valid_encode_columns
- super + ['title', 'description']
- end
-
def self.visible_count_options
{:conditions => 'visible > 0'}
end
-class GroundColor < Peta::Content
- include Peta::Element
+class GroundColor < Peta::Element
+ load_manifest
include ElementInspire
belongs_to :panel
belongs_to :color
validates :z, :presence => true, :numericality => {:greater_than => 0}
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
- def self.owner_model
- Panel
- end
-
- def self.valid_encode_columns
- super + ['caption']
- end
-
def self.colum_structures
@@colum_structures ||= {
:code => {
end
end
- def opt_div_style spot = nil, opacity = 20
- o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
- "position: absolute; left:#{self.div_x}%; top:#{self.div_y}%; width:#{self.div_width}%; height:#{self.div_height}%; z-index:#{self.z}; background-color:##{format("%06x", self.code)}; #{o}"
+ def style spot = nil, opacity = 20
+ r = {
+ 'position' => 'absolute', 'z-index' => self.z,
+ 'top' => self.div_y.to_s + '%', 'left' => self.div_x.to_s + '%',
+ 'width' => self.div_width.to_s + '%', 'height' => self.div_height.to_s + '%',
+ 'background-color' => '#' + format("%06x", self.code)
+ }
+ self.merge_opacity(r, opacity) if spot and spot != self
+ r
end
def boost
-class GroundPicture < Peta::Content
- include Peta::Element
+class GroundPicture < Peta::Element
+ load_manifest
include ElementInspire
belongs_to :panel
belongs_to :picture
@@repeat_texts = ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']
- def self.owner_model
- Panel
- end
-
- def self.valid_encode_columns
- super + ['caption']
- end
-
def self.list_opt_for_panel
{
:ground_pictures => {
self.owner_model.visible? operators
end
- def opt_div_style full_url, spot = nil, opacity = 20
- o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
- "position: absolute; width:#{self.get_panel.width}px; height:#{self.get_panel.height}px; top: 0px; left: 0px; z-index:#{self.z}; background-image: url(#{full_url}); background-repeat: #{self.repeat_text}; background-position: #{self.x}px #{self.y}px; #{o}"
+ def style spot = nil, opacity = 20
+ r = {
+ 'position' => 'absolute', 'top' => '0px', 'left' => '0px', 'z-index' => self.z,
+ 'background-image' => "url(#{self.picture.url})",
+ 'background-repeat' => self.repeat_text,
+ 'background-position' => "#{self.x}px #{self.y}px"
+ }
+ self.merge_opacity(r, opacity) if spot and spot != self
+ r
end
def tmb_opt_img_tag
#
class License < Peta::Item
+ load_manifest
belongs_to :license_group
belongs_to :system_picture
has_many :resource_pictures
validates :url, :presence => true, :length => {:maximum => 200}, :uniqueness => true, :url => {:message => I18n.t('errors.messages.url')} #{:allow_blank => true}
validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
- def self.valid_encode_columns
- super + ['name', 'caption', 'url', 'settings', 'credit_pictures']
- end
-
def supply_default
end
#ライセンスグループ
class LicenseGroup < Peta::Item
+ load_manifest
has_many :licenses
validates :name, :presence => true, :length => {:maximum => 50}, :uniqueness => true
validates :caption, :presence => true, :length => {:maximum => 30}
validates :url, :presence => true, :length => {:maximum => 200}, :url => {:message => I18n.t('errors.messages.url')}
- def self.valid_encode_columns
- super + ['name', 'classname', 'caption', 'url']
- end
-
def supply_default
end
class OriginalPicture < Peta::Content
+ load_manifest
belongs_to :artist
belongs_to :original_picture_license_group
has_one :resource_picture
validates :artist_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :md5, :presence => true, :length => {:minimum => 32, :maximum => 32}
- def self.owner_type
- :artist
- end
-
def supply_default
end
#コマ
class Panel < Peta::Content
+ load_manifest
belongs_to :author
has_many :scroll_panels
has_many :sheet_panels
self.publish > 0
end
+ # ground_picture element template
+ def style_wh
+ {
+ 'width' => self.width.to_s + 'px', 'height' => self.height.to_s + 'px'
+ }
+ end
+
def tag_id c = nil
'panel' + self.tag_panel_id + c.to_s
end
-class PanelPicture < Peta::Content
- include Peta::Element
+class PanelPicture < Peta::Element
+ load_manifest
include ElementInspire
belongs_to :panel
belongs_to :picture
validates :z, :presence => true, :numericality => {:greater_than => 0}
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
- def self.owner_model
- Panel
- end
-
- def self.valid_encode_columns
- super + ['link', 'caption']
- end
-
def self.colum_structures
@@colum_structures ||= {
:width => {
def opt_img_tag spot = nil, opacity = 20
o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
- {:id => self.tag_id(:img), :panel_id => self.tag_panel_id, :element_id => self.tag_element_id, :element_type => self.tag_element_type,
- :class => "panel-picture", :vPicture => self.id,
- :src => self.url, :width => self.width.abs, :height => self.height.abs, :picture_id => self.picture_id, :ext => self.picture.ext, :alt => self.caption,
- :style => "#{o}"}
+ self.tag_attributes(:img, {
+ :class => "panel-picture", :vPicture => self.id,
+ :src => self.url, :width => self.width.abs, :height => self.height.abs, :picture_id => self.picture_id, :ext => self.picture.ext, :alt => self.caption,
+ :style => "#{o}"
+ })
end
def tmb_opt_img_tag
#実素材
class Picture < Peta::Content
+ load_manifest
belongs_to :original_picture
belongs_to :license
belongs_to :artist
validates :artist_name, :presence => true
validates :classname, :presence => true, :length => {:maximum => 50}
- def self.owner_type
- :artist
- end
-
- def self.valid_encode_columns
- super + ['artist_name', 'classname', 'credit', 'settings']
- end
-
def supply_default
end
#素材
class ResourcePicture < Peta::Content
+ load_manifest
belongs_to :artist
belongs_to :license
belongs_to :picture
validates :classname, :presence => true, :length => {:maximum => 50}
validates :picture_id, :presence => true, :numericality => true, :existence => {:both => false}
- def self.owner_type
- :artist
- end
-
- def self.valid_encode_columns
- super + ['artist_name', 'classname', 'credit', 'settings']
- end
-
def supply_default
end
class Scroll < Peta::Content
+ load_manifest
has_many :scroll_panels
belongs_to :author
validates :title, :presence => true, :length => {:maximum => 100}
validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
-
- def self.valid_encode_columns
- super + ['title']
- end
-
def supply_default
self.visible = 0 if self.visible.blank?
end
{:include => {:scroll_panels => {:include => {:panel => {}}}, :author => {}}}
end
- def tag_attributes column = nil, opt = {}
- {
- }
- end
-
def self.visible_count
Scroll.count 'visible > 0'
end
-class ScrollPanel < Peta::Content
+class ScrollPanel < Peta::Element
+ load_manifest
belongs_to :author
belongs_to :panel
belongs_to :scroll
}
end
- def self.owner_model
- Scroll
- end
-
def supply_default
self.scroll_id = nil
self.panel_id = nil
class Sheet < Peta::Content
+ load_manifest
has_many :sheet_panels
has_many :story_sheets
belongs_to :author
validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
accepts_nested_attributes_for :sheet_panels, :allow_destroy => true
- def self.valid_encode_columns
- super + ['caption']
- end
-
def self.each_element_class_names
{'SheetPanel' => 'sheet_panels'}.each do |k, n|
yield k
-class SheetPanel < Peta::Content
+class SheetPanel < Peta::Element
+ load_manifest
belongs_to :author
belongs_to :panel
belongs_to :sheet
validates :z, :presence => true, :numericality => {:greater_than => 0}
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
- def self.owner_model
- Sheet
- end
-
def supply_default
self.x = 15
self.y = 15
class Speech < Peta::Content
+ load_manifest
include Peta::ElementPart
belongs_to :speech_balloon
belongs_to :writing_format
@@text_align_texts = ['left', 'left', 'right', 'center']
- def owner_model
- self.speech_balloon.panel
- end
-
- def self.valid_encode_columns
- super + ['content', 'quotes', 'settings']
- end
-
def self.colum_structures
@@colum_structures ||= {
:fore_color => {
'speech'
end
+ def outer_style
+ {
+ 'top' => self.y, 'left' => self.x,
+ 'width' => self.width, 'height' => self.height
+ }
+ end
+
+ def inner_style
+ {
+ 'font-size' => self.font_size.to_s + 'em',
+ 'text-align' => self.text_align_text,
+ 'color' => '#' + format("%06x", self.fore_color)
+ }
+ end
+
def text_align_text
@@text_align_texts[self.text_align]
end
-class SpeechBalloon < Peta::Content
- include Peta::Element
+class SpeechBalloon < Peta::Element
+ load_manifest
include ElementInspire
has_one :balloon, :dependent => :destroy
has_one :speech, :dependent => :destroy
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
validates :settings, :extend_speech_balloon => true
- def self.owner_model
- Panel
- end
-
- def self.valid_encode_columns
- super + ['caption', 'classname', 'settings']
- end
-
def self.list_opt_for_panel
{
:speech_balloons => {:balloon => {}, :speech => {}}
#フキダシテンプレート
class SpeechBalloonTemplate < Peta::Item
+ load_manifest
has_many :speech_balloons
belongs_to :system_picture
validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :settings, :presence => true
- def self.valid_encode_columns
- super + ['name', 'classname', 'caption', 'settings']
- end
-
def supply_default
end
#ストーリー
class Story < Peta::Content
+ load_manifest
has_many :story_sheets
belongs_to :comic
}
end
- def self.owner_model
- Comic
- end
-
- def self.valid_encode_columns
- super + ['title', 'description']
- end
-
def supply_default
self.comic_id = nil
self.visible = 0 if self.visible.blank?
-class StorySheet < Peta::Content
+class StorySheet < Peta::Element
+ load_manifest
belongs_to :author
belongs_to :story
belongs_to :sheet
}
end
- def self.owner_model
- Story
- end
-
def supply_default
self.story_id = nil
self.sheet_id = nil
class SystemPicture < Peta::Item
+ load_manifest
has_many :balloons
has_many :speech_balloon_templates
has_many :licenses
class WritingFormat < Peta::Item
+ load_manifest
has_many :speeches
belongs_to :system_picture
validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :settings, :presence => true
- def self.valid_encode_columns
- super + ['name', 'classname', 'caption', 'settings']
- end
-
def supply_default
end
-<div <%= raw elm.any_tag_attr() -%> class="pettanr-comic-ground-color" style="<%= elm.opt_div_style(spot) -%>">
+<%= content_tag :div, element.tag_attributes(:div, {'class' => "pettanr-comic-ground-color", 'style' => raw(element.style(spot).to_style)}) do %>
-</div>
+<% end %>
-<div <%= raw elm.any_tag_attr() -%> class="pettanr-comic-ground-picture" style="<%= elm.opt_div_style(full_url(elm.picture.url), spot) -%>">
+<%= content_tag :div, element.tag_attributes(:div, {'class' => "pettanr-comic-ground-picture", 'style' => raw(element.style(spot).merge(root.style_wh).to_style)}) do %>
-</div>
+<% end %>
-<div <%= raw elm.any_tag_attr(:div) -%> class="pettanr-panel-picture-wrapper" style="<%= elm.opt_div_style() -%>">
- <%= link_to_unless(elm.link.blank?, tag(:img, elm.opt_img_tag(spot)), elm.link) %>
-</div>
+<%= content_tag :div, element.tag_attributes(:div, {'class' => "pettanr-panel-picture-wrapper", 'style' => element.opt_div_style()}) do %>
+ <%= link_to_unless(element.link.blank?, tag(:img, element.opt_img_tag(spot)), element.link) %>
+<% end %>
-<% panel.panel_elements.each do |elm| %>
- <% case elm.class.to_s %>
- <% when 'SpeechBalloon' %>
- <% elm.boost %>
- <% end %>
-<% end %>
<%= content_tag :div, :id => panel.tag_id, :panel_id => panel.tag_panel_id, :class => "pettanr-comic-panel", :style => "width: #{panel.width}px; height: #{panel.height}px; border-style: solid; border-width: #{panel.border}px; border-color: black; background-color: white;" do %>
<% if panel.visible? operators -%>
- <% panel.panel_elements.each do |elm| %>
- <%= render elm.class.to_s.tableize + '/element', :elm => elm, :spot => spot %>
+ <% panel.panel_elements.each do |element| %>
+ <%= render element.path_name + '/element', :element => element, :root => panel, :spot => spot %>
<% end %>
<% else %>
<h2><%= t('panels.hidden') %></h2>
-<div <%= raw elm.any_tag_attr() -%> balloon_id="<%= elm.balloon.tag_element_part_id -%>" speech_id="<%= elm.speech.tag_element_part_id -%>" class="pettanr-comic-balloon" style="width:<%= elm.balloon.width -%>px; height:<%= elm.balloon.height -%>px; top:<%= elm.balloon.y -%>px; left:<%= elm.balloon.x -%>px; z-index:<%= elm.z -%>; ">
- <img <%= raw elm.balloon.tag_attr -%> class="pettanr-balloon" src="<%= elm.balloon.system_picture.url -%>" alt="<%= elm.caption -%>">
- <div class="pettanr-comic-speech" style="top:<%= elm.speech.y -%>%; left:<%= elm.speech.x -%>%;width:<%= elm.speech.width -%>%; height:<%= elm.speech.height -%>%;">
- <div class="pettanr-comic-speech-inner" <%= raw elm.speech.tag_attr -%> style="font-size:<%= elm.speech.font_size -%>em; text-align:<%= elm.speech.text_align_text -%>; color:#<%= format("%06x", elm.speech.fore_color) -%>;">
- <%= raw elm.speech.writing_format.engine_model.render(elm.speech.content) -%>
- </div>
- </div>
-</div>
+<%= content_tag :div, element.tag_attributes(:div, {'class' => "pettanr-comic-balloon", 'style' => raw(element.balloon.style.merge({'z-index' => element.z}).to_style)}) do %>
+ <%= tag :img, element.balloon.tag_attributes(nil, {'class' => "pettanr-balloon", 'src' => element.balloon.system_picture.url, 'alt' => element.caption}) %>
+ <%= content_tag :div, {'class' => "pettanr-comic-speech", 'style' => raw(element.speech.outer_style.to_style)} do %>
+ <%= content_tag :div, element.speech.tag_attributes(nil, {'class' => "pettanr-comic-speech-inner", 'style' => raw(element.speech.inner_style.to_style)}) do %>
+ <%= raw element.speech.writing_format.engine_model.render(element.speech.content) -%>
+ <% end %>
+ <% end %>
+<% end %>
require_dependency 'manifest'
require_dependency 'editor/editor'
Manifest.manifest.init
+Manifest.manifest.load_models_manifest
def to_attr
self.map {|k, n| "#{k}=\"#{n}\"" }.join(' ')
end
+
+ def to_style
+ self.map {|k, n| "#{k}: #{n}" }.join('; ')
+ end
+
end
class Editor
include EditorModule
-
+ cattr_accessor :eid
+ @@eid = 0
class Generator
def initialize editor
@editor = editor
attr_accessor :root_item, :dock, :generator, :operators
def initialize root_item, operators
+ @@eid += 1
@root_item = root_item
@operators = operators
@dock = self.new_dock
+ @pool = Pool.new self, @root_item
@generator = Generator.new self
+ @@eid = 0 if @@eid > 0x7fffff
end
#InstanceMethods
+ def name
+ 'owner'
+ end
+
+ def eid
+ @@eid
+ end
+
def new_dock
Dock.new self
end
self.template_dir + self.template_file_name
end
+ def register
+ @root_item.editor = self
+ @root_item.each_elements(self.name) do |element|
+ element.editor = self
+ element.parent = @root_item
+ end
+ end
+
+ def eid
+ 'editor-' + @@eid.to_s
+ end
+
def dom_id
'editor-' + @root_item.id.to_s
end
require_dependency "editor/panel_dock/panel_dock"
module Editor
class PanelEditor < Editor
+ def name
+ 'panel'
+ end
+
def new_dock
PanelDock.new self
end
--- /dev/null
+module Editor
+ module EditorModule
+ class Pool
+ attr_accessor :editor, :root_item, :pool, :index
+ def initialize editor, root_item
+ @editor = editor
+ @root_item = root_item
+ @pool = {}
+ @index = 1
+ self.editize
+ end
+
+ # regist stored element
+ def editize
+ self.register @root_item
+ @root_item.each_elements(self.name) do |element|
+ self.register element
+ end
+ end
+
+ def register item
+ @item.editor = @editor
+ parent_model = item.parent_model(@editor.name)
+ if parent_model
+ item.parent = find
+ end
+ if item.new_record?
+ if parent_model
+ # element
+ item.parent__send__ "build_#{parent_model.child_element_name(item.item_name)}"
+ else
+ # root
+
+ end
+ item.pool_id = @index
+ @index += 1
+ else
+ item.pool_id = item.id
+ end
+ @pool[item.item_name] ||= {'stored' => {}, 'new' => {}}
+ @pool[item.item_name][item.dom_pool_type] ||= {}
+ @pool[item.item_name][item.dom_pool_type][item.pool_id] = item
+ end
+
+ def unregister item
+
+ end
+
+ end
+
+ end
+end
end
- class TextTag < Base
- end
-
- class NumberTag < Base
- end
-
- class TextAreaTag < Base
- end
-
- class SelectTag < Base
- end
-
- class HiddenTag < Base
- end
-
end
end
end
@form.mounted ? 0 : 1
end
+ def mount_option
+ {'mount' => self.mounted}
+ end
+
def item
@form.item
end
end
def options tag_options = {}
- self.item.field_tag_attributes(@field_manifest.column_name, self.mounted, tag_options)
+ self.item.field_tag_attributes(@field_manifest.column_name, tag_options).merge(self.mount_option)
end
def form_field_name
@system_resources.init
end
+ def load_models_manifest
+ @models.each do |model_name, model|
+ model.classify.load_manifest
+ end
+ end
+
+ def add_action
+ return
+ @controllers.each do |controller_name, controller|
+ model_name = controller.model_name
+ next if model_name.blank?
+ controller.actions.each do |action_name, conf|
+ next unless conf['type'] == 'list'
+ list_name = conf['list']['list_name']
+ list = Pettanr::Application::manifest.list_managers[model_name]
+ list.add_action action_name, list_name
+ end
+ end
+ end
+
end
module ModuleMethods
::Manifest.item_name_to_model @model_name
end
+ def table_name
+ self.classify.table_name
+ end
+
+ def valid_encode_columns
+ r = []
+ @attributes.each {|attribute_name, attribute|
+ next unless attribute.type == 'text'
+ r << attribute_name
+ }
+ r
+ end
+
+ def owner_type
+ return :author if @attributes['author_id']
+ return :artist if @attributes['artist_id']
+ false
+ end
+
+ def content_model
+ return true if self.owner_type
+ false
+ end
+
+ def each_child_model_manifest tree_name
+ ::Manifest.models.each {|child_model_name, child_model_manifest|
+ next unless child_model_manifest.tree[tree_name]
+ next unless child_model_manifest.tree[tree_name].parent_model_name == @model_name
+ yield child_model_manifest
+ }
+ end
+
+ def child_models tree_name
+ r = []
+ self.each_child_model_manifest(tree_name) {|child_model_manifest|
+ r << child_model_manifest.classify
+ }
+ r
+ end
+
+ def child_element_names tree_name
+ r = []
+ self.each_child_model_manifest(tree_name) {|child_model_manifest|
+ # has_one ?
+ r << self.associations.child_element_name(child_model_manifest.model_name)
+ }
+ r
+ end
+
end
end
@model.model_manifest
end
+ def child_element_name child_item_name
+ if @has_one[child_item_name]
+ child_model_manifest.model_name
+ else
+ child_model_manifest.table_name
+ end
+ end
+
end
end
end
end
+ def parent_model
+ self.parent_model_manifest.classify
+ end
+
def model_manifest
@model.model_manifest
end
module Peta
class Content < Item
self.abstract_class = true
- # ClassMethods
- def self.owner_model
- nil
+ # Dynamic Methods
+
+ def self._content?
+ self.my_manifest.content_model
end
- def self.owner_type
- :author
+ def self._owner_type
+ self.my_manifest.owner_type
end
- def self.content?
- true
+ def self._owner_model
+ t = self.my_manifest.tree['owner']
+ return nil unless t
+ t.parent_model
end
- def self.operator operators
- case self.owner_type
- when :author
- operators.author
- when :artist
- operators.artist
- else
- nil
+ def self._owner_column
+ self.owner_type.to_s + '_id'
+ end
+
+ def self.load_manifest
+ super
+ # Class Methods
+ f = self._content?
+ define_singleton_method("content?") do
+ f
+ end
+ t = self._owner_type
+ define_singleton_method("owner_type") do
+ t
+ end
+ m = self._owner_model
+ define_singleton_method("owner_model") do
+ m
+ end
+ define_singleton_method("parent_model") do |tree_name|
+ self.my_manifest.tree[tree_name].parent_model
+ end
+ o = self._owner_column
+ define_singleton_method("owner_column") do
+ o
+ end
+ define_singleton_method("child_models") do |tree_name|
+ self.my_manifest.child_models tree_name
+ end
+ # Instance Methods
+ define_method("parent_model") do |tree_name|
+ self.__send__ self.class.parent_model(tree_name).item_name
+ end
+ define_method("elements") do |tree_name|
+ self.my_manifest.child_element_names(tree_name).map {|element_name|
+ self.__send__ element_name
+ }
end
end
- def self.owner_column
- self.owner_type.to_s + '_id'
+ # Class Methods
+
+ def self.operator operators
+ return nil unless self.owner_type
+ operators.__send__ self.owner_type
end
def self.public_list_where
raise ActiveRecord::Forbidden unless content.own?(operators)
content
end
-
- #InstanceMethods
+ # Instance Methods
def owner_model
self.class.owner_model ? self.__send__(self.class.owner_model.item_name) : self
module Peta
- module Element
- def self.included(base)
- base.extend(ClassMethods)
- base.__send__ :include, InstanceMethods
+ class Element < Content
+ self.abstract_class = true
+
+ # Dynamic ClassMethods
+
+
+ def self.list_opt_for_panel
+ {}
+ end
+
+ def self.show_opt_for_panel
+ {}
+ end
+
+ def self.json_opt_for_panel
+ {}
+ end
+
+ def has_picture?
+ false
+ end
+
+ def has_part?
+ false
+ end
+
+ def parts
+ @parts ||= []
end
- module ClassMethods
- def colum_structures
- raise
- end
-
- def list_opt_for_panel
- {}
- end
-
- def show_opt_for_panel
- {}
- end
-
- def json_opt_for_panel
- {}
- end
-
- def path_name with_engine = false
- self.to_s.tableize
- end
-
+ def extend_column
+ nil
end
- module InstanceMethods
- private
-
- public
-
- def has_picture?
- false
- end
-
- def has_part?
- false
- end
-
- def parts
- @parts ||= []
- end
-
- def has_helper? column_name
- self.class.colum_structures[column_name] and self.class.colum_structures[column_name][:helper]
- end
-
- def element_name
- self.class.to_s.underscore
- end
-
- def extend_column
- nil
- end
-
- def extend_element_name
- self.extend_column ? self.attributes[extend_column] : self.element_name
- end
-
- def find_configurations hash, key
- if hash[key].is_a? String
- self.find_configurations hash, hash[key]
- else
- return hash[key]
- end
- end
-
- def element_index
- @element_index ||= self.t
- end
-
- def parent
- @parent ||= self.panel
- end
-
- def parent= content
- @parent = content
- end
-
- def new_index
- @new_index
- end
-
- def new_index= v
- @new_index = v
- end
-
- def new_panel
- @new_panel
- end
-
- def new_panel= v
- @new_panel = v
- end
-
- def get_panel
- self.panel || @new_panel
- end
-
- def tag_id c = nil
- 'panel' + self.tag_panel_id + self.tag_element_type + self.tag_element_id + c.to_s
- end
-
- def field_tag_id f
- self.tag_id + f.to_s
- end
-
- def tag_panel_id
- self.get_panel.new_record? ? '0' : self.get_panel.id.to_s
- end
-
- def tag_element_id
- self.new_record? ? '0' : self.id.to_s
- end
-
- def tag_element_type
- raise
- end
-
- def tag_new_index
- self.new_index.to_s
- end
-
- def path_name with_engine = false
- self.class.path_name(with_engine)
- end
-
- def form_template with_engine = false
- self.path_name(with_engine) + '/form'
- end
-
- def scenario_template with_engine = false
- self.path_name(with_engine) + '/scenario'
- end
-
- def element_face_template with_engine = false
- self.path_name(with_engine) + '/element_face'
- end
-
- def form_helper_template(colum_name)
- self.class.colum_structures[colum_name][:helper]
- end
-
- def tag_attributes column = nil, opt = {}
- {
- :id => self.field_tag_id(column), :panel_id => self.tag_panel_id,
- :element_id => self.tag_element_id, :element_type => self.tag_element_type
- }.merge(opt)
- end
-
- def field_tag_attributes column, no_attr, opt = {}
- self.tag_attributes(column).merge(
- {:column => column, :new_index => self.tag_new_index, :no_attr => no_attr}
- ).merge(opt)
- end
-
- #render element by body
- def any_tag_attributes name = nil, opt = {}
- r = self.tag_attributes(name)
- r.merge!(
- {:new_index => self.tag_new_index}
- ) if self.new_index
- r.merge(opt)
- end
-
- def select_tag_attributes(selected, column, no_attr)
- [
- :last, :first,
- {:html => {:selected => selected}},
- self.field_tag_attributes(column, no_attr)
- ]
- end
-
- def tag_attr column = nil, opt = {}
- self.tag_attributes(column, opt).to_attr
- end
-
- def field_tag_attr column, no_attr, opt = {}
- self.field_tag_attributes(column, no_attr, opt).to_attr
- end
-
- def any_tag_attr name = nil, opt = {}
- self.any_tag_attributes(name, opt).to_attr
- end
-
+ def extend_element_name
+ self.extend_column ? self.attributes[extend_column] : self.element_name
end
+
+ def parent
+ @parent
+ end
+
+ def parent= content
+ @parent = content
+ end
+
+ def scenario_template with_engine = false
+ self.path_name(with_engine) + '/scenario'
+ end
+
+ def element_face_template with_engine = false
+ self.path_name(with_engine) + '/element_face'
+ end
+
+ def tag_attributes column = nil, opt = {}
+ r = super
+ r.merge({'data-parent_dom_id' => self.parent.dom_item_id}) if self.editor
+ r
+ end
+
+ def merge_opacity s, opacity
+ s.merge({
+ 'opacity' => opacity.to_f/100,
+ 'filter' => "alpha(opacity=#{opacity})"
+ })
+ end
+
end
end
module Peta
class Item < ActiveRecord::Base
self.abstract_class = true
+
+ # Dynamic ClassMethods
+
+ def self._valid_encode_columns
+ self.my_manifest.valid_encode_columns
+ end
+
+ def self.load_manifest
+ return nil unless self.my_manifest
+ r = self._valid_encode_columns
+ define_singleton_method("valid_encode_columns") do
+ r
+ end
+ end
+
# ClassMethods
# class_name
# table_name
before_validation :valid_encode
+ def self.my_manifest
+ Manifest.manifest.models[self.item_name]
+ end
+
def self.singular
self.to_s
end
self.plural.underscore
end
- def self.valid_encode_columns
- []
- end
-
def self.visible_count_options
nil
end
{}
end
- def self.visible_count
- self.count self.visible_count_options
- end
-
- def self.visible_count_options
- []
- end
-
#InstanceMethods
def self.fold_extend_settings params
self.class.table_name
end
+ def path_name with_engine = false
+ self.class.path_name(with_engine)
+ end
+
+ def form_template with_engine = false
+ self.path_name(with_engine) + '/form'
+ end
+
def extend_column
nil
end
true
end
- def dom_id_item
- self.new_record? ? '0' : self.id.to_s
+ def editor
+ @editor
end
- def tag_item_id c = nil
- self.item_name + self.item_id + c.to_s
+ def editor=(e)
+ @editor = e
end
- def dom_id_item_field field_name
- self.tag_item_id + field_name.to_s
+ def pool_id
+ @pool_id || self.id
end
- def path_name with_engine = false
- self.class.path_name(with_engine)
- end
-
- def form_template with_engine = false
- self.path_name(with_engine) + '/form'
- end
-
- def tag_item_attributes column = nil, opt = {}
- {
- :id => self.field_tag_id(column), :panel_id => self.tag_panel_id,
- :element_id => self.tag_element_id, :element_type => self.tag_element_type
- }.merge(opt)
- end
-
- def tag_new_index
- end
-
- def field_tag_attributes column, no_attr, opt = {}
- self.tag_attributes(column).merge(
- {:column => column, :new_index => self.tag_new_index, :no_attr => no_attr}
- ).merge(opt)
+ def pool_id=(i)
+ @pool_id = i
end
- #render element by body
- def any_tag_attributes name = nil, opt = {}
- r = self.tag_attributes(name)
- r.merge!(
- {:new_index => self.tag_new_index}
- ) if self.new_index
- r.merge(opt)
+ def dom_id
+ self.pool_id.to_s
end
- def select_tag_attributes(selected, column, no_attr)
- [
- :last, :first,
- {:html => {:selected => selected}},
- self.field_tag_attributes(column, no_attr)
- ]
+ def dom_pool_type
+ self.new_record? ? 'stored' : 'new'
end
- def tag_attr column = nil, opt = {}
- self.tag_attributes(column, opt).to_attr
+ def dom_item_id name = nil
+ r = [self.editor.eid, self.dom_pool_type, self.item_name, self.dom_id]
+ r += name.to_s if column_name
+ r.join '-'
end
- def field_tag_attr column, no_attr, opt = {}
- self.field_tag_attributes(column, no_attr, opt).to_attr
+ def tag_attributes name = nil, opt = {}
+ r = {
+ 'data-pool_type' => self.dom_pool_type, 'data-id' => self.dom_id,
+ 'data-item_name' => self.item_name
+ }
+ r.merge!({'id' => self.dom_item_id(name)}) if self.editor
+ r.merge!(opt)
+ r
end
- def any_tag_attr name = nil, opt = {}
- self.any_tag_attributes(name, opt).to_attr
+ def field_tag_attributes column_name, opt = {}
+ self.tag_attributes(column_name, opt).merge(
+ {'data-column_name' => column_name}
+ )
end
end