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
20 def visible? operators
22 when nil # super return
31 def scroll_panels_count
32 ScrollPanel.where(['scroll_panels.scroll_id = ?', self.id]).count
35 def self.public_list_order
36 'scrolls.updated_at desc'
44 {:scroll_panels => {:panel => {}}, :author => {} }
47 def self.list_json_opt
48 {:include => {:scroll_panels => {:include => {:panel => {}}}, :author => {}}}
52 {:include => {:scroll_panels => {:panel => {}}, :author => {}}}
55 def self.show_json_opt
56 {:include => {:scroll_panels => {:include => {:panel => {}}}, :author => {}}}