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
36 def self.by_author_list_includes
51 :panel_pictures => {:picture => {:artist => {}, :license => {}}},
52 :speech_balloons =>{:balloon => {}, :speech => {}}
61 def sheet_panel_as_json au
62 panel_include = if self.panel and self.panel.visible?(au)
63 {:include => {}, :methods => :elements}
67 self.to_json({:include => {:sheet => {:include => {:author => {}}}, :panel => panel_include}})
70 def self.list_as_json_text ary, au
71 '[' + ary.map {|i| i.sheet_panel_as_json(au) }.join(',') + ']'
76 self.panel.licensed_pictures
83 if self.panel and self.panel.publish?
91 return nil if self.sheet_id == nil or self.panel_id == nil
92 self.sheet.own?(operators) and self.panel.usable?(operators)
95 def store operators, old_t = nil
97 self.class.transaction do
98 case self.allow? operators
102 raise ActiveRecord::Forbidden
106 raise ActiveRecord::Rollback unless res
107 res = self.class.validate_t(self.sheet_id)
109 self.errors.add :t, 'unserialized'
110 raise ActiveRecord::Rollback