1 class Scroll < Pettanr::Content
2 has_many :scroll_panels
5 validates :title, :presence => true, :length => {:maximum => 100}
6 validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
7 validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
9 def self.valid_encode_columns
14 self.visible = 0 if self.visible.blank?
17 def overwrite operators
18 return false unless operators.author
19 self.author_id = operators.author.id
22 def visible? operators
23 return false unless super
27 def scroll_panels_count
28 ScrollPanel.where(['scroll_panels.scroll_id = ?', self.id]).count
32 'scrolls.updated_at desc'
40 {:scroll_panels => {:panel => {}}, :author => {} }
43 def self.list_json_opt
44 {:include => {:scroll_panels => {:include => {:panel => {}}}, :author => {}}}
48 {:include => {:scroll_panels => {:panel => {}}, :author => {}}}
51 def self.show_json_opt
52 {:include => {:scroll_panels => {:include => {:panel => {}}}, :author => {}}}
55 def self.visible_count
56 Scroll.count 'visible > 0'
59 def destroy_with_scroll_panel
62 self.scroll_panels.each do |scroll_panel|
63 raise ActiveRecord::Rollback unless scroll_panel.destroy
65 raise ActiveRecord::Rollback unless self.destroy