OSDN Git Service

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