OSDN Git Service

87272e64ae36e0d2fd45fd24ee0cce7b649f424b
[pettanr/pettanr.git] / app / models / speech_balloon.rb
1 class SpeechBalloon < Peta::Element
2   load_manifest
3   has_one :balloon, :dependent => :destroy
4   has_one :speech, :dependent => :destroy
5   belongs_to :speech_balloon_template
6   belongs_to :panel
7   
8   accepts_nested_attributes_for :balloon
9   accepts_nested_attributes_for :speech
10   
11   validates :panel_id, :numericality => {:allow_blank => true}
12   validates :speech_balloon_template_id, :presence => true, :numericality => true, :existence => {:both => false}
13   validates :speech_balloon_template_classname, :presence => true, :length => {:maximum => 50}
14   validates :z, :presence => true, :numericality => {:greater_than => 0}
15   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
16   validates :speech_balloon_template_settings, :boost => {:boost_name => :speech_balloon_template}
17   
18   def self.by_author_list_includes
19     {
20       :panel => {
21         :author => {}
22       }
23     }
24   end
25   
26   def self.list_opt_for_panel
27     {
28       :speech_balloons => {:balloon => {}, :speech => {}}
29     }
30   end
31   
32   def self.show_opt_for_panel
33     {
34       :speech_balloons => {:balloon => {}, :speech => {}}
35     }
36   end
37   
38   def self.json_opt_for_panel
39     {
40       :balloon => {}, :speech => {}
41     }
42   end
43   
44   def self.has_picture?
45     false
46   end
47   
48   def supply_default
49     if self.panel
50       self.t = self.panel.new_t 
51       self.z = self.panel.new_z 
52     end
53   end
54   
55   def overwrite pid
56     self.panel_id = pid
57   end
58   
59   def symbol_option
60     self.speech_balloon_template.symbol_option
61   end
62   
63   def tag_element_type
64     'speech_balloon'
65   end
66   
67   def self.public_list_where
68     'panels.publish > 0'
69   end
70   
71   def self.show_opt
72     {:include => {:panel => {:author => {}}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
73   end
74   
75   def self.show_json_opt
76     {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
77   end
78   
79   def parts
80     @parts ||= [self.balloon, self.speech]
81   end
82   
83   def engine_path_name 
84     self.speech_balloon_template.engine_name + '/'
85   end
86   
87   def path_name with_engine = false
88     (with_engine ? self.engine_path_name : '') + 
89       self.class.path_name
90   end
91   
92   def form_template with_engine = false
93     self.path_name(true) + '/form'
94   end
95   
96   def speech_form_template with_engine = false
97     self.engine_path_name + 'speeches/form'
98   end
99   
100   def balloon_form_template with_engine = false
101     self.engine_path_name + 'balloons/form'
102   end
103   
104   def scenario_template with_engine = false
105     self.path_name(true) + '/scenario'
106   end
107   
108   def element_face_template with_engine = false
109     self.path_name(false) + '/element_face'
110   end
111   
112   def scenario
113     ERB::Util.html_escape(self.caption.to_s) + self.balloon.scenario.to_s + 
114     self.speech.scenario.to_s
115   end
116   
117   def plain_scenario
118     self.caption.to_s + self.balloon.plain_scenario.to_s + 
119     self.speech.plain_scenario.to_s
120   end
121   
122 end