OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / models / scroll.rb
1 class Scroll < Peta::Binder
2   load_manifest
3   has_many :scroll_panels
4   belongs_to :author
5   
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}
9   
10   def supply_default
11     self.visible = 0 if self.visible.blank?
12   end
13   
14   def overwrite operators
15     return false unless operators.author
16     self.author_id = operators.author.id
17     super()
18   end
19   
20   def visible? operators
21     case super
22     when nil # super return
23       return true
24     when false
25       return false
26     else
27       self.visible > 0
28     end
29   end
30   
31   def scroll_panels_count
32     ScrollPanel.where(['scroll_panels.scroll_id = ?', self.id]).count
33   end
34   
35   def self.public_list_order
36     'scrolls.updated_at desc'
37   end
38   
39   def self.list_where
40     'scrolls.visible > 0'
41   end
42   
43   def self.list_opt
44     {:scroll_panels => {:panel => {}}, :author => {} }
45   end
46   
47   def self.list_json_opt
48     {:include => {:scroll_panels => {:include => {:panel => {}}}, :author => {}}}
49   end
50   
51   def self.show_opt
52     {:include => {:scroll_panels => {:panel => {}}, :author => {}}}
53   end
54   
55   def self.show_json_opt
56     {:include => {:scroll_panels => {:include => {:panel => {}}}, :author => {}}}
57   end
58   
59   def scenario
60     panels.map {|panel|
61       panel.scenario
62     }.join
63   end
64   
65   def plain_scenario
66     panels.map {|panel|
67       panel.plain_scenario
68     }.join
69   end
70   
71 end