1 class SpeechBalloon < Peta::Element
4 has_one :balloon, :dependent => :destroy
5 has_one :speech, :dependent => :destroy
6 belongs_to :speech_balloon_template
9 accepts_nested_attributes_for :balloon
10 accepts_nested_attributes_for :speech
12 validates :panel_id, :numericality => {:allow_blank => true}
13 validates :speech_balloon_template_id, :presence => true, :numericality => true, :existence => {:both => false}
14 validates :classname, :presence => true, :length => {:maximum => 50}
15 validates :z, :presence => true, :numericality => {:greater_than => 0}
16 validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
17 validates :settings, :extend_speech_balloon => true
19 def self.list_opt_for_panel
21 :speech_balloons => {:balloon => {}, :speech => {}}
25 def self.show_opt_for_panel
27 :speech_balloons => {:balloon => {}, :speech => {}}
31 def self.json_opt_for_panel
33 :balloon => {}, :speech => {}
43 self.t = self.panel.new_t
44 self.z = self.panel.new_z
52 def visible? operators
53 return false unless super
54 self.owner_model.visible? operators
58 self.speech_balloon_template.symbol_option
70 self.balloon || @new_balloon
82 self.speech || @new_speech
86 self.extend self.speech_balloon_template.engine_extend_module
89 self.new_balloon = self.build_balloon
90 self.new_speech = self.build_speech
92 self.balloon.extend self.speech_balloon_template.engine_balloon_module
93 self.speech.extend self.speech_balloon_template.engine_speech_module
94 self.balloon.new_parent = self
95 self.speech.new_parent = self
96 self.extend_speech_balloon = if self.settings.blank?
99 JSON.parse(self.settings)
101 self.balloon.extend_balloon = if self.balloon.settings.blank?
104 JSON.parse(self.get_balloon.settings)
106 self.speech.extend_speech = if self.speech.settings.blank?
109 JSON.parse(self.get_speech.settings)
113 def self.fold_extend_settings params
114 speech_balloon_settings = params[:speech_balloon][:settings]
115 if speech_balloon_settings.is_a?(Hash)
116 params[:speech_balloon][:settings] = speech_balloon_settings.to_json
118 balloon_settings = params[:speech_balloon][:balloon_attributes][:settings]
119 if balloon_settings.is_a?(Hash)
120 params[:speech_balloon][:balloon_attributes][:settings] = balloon_settings.to_json
122 speech_settings = params[:speech_balloon][:speech_attributes][:settings]
123 if speech_settings.is_a?(Hash)
124 params[:speech_balloon][:speech_attributes][:settings] = speech_settings.to_json
137 'speech_balloons.updated_at desc'
141 {:panel => {:author => {}}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }
144 def self.list_json_opt
145 {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
149 {:include => {:panel => {:author => {}}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
152 def self.show_json_opt
153 {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
156 def store operators, attr
158 sb = self.panel.speech_balloons.build
161 self.panel.speech_balloons.each do |speech_balloon|
162 next unless speech_balloon == self
164 speech_balloon.attributes = attr
168 self.panel.store({}, operators)
172 self.panel.remove_element(self, au)
176 @parts ||= [self.balloon, self.speech]
180 self.speech_balloon_template.engine_name + '/'
183 def path_name with_engine = false
184 (with_engine ? self.engine_path_name : '') +
188 def form_template with_engine = false
189 self.path_name(true) + '/form'
192 def speech_form_template with_engine = false
193 self.engine_path_name + 'speeches/form'
196 def balloon_form_template with_engine = false
197 self.engine_path_name + 'balloons/form'
200 def scenario_template with_engine = false
201 self.path_name(true) + '/scenario'
204 def element_face_template with_engine = false
205 self.path_name(false) + '/element_face'
209 ERB::Util.html_escape(self.caption.to_s) + self.balloon.scenario.to_s +
210 self.speech.scenario.to_s
214 self.caption.to_s + self.balloon.plain_scenario.to_s +
215 self.speech.plain_scenario.to_s