#コマ
-class Panel < Pettanr::Content
+class Panel < Peta::Root
+ load_manifest
belongs_to :author
has_many :scroll_panels
has_many :sheet_panels
validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :publish, :presence => true, :numericality => true
- def self.valid_encode_columns
- super + ['caption']
- end
-
- def self.each_element_class_names
- Pettanr::Application.manifest.system_resources.elements.each do |k, n|
- yield k
- end
- end
-
- def self.class_name_to_class k
- Object.const_get k
- end
-
- def self.each_element_classes
- self.each_element_class_names do |k|
- e = self.class_name_to_class k
- yield e
- end
- end
-
- def elements_by_class_name class_name
- self.__send__ class_name.tableize
- end
-
def supply_default
self.border = 2
self.publish = 0
self.publish > 0
end
- def tag_id c = nil
- 'panel' + self.tag_panel_id + c.to_s
- end
-
- def tag_panel_id
- self.new_record? ? '0' : self.id.to_s
- end
-
- def field_tag_id f
- self.tag_id + f.to_s
- end
-
- def tag_attributes column = nil, opt = {}
+ def style
{
- :id => self.field_tag_id(column), :panel_id => self.tag_panel_id
- }.merge(opt)
- end
-
- def select_tag_attributes(selected, column, opt = {})
- [
- {:html => {:selected => selected}},
- self.field_tag_attributes(column, opt)
- ]
- end
-
- def field_tag_attributes column, no_attr, opt = {}
- self.tag_attributes(column).merge(
- {:column => column}
- ).merge(opt)
- end
-
- def tag_attr column = nil, opt = {}
- self.tag_attributes(column, opt).to_attr
+ 'width' => self.width.to_s + 'px', 'height' => self.height.to_s + 'px',
+ 'border-style' => 'solid', 'border-width' => self.border.to_s + 'px',
+ 'border-color' => 'black', 'background-color' => 'white'
+ }
end
- def field_tag_attr column, no_attr, opt = {}
- self.field_tag_attributes(column, no_attr, opt).to_attr
+ # ground_picture element template
+ def style_wh
+ {
+ 'width' => self.width.to_s + 'px', 'height' => self.height.to_s + 'px'
+ }
end
- def render_count
- @render_count ||= 1
- end
-
- def rendered
- @render_count = render_count + 1
- end
-
def self.list_where
'panels.publish > 0'
end
r = {
:author => {}
}
- self.each_element_classes do |e|
- r.merge!(e.list_opt_for_panel)
+ self.child_models.each do |child_model|
+ r.merge!(child_model.list_opt_for_panel)
end
r
end
r = {
:author => {}
}
- self.each_element_classes do |e|
- r.merge!(e.show_opt_for_panel)
+ self.child_models.each do |child_model|
+ r.merge!(child_model.show_opt_for_panel)
end
{:include => r}
end
def parts_element
- r = []
- self.class.each_element_class_names do |k|
- r += (self.elements_by_class_name(k) || [])
- end
- r
+ self.elements_items
end
def zorderd_elements
end
def validate_serial_list
- l = []
- self.class.each_element_class_names do |k|
- l << self.elements_by_class_name(k)
- end
[
- {:elements => l, :name => :t, :offset => 0},
- {:elements => l, :name => :z, :offset => 1}
+ {:elements => self.elements_items, :name => :t, :offset => 0},
+ {:elements => self.elements_items, :name => :z, :offset => 1}
]
end
def validate_child
Panel.validate_elements_serial validate_serial_list
end
- def boost
- @new_element_index = 0
- self.panel_elements.each do |elm|
- if elm.new_record?
- elm.new_index = @new_element_index
- @new_element_index += 1
- end
- end
- end
-
def store attr, operators
if attr == false
self.errors.add :base, I18n.t('errors.invalid_json')
res = false
Panel.transaction do
self.panel_elements.each do |elm|
- elm.new_panel = self
elm.boost
end
#self.publish = nil
res
end
- def copy
- attr = self.copy_attributes
- Panel.each_element_class_names do |n|
- attr.merge! Panel.class_name_to_class(n).panelize(self.elements_by_class_name(n).map {|elm| elm.copy_attributes})
- end
- attr
- end
-
- def copy_attributes
- r = self.attributes
- r.delete 'id'
- r.delete 'author_id'
- r.delete 'created_at'
- r.delete 'updated_at'
- r
- end
-
def self.panelize panel
attr = panel.attributes
attr.delete 'id'