1 class Scroll < Peta::Content
3 has_many :scroll_panels
6 validates :title, :presence => true, :length => {:maximum => 100}
7 validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
8 validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
10 self.visible = 0 if self.visible.blank?
13 def overwrite operators
14 return false unless operators.author
15 self.author_id = operators.author.id
18 def visible? operators
19 return false unless super
23 def scroll_panels_count
24 ScrollPanel.where(['scroll_panels.scroll_id = ?', self.id]).count
28 'scrolls.updated_at desc'
36 {:scroll_panels => {:panel => {}}, :author => {} }
39 def self.list_json_opt
40 {:include => {:scroll_panels => {:include => {:panel => {}}}, :author => {}}}
44 {:include => {:scroll_panels => {:panel => {}}, :author => {}}}
47 def self.show_json_opt
48 {:include => {:scroll_panels => {:include => {:panel => {}}}, :author => {}}}
51 def self.visible_count
52 Scroll.count 'visible > 0'
55 def destroy_with_scroll_panel
58 self.scroll_panels.each do |scroll_panel|
59 raise ActiveRecord::Rollback unless scroll_panel.destroy
61 raise ActiveRecord::Rollback unless self.destroy