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 :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}
18 def self.by_author_list_includes
26 def self.list_opt_for_panel
28 :speech_balloons => {:balloon => {}, :speech => {}}
32 def self.show_opt_for_panel
34 :speech_balloons => {:balloon => {}, :speech => {}}
38 def self.json_opt_for_panel
40 :balloon => {}, :speech => {}
50 self.t = self.panel.new_t
51 self.z = self.panel.new_z
60 self.speech_balloon_template.symbol_option
67 def self.public_list_where
72 'speech_balloons.updated_at desc'
75 def self.list_json_opt
76 {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
80 {:include => {:panel => {:author => {}}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
83 def self.show_json_opt
84 {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
87 def store operators, attr
89 sb = self.panel.speech_balloons.build
92 self.panel.speech_balloons.each do |speech_balloon|
93 next unless speech_balloon == self
95 speech_balloon.attributes = attr
99 self.panel.store({}, operators)
103 self.panel.remove_element(self, au)
107 @parts ||= [self.balloon, self.speech]
111 self.speech_balloon_template.engine_name + '/'
114 def path_name with_engine = false
115 (with_engine ? self.engine_path_name : '') +
119 def form_template with_engine = false
120 self.path_name(true) + '/form'
123 def speech_form_template with_engine = false
124 self.engine_path_name + 'speeches/form'
127 def balloon_form_template with_engine = false
128 self.engine_path_name + 'balloons/form'
131 def scenario_template with_engine = false
132 self.path_name(true) + '/scenario'
135 def element_face_template with_engine = false
136 self.path_name(false) + '/element_face'
140 ERB::Util.html_escape(self.caption.to_s) + self.balloon.scenario.to_s +
141 self.speech.scenario.to_s
145 self.caption.to_s + self.balloon.plain_scenario.to_s +
146 self.speech.plain_scenario.to_s