OSDN Git Service

ebca4eff0a61b1b41cde4887e6bacd78c80422b4
[pettanr/pettanr.git] / app / models / balloon.rb
1 class Balloon < Peta::Element
2   load_manifest
3   belongs_to :speech_balloon
4   belongs_to :system_picture
5   
6   validates :speech_balloon_id, :numericality => {:allow_blank => true}
7   validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
8   validates :x, :presence => true, :numericality => true
9   validates :y, :presence => true, :numericality => true
10   validates :width, :presence => true, :numericality => true, :natural_number => true
11   validates :height, :presence => true, :numericality => true, :natural_number => true
12   validates :r, :presence => true, :numericality => true
13 #  validates :caption, :presence => true
14   validates :settings, :extend_balloon => true
15
16   def url
17     '/system_pictures/' + self.system_picture.filename
18   end
19   
20   def visible? operators
21     return false unless super
22     self.owner_model.visible? operators
23   end
24   
25   def supply_default
26     self.x = 0
27     self.y = 0
28     self.width = 100
29     self.height = 100
30     self.r = 0
31 self.system_picture_id = 1
32   end
33   
34   def symbol_option
35     self.speech_balloon.speech_balloon_template.symbol_option
36   end
37   
38   def self.list_where
39     'panels.publish > 0'
40   end
41   
42   def self.list_order
43     'balloons.updated_at desc'
44   end
45   
46   def self.by_author_list_includes
47     {
48       :speech_balloon => {
49         :panel => {
50           :author => {}
51         }
52       }
53     }
54   end
55   
56   def self.list_opt
57     {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}
58   end
59   
60   def self.list_json_opt
61     {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}}
62   end
63   
64   def self.show_opt
65     {:include => {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}}
66   end
67   
68   def self.show_json_opt
69     {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}}
70   end
71   
72   def style
73     {
74       'width' => self.width.to_s + 'px','height' => self.height.to_s + 'px',
75       'top' => self.y.to_s + 'px','left' => self.x.to_s + 'px'
76     }
77   end
78   
79   def copy_attributes
80     r = self.attributes
81     r.delete 'id'
82     r.delete 'speech_balloon_id'
83     r.delete 'created_at'
84     r.delete 'updated_at'
85     r
86   end
87   
88   def self.panelize balloon_attributes
89     {'balloon_attributes' => balloon_attributes}
90   end
91   
92   def scenario
93   end
94   
95   def plain_scenario
96   end
97   
98 end