1 class Scroll < Peta::Binder
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}
11 self.visible = 0 if self.visible.blank?
14 def overwrite operators
15 return false unless operators.author
16 self.author_id = operators.author.id
19 def visible? operators
20 return false unless super
24 def scroll_panels_count
25 ScrollPanel.where(['scroll_panels.scroll_id = ?', self.id]).count
29 'scrolls.updated_at desc'
37 {:scroll_panels => {:panel => {}}, :author => {} }
40 def self.list_json_opt
41 {:include => {:scroll_panels => {:include => {:panel => {}}}, :author => {}}}
45 {:include => {:scroll_panels => {:panel => {}}, :author => {}}}
48 def self.show_json_opt
49 {:include => {:scroll_panels => {:include => {:panel => {}}}, :author => {}}}
52 def self.visible_count
53 Scroll.count 'visible > 0'
56 def destroy_with_scroll_panel
59 self.scroll_panels.each do |scroll_panel|
60 raise ActiveRecord::Rollback unless scroll_panel.destroy
62 raise ActiveRecord::Rollback unless self.destroy