1 class SpeechBalloon < Peta::Element
3 has_one :balloon, :dependent => :destroy
4 has_one :speech, :dependent => :destroy
5 belongs_to :speech_balloon_template
8 accepts_nested_attributes_for :balloon
9 accepts_nested_attributes_for :speech
11 validates :panel_id, :numericality => {:allow_blank => true}
12 validates :speech_balloon_template_id, :presence => true, :numericality => true, :existence => {:both => false}
13 validates :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 :settings, :extend_speech_balloon => true
18 def self.list_opt_for_panel
20 :speech_balloons => {:balloon => {}, :speech => {}}
24 def self.show_opt_for_panel
26 :speech_balloons => {:balloon => {}, :speech => {}}
30 def self.json_opt_for_panel
32 :balloon => {}, :speech => {}
42 self.t = self.panel.new_t
43 self.z = self.panel.new_z
51 def visible? operators
52 return false unless super
53 self.owner_model.visible? operators
57 self.speech_balloon_template.symbol_option
61 self.extend self.speech_balloon_template.engine_speech_balloon_module
64 self.new_balloon = self.build_balloon
65 self.new_speech = self.build_speech
67 self.balloon.extend self.speech_balloon_template.engine_balloon_module
68 self.speech.extend self.speech_balloon_template.engine_speech_module
70 self.balloon.new_parent = self
71 self.speech.new_parent = self
72 self.extend_speech_balloon = if self.settings.blank?
75 JSON.parse(self.settings)
77 self.balloon.extend_balloon = if self.balloon.settings.blank?
80 JSON.parse(self.get_balloon.settings)
82 self.speech.extend_speech = if self.speech.settings.blank?
85 JSON.parse(self.get_speech.settings)
89 def self.fold_extend_settings params
90 speech_balloon_settings = params[:speech_balloon][:settings]
91 if speech_balloon_settings.is_a?(Hash)
92 params[:speech_balloon][:settings] = speech_balloon_settings.to_json
94 balloon_settings = params[:speech_balloon][:balloon_attributes][:settings]
95 if balloon_settings.is_a?(Hash)
96 params[:speech_balloon][:balloon_attributes][:settings] = balloon_settings.to_json
98 speech_settings = params[:speech_balloon][:speech_attributes][:settings]
99 if speech_settings.is_a?(Hash)
100 params[:speech_balloon][:speech_attributes][:settings] = speech_settings.to_json
113 'speech_balloons.updated_at desc'
116 def self.list_json_opt
117 {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
121 {:include => {:panel => {:author => {}}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
124 def self.show_json_opt
125 {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
128 def store operators, attr
130 sb = self.panel.speech_balloons.build
133 self.panel.speech_balloons.each do |speech_balloon|
134 next unless speech_balloon == self
136 speech_balloon.attributes = attr
140 self.panel.store({}, operators)
144 self.panel.remove_element(self, au)
148 @parts ||= [self.balloon, self.speech]
152 self.speech_balloon_template.engine_name + '/'
155 def path_name with_engine = false
156 (with_engine ? self.engine_path_name : '') +
160 def form_template with_engine = false
161 self.path_name(true) + '/form'
164 def speech_form_template with_engine = false
165 self.engine_path_name + 'speeches/form'
168 def balloon_form_template with_engine = false
169 self.engine_path_name + 'balloons/form'
172 def scenario_template with_engine = false
173 self.path_name(true) + '/scenario'
176 def element_face_template with_engine = false
177 self.path_name(false) + '/element_face'
181 ERB::Util.html_escape(self.caption.to_s) + self.balloon.scenario.to_s +
182 self.speech.scenario.to_s
186 self.caption.to_s + self.balloon.plain_scenario.to_s +
187 self.speech.plain_scenario.to_s