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
21 when nil # super return
30 def scroll_panels_count
31 ScrollPanel.where(['scroll_panels.scroll_id = ?', self.id]).count
34 def self.public_list_order
35 'scrolls.updated_at desc'
43 {:scroll_panels => {:panel => {}}, :author => {} }
46 def self.list_json_opt
47 {:include => {:scroll_panels => {:include => {:panel => {}}}, :author => {}}}
51 {:include => {:scroll_panels => {:panel => {}}, :author => {}}}
54 def self.show_json_opt
55 {:include => {:scroll_panels => {:include => {:panel => {}}}, :author => {}}}
58 def self.visible_count
59 Scroll.count 'visible > 0'
62 def destroy_with_scroll_panel
65 self.scroll_panels.each do |scroll_panel|
66 raise ActiveRecord::Rollback unless scroll_panel.destroy
68 raise ActiveRecord::Rollback unless self.destroy