OSDN Git Service

element
[pettanr/pettanr.git] / app / models / balloon.rb
1 class Balloon < Peta::Content
2   load_manifest
3   include Peta::ElementPart
4   belongs_to :speech_balloon
5   belongs_to :system_picture
6   
7   validates :speech_balloon_id, :numericality => {:allow_blank => true}
8   validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
9   validates :x, :presence => true, :numericality => true
10   validates :y, :presence => true, :numericality => true
11   validates :width, :presence => true, :numericality => true, :natural_number => true
12   validates :height, :presence => true, :numericality => true, :natural_number => true
13   validates :r, :presence => true, :numericality => true
14 #  validates :caption, :presence => true
15   validates :settings, :extend_balloon => true
16
17   def self.colum_structures
18     @@colum_structures ||= {
19       :r => {
20         :helper => 'panels/tail_angle_helper'
21       }
22     }
23   end
24   
25   def url
26     '/system_pictures/' + self.system_picture.filename
27   end
28   
29   def visible? operators
30     return false unless super
31     self.owner_model.visible? operators
32   end
33   
34   def supply_default
35     self.x = 0
36     self.y = 0
37     self.width = 100
38     self.height = 100
39     self.r = 0
40 self.system_picture_id = 1
41   end
42   
43   def symbol_option
44     self.get_parent.speech_balloon_template.symbol_option
45   end
46   
47   def get_parent
48     self.speech_balloon || @new_parent
49   end
50   
51   def tag_element_part_type
52     'balloon'
53   end
54   
55   def self.list_where
56     'panels.publish > 0'
57   end
58   
59   def self.list_order
60     'balloons.updated_at desc'
61   end
62   
63   def self.list_opt
64     {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}
65   end
66   
67   def self.list_json_opt
68     {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}}
69   end
70   
71   def self.show_opt
72     {:include => {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}}
73   end
74   
75   def self.show_json_opt
76     {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}}
77   end
78   
79   def style
80     {
81       'width' => self.width.to_s + 'px','height' => self.height.to_s + 'px',
82       'top' => self.y.to_s + 'px','left' => self.x.to_s + 'px'
83     }
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