OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / models / scroll_panel.rb
1 class ScrollPanel < Peta::Leaf
2   load_manifest
3   belongs_to :author
4   belongs_to :panel
5   belongs_to :scroll
6   
7   validates :scroll_id, :presence => true, :numericality => true, :existence => {:both => false}
8   validates :panel_id, :presence => true, :numericality => true, :existence => {:both => false}
9   validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
10   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
11   
12   def supply_default
13     self.scroll_id = nil
14     self.panel_id = nil
15     self.t = nil
16   end
17   
18   def overwrite operators
19     return false unless operators.author
20     self.author_id = operators.author.id
21   end
22   
23   def self.public_list_order
24     'scroll_panels.updated_at desc'
25   end
26   
27   def self.public_list_where
28     'scrolls.visible > 0'
29   end
30   
31   def self.show_opt
32     {:include => {
33       :author => {}, 
34       :scroll => {
35         :author => {}
36       }, 
37       :panel => {
38         :author => {}, 
39         :panel_pictures => {:picture => {:artist => {}, :license => {}}}, 
40         :speech_balloons =>{:balloon => {}, :speech => {}}
41       }
42     }}
43   end
44   
45   def self.licensed_pictures scroll_panels
46     Panel.licensed_pictures scroll_panels.select {|sp| sp.panel }.map {|sp| sp.panel }
47   end
48   
49   def allow? operators
50     return nil if self.scroll_id == nil or self.panel_id == nil
51     self.scroll.own?(operators) and self.panel.usable?(operators)
52   end
53   
54 end