1 class SheetPanel < Peta::Element
5 accepts_nested_attributes_for :panel, :allow_destroy => true
6 #alias_attribute :attr_y, :y
8 validates :sheet_id, :numericality => {:allow_blank => true}
9 validates :panel_id, :numericality => {:allow_blank => true}
10 validates :x, :presence => true, :numericality => true
11 validates :y, :presence => true, :numericality => true
12 validates :z, :presence => true, :numericality => {:greater_than => 0}
13 validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
23 self.t = self.sheet.new_t
24 self.z = self.sheet.new_z
33 def self.by_author_list_includes
48 :panel_pictures => {:picture => {:artist => {}, :license => {}}},
49 :speech_balloons =>{:balloon => {}, :speech => {}}
58 def sheet_panel_as_json au
59 panel_include = if self.panel and self.panel.visible?(au)
60 {:include => {}, :methods => :elements}
64 self.to_json({:include => {:sheet => {:include => {:author => {}}}, :panel => panel_include}})
67 def self.list_as_json_text ary, au
68 '[' + ary.map {|i| i.sheet_panel_as_json(au) }.join(',') + ']'
73 self.panel.licensed_pictures
79 def self.panelize elements_attributes
80 elements_attributes = [elements_attributes] unless elements_attributes.is_a?(Array)
83 elements_attributes.each do |element_attributes|
84 hash[self.to_s.tableize + '_attributes'] ||= {}
85 n = if element_attributes['id']
86 element_attributes['id'].to_s
91 hash[self.to_s.tableize + '_attributes'][n] = element_attributes
100 r.delete 'panel_id' # create panel
101 r.delete 'created_at'
102 r.delete 'updated_at'
107 if self.panel and self.panel.publish? == false
116 {'panel_attributes' => self.panel.copy}
123 return nil if self.sheet_id == nil or self.panel_id == nil
124 self.sheet.own?(operators) and self.panel.usable?(operators)
127 def store operators, old_t = nil
129 self.class.transaction do
130 case self.allow? operators
134 raise ActiveRecord::Forbidden
138 raise ActiveRecord::Rollback unless res
139 res = self.class.validate_t(self.sheet_id)
141 self.errors.add :t, 'unserialized'
142 raise ActiveRecord::Rollback