OSDN Git Service

work
[pettanr/pettanr.git] / app / models / balloon.rb
1 class Balloon < Pettanr::Content
2   include ElementPart
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 owner_model
17     self.speech_balloon.panel
18   end
19   
20   def self.valid_encode_columns
21     super + ['settings']
22   end
23   
24   def self.colum_structures
25     @@colum_structures ||= {
26       :r => {
27         :helper => 'panels/tail_angle_helper'
28       }
29     }
30   end
31   
32   def url
33     '/system_pictures/' + self.system_picture.filename
34   end
35   
36   def visible? operators
37     return false unless super
38     self.owner_model.visible? operators
39   end
40   
41   def supply_default
42     self.x = 0
43     self.y = 0
44     self.width = 100
45     self.height = 100
46     self.r = 0
47 self.system_picture_id = 1
48   end
49   
50   def symbol_option
51     self.get_parent.speech_balloon_template.symbol_option
52   end
53   
54   def get_parent
55     self.speech_balloon || @new_parent
56   end
57   
58   def tag_element_part_type
59     'balloon'
60   end
61   
62   def self.list_where
63     'panels.publish > 0'
64   end
65   
66   def self.list_order
67     'balloons.updated_at desc'
68   end
69   
70   def self.list_opt
71     {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}
72   end
73   
74   def self.list_json_opt
75     {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}}
76   end
77   
78   def self.show_opt
79     {:include => {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}}
80   end
81   
82   def self.show_json_opt
83     {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}}
84   end
85   
86   def copy_attributes
87     r = self.attributes
88     r.delete 'id'
89     r.delete 'speech_balloon_id'
90     r.delete 'created_at'
91     r.delete 'updated_at'
92     r
93   end
94   
95   def self.panelize balloon_attributes
96     {'balloon_attributes' => balloon_attributes}
97   end
98   
99   def scenario
100   end
101   
102   def plain_scenario
103   end
104   
105 end