1 class ScrollPanel < Peta::Leaf
7 validates :scroll_id, :presence => true, :numericality => true, :existence => {:both => false}
8 validates :panel_id, :presence => true, :numericality => true, :existence => {:both => false}
9 validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
10 validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
18 def overwrite operators
19 return false unless operators.author
20 self.author_id = operators.author.id
23 def self.public_list_order
24 'scroll_panels.updated_at desc'
31 def self.by_author_list_includes
39 def self.play_list_where cid
40 ['scroll_panels.scroll_id = ?', cid]
43 def self.play_list scroll, author, offset = 0, limit = ScrollPanel.default_panel_size
44 ScrollPanel.where(self.play_list_where(scroll.id)).includes(ScrollPanel.list_opt).order('scroll_panels.t').offset(offset).limit(limit)
55 :panel_pictures => {:picture => {:artist => {}, :license => {}}},
56 :speech_balloons =>{:balloon => {}, :speech => {}}
61 def self.list_json_opt
69 :panel_pictures => {:picture => {:artist => {}, :license => {}}},
70 :speech_balloons =>{:balloon => {}, :speech => {}}
83 :panel_pictures => {:picture => {:artist => {}, :license => {}}},
84 :speech_balloons =>{:balloon => {}, :speech => {}}
93 def scroll_panel_as_json au
94 panel_include = if self.panel and self.panel.visible?(au)
95 {:include => {:author => {}}, :methods => :elements}
97 {:include => {:author => {}}}
99 self.to_json({:include => {:scroll => {:include => {:author => {}}}, :author => {}, :panel => panel_include}})
102 def self.list_as_json_text ary, au
103 '[' + ary.map {|i| i.scroll_panel_as_json(au) }.join(',') + ']'
106 def self.licensed_pictures scroll_panels
108 scroll_panels.each do |scroll_panel|
109 r.merge!(scroll_panel.panel.licensed_pictures) if scroll_panel.panel
115 return nil if self.scroll_id == nil or self.panel_id == nil
116 self.scroll.own?(operators) and self.panel.usable?(operators)
119 def store operators, old_t = nil
121 self.class.transaction do
122 case self.allow? operators
126 raise ActiveRecord::Forbidden
130 raise ActiveRecord::Rollback unless res
131 res = self.class.validate_t(self.scroll_id)
133 self.errors.add :t, 'unserialized'
134 raise ActiveRecord::Rollback