-class Scroll < Peta::Content
+class Scroll < Peta::Binder
load_manifest
has_many :scroll_panels
belongs_to :author
def supply_default
self.visible = 0 if self.visible.blank?
+ self.author_id = nil
end
def overwrite operators
return false unless operators.author
self.author_id = operators.author.id
+ super()
end
def visible? operators
- return false unless super
- self.visible > 0
- end
-
- def scroll_panels_count
- ScrollPanel.where(['scroll_panels.scroll_id = ?', self.id]).count
- end
-
- def self.list_order
- 'scrolls.updated_at desc'
+ case super
+ when nil # super return
+ return true
+ when false
+ return false
+ else
+ self.visible > 0
+ end
end
- def self.list_where
+ def self.public_list_where
'scrolls.visible > 0'
end
- def self.list_opt
- {:scroll_panels => {:panel => {}}, :author => {} }
- end
-
- def self.list_json_opt
- {:include => {:scroll_panels => {:include => {:panel => {}}}, :author => {}}}
- end
-
def self.show_opt
{:include => {:scroll_panels => {:panel => {}}, :author => {}}}
end
- def self.show_json_opt
- {:include => {:scroll_panels => {:include => {:panel => {}}}, :author => {}}}
- end
-
- def self.visible_count
- Scroll.count 'visible > 0'
- end
-
- def destroy_with_scroll_panel
- res = false
- Scroll.transaction do
- self.scroll_panels.each do |scroll_panel|
- raise ActiveRecord::Rollback unless scroll_panel.destroy
- end
- raise ActiveRecord::Rollback unless self.destroy
- res = true
- end
- res
- end
-
def scenario
panels.map {|panel|
panel.scenario