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
62 self.extend self.speech_balloon_template.engine_speech_balloon_module
65 self.new_balloon = self.build_balloon
66 self.new_speech = self.build_speech
68 self.balloon.extend self.speech_balloon_template.engine_balloon_module
69 self.speech.extend self.speech_balloon_template.engine_speech_module
71 self.balloon.new_parent = self
72 self.speech.new_parent = self
73 self.extend_speech_balloon = if self.settings.blank?
76 JSON.parse(self.settings)
78 self.balloon.extend_balloon = if self.balloon.settings.blank?
81 JSON.parse(self.get_balloon.settings)
83 self.speech.extend_speech = if self.speech.settings.blank?
86 JSON.parse(self.get_speech.settings)
90 def self.fold_extend_settings params
91 speech_balloon_settings = params[:speech_balloon][:settings]
92 if speech_balloon_settings.is_a?(Hash)
93 params[:speech_balloon][:settings] = speech_balloon_settings.to_json
95 balloon_settings = params[:speech_balloon][:balloon_attributes][:settings]
96 if balloon_settings.is_a?(Hash)
97 params[:speech_balloon][:balloon_attributes][:settings] = balloon_settings.to_json
99 speech_settings = params[:speech_balloon][:speech_attributes][:settings]
100 if speech_settings.is_a?(Hash)
101 params[:speech_balloon][:speech_attributes][:settings] = speech_settings.to_json
114 'speech_balloons.updated_at desc'
117 def self.list_json_opt
118 {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
122 {:include => {:panel => {:author => {}}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
125 def self.show_json_opt
126 {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
129 def store operators, attr
131 sb = self.panel.speech_balloons.build
134 self.panel.speech_balloons.each do |speech_balloon|
135 next unless speech_balloon == self
137 speech_balloon.attributes = attr
141 self.panel.store({}, operators)
145 self.panel.remove_element(self, au)
149 @parts ||= [self.balloon, self.speech]
153 self.speech_balloon_template.engine_name + '/'
156 def path_name with_engine = false
157 (with_engine ? self.engine_path_name : '') +
161 def form_template with_engine = false
162 self.path_name(true) + '/form'
165 def speech_form_template with_engine = false
166 self.engine_path_name + 'speeches/form'
169 def balloon_form_template with_engine = false
170 self.engine_path_name + 'balloons/form'
173 def scenario_template with_engine = false
174 self.path_name(true) + '/scenario'
177 def element_face_template with_engine = false
178 self.path_name(false) + '/element_face'
182 ERB::Util.html_escape(self.caption.to_s) + self.balloon.scenario.to_s +
183 self.speech.scenario.to_s
187 self.caption.to_s + self.balloon.plain_scenario.to_s +
188 self.speech.plain_scenario.to_s