1 class SheetPanel < Peta::Element
6 accepts_nested_attributes_for :panel, :allow_destroy => true
8 validates :sheet_id, :numericality => {:allow_blank => true}
9 validates :panel_id, :numericality => {:allow_blank => true}
10 validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
11 validates :x, :presence => true, :numericality => true
12 validates :y, :presence => true, :numericality => true
13 validates :z, :presence => true, :numericality => {:greater_than => 0}
14 validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
24 self.t = self.sheet.new_t
25 self.z = self.sheet.new_z
34 def overwrite operators
35 return false unless operators.author
36 self.author_id = operators.author.id
39 def self.by_author_list_includes
55 :panel_pictures => {:picture => {:artist => {}, :license => {}}},
56 :speech_balloons =>{:balloon => {}, :speech => {}}
65 def sheet_panel_as_json au
66 panel_include = if self.panel and self.panel.visible?(au)
67 {:include => {:author => {}}, :methods => :elements}
69 {:include => {:author => {}}}
71 self.to_json({:include => {:sheet => {:include => {:author => {}}}, :author => {}, :panel => panel_include}})
74 def self.list_as_json_text ary, au
75 '[' + ary.map {|i| i.sheet_panel_as_json(au) }.join(',') + ']'
80 self.panel.licensed_pictures
86 def self.panelize elements_attributes
87 elements_attributes = [elements_attributes] unless elements_attributes.is_a?(Array)
90 elements_attributes.each do |element_attributes|
91 hash[self.to_s.tableize + '_attributes'] ||= {}
92 n = if element_attributes['id']
93 element_attributes['id'].to_s
98 hash[self.to_s.tableize + '_attributes'][n] = element_attributes
107 r.delete 'panel_id' # create panel
108 r.delete 'created_at'
109 r.delete 'updated_at'
114 if self.panel and self.panel.publish? == false
123 {'panel_attributes' => self.panel.copy}
130 return nil if self.sheet_id == nil or self.panel_id == nil
131 self.sheet.own?(operators) and self.panel.usable?(operators)
134 def store operators, old_t = nil
136 self.class.transaction do
137 case self.allow? operators
141 raise ActiveRecord::Forbidden
145 raise ActiveRecord::Rollback unless res
146 res = self.class.validate_t(self.sheet_id)
148 self.errors.add :t, 'unserialized'
149 raise ActiveRecord::Rollback