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
80 if self.panel and self.panel.publish?
88 return nil if self.sheet_id == nil or self.panel_id == nil
89 self.sheet.own?(operators) and self.panel.usable?(operators)
92 def store operators, old_t = nil
94 self.class.transaction do
95 case self.allow? operators
99 raise ActiveRecord::Forbidden
103 raise ActiveRecord::Rollback unless res
104 res = self.class.validate_t(self.sheet_id)
106 self.errors.add :t, 'unserialized'
107 raise ActiveRecord::Rollback