OSDN Git Service

fix model
[pettanr/pettanr.git] / app / models / balloon.rb
1 class Balloon < Peta::Content
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.get_parent.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.list_opt
47     {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}
48   end
49   
50   def self.list_json_opt
51     {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}}
52   end
53   
54   def self.show_opt
55     {:include => {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}}
56   end
57   
58   def self.show_json_opt
59     {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}}
60   end
61   
62   def style
63     {
64       'width' => self.width.to_s + 'px','height' => self.height.to_s + 'px',
65       'top' => self.y.to_s + 'px','left' => self.x.to_s + 'px'
66     }
67   end
68   
69   def copy_attributes
70     r = self.attributes
71     r.delete 'id'
72     r.delete 'speech_balloon_id'
73     r.delete 'created_at'
74     r.delete 'updated_at'
75     r
76   end
77   
78   def self.panelize balloon_attributes
79     {'balloon_attributes' => balloon_attributes}
80   end
81   
82   def scenario
83   end
84   
85   def plain_scenario
86   end
87   
88 end