1 class SpeechBalloon < Pettanr::Content
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
23 def self.valid_encode_columns
24 super + ['caption', 'classname', 'settings']
27 def self.list_opt_for_panel
29 :speech_balloons => {:balloon => {}, :speech => {}}
33 def self.show_opt_for_panel
35 :speech_balloons => {:balloon => {}, :speech => {}}
39 def self.json_opt_for_panel
41 :balloon => {}, :speech => {}
55 self.t = self.panel.new_t
56 self.z = self.panel.new_z
64 def visible? operators
65 return false unless super
66 self.owner_model.visible? operators
70 self.speech_balloon_template.symbol_option
82 self.balloon || @new_balloon
94 self.speech || @new_speech
98 self.extend self.speech_balloon_template.engine_speech_balloon_module
101 self.new_balloon = self.build_balloon
102 self.new_speech = self.build_speech
104 self.balloon.extend self.speech_balloon_template.engine_balloon_module
105 self.speech.extend self.speech_balloon_template.engine_speech_module
106 self.balloon.new_parent = self
107 self.speech.new_parent = self
108 self.extend_speech_balloon = if self.settings.blank?
111 JSON.parse(self.settings)
113 self.balloon.extend_balloon = if self.balloon.settings.blank?
116 JSON.parse(self.get_balloon.settings)
118 self.speech.extend_speech = if self.speech.settings.blank?
121 JSON.parse(self.get_speech.settings)
125 def self.fold_extend_settings params
126 speech_balloon_settings = params[:speech_balloon][:settings]
127 if speech_balloon_settings.is_a?(Hash)
128 params[:speech_balloon][:settings] = speech_balloon_settings.to_json
130 balloon_settings = params[:speech_balloon][:balloon_attributes][:settings]
131 if balloon_settings.is_a?(Hash)
132 params[:speech_balloon][:balloon_attributes][:settings] = balloon_settings.to_json
134 speech_settings = params[:speech_balloon][:speech_attributes][:settings]
135 if speech_settings.is_a?(Hash)
136 params[:speech_balloon][:speech_attributes][:settings] = speech_settings.to_json
149 'speech_balloons.updated_at desc'
153 {:panel => {:author => {}}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }
156 def self.list_json_opt
157 {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
161 {:include => {:panel => {:author => {}}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
164 def self.show_json_opt
165 {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
170 sb = self.panel.speech_balloons.build
173 self.panel.speech_balloons.each do |speech_balloon|
174 next unless speech_balloon == self
176 speech_balloon.attributes = attr
180 self.panel.store({}, au)
184 self.panel.remove_element(self, au)
188 @parts ||= [self.balloon, self.speech]
192 self.speech_balloon_template.engine_name + '/'
195 def path_name with_engine = false
196 (with_engine ? self.engine_path_name : '') +
200 def form_template with_engine = false
201 self.path_name(true) + '/form'
204 def speech_form_template with_engine = false
205 self.engine_path_name + 'speeches/form'
208 def balloon_form_template with_engine = false
209 self.engine_path_name + 'balloons/form'
212 def scenario_template with_engine = false
213 self.path_name(true) + '/scenario'
216 def element_face_template with_engine = false
217 self.path_name(false) + '/element_face'
221 ERB::Util.html_escape(self.caption.to_s) + self.balloon.scenario.to_s +
222 self.speech.scenario.to_s
226 self.caption.to_s + self.balloon.plain_scenario.to_s +
227 self.speech.plain_scenario.to_s