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, :allow_destroy => true
9 accepts_nested_attributes_for :speech, :allow_destroy => true
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_module_name, :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 scope :with_panel, -> do
22 scope :with_speech_balloon_template, -> do
23 includes(:speech_balloon_template)
26 scope :find_index, -> do
27 with_panel.where(Panel.arel_table[:publish].gt 0).references(:panel)
30 scope :find_private, -> (operators) do
31 with_panel.where(Panel.arel_table[:author_id].eq operators.author.id).references(:panel)
34 scope :find_by_panel, -> (panel_id) do
35 find_index.where(panel_id: panel_id).references(:panel)
38 scope :find_by_speech_balloon_template, -> (speech_balloon_template_id) do
39 find_index.where(speech_balloon_template_id: speech_balloon_template_id).references(:panel)
42 scope :find_by_author, -> (author_id) do
43 find_index.where(Panel.arel_table[:author_id].eq author_id).references(:panel)
46 def self.by_author_list_includes
60 self.t = self.panel.new_t
61 self.z = self.panel.new_z
70 self.speech_balloon_template.symbol_option
77 def self.public_list_where list
82 {:include => {:panel => {:author => {}}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
85 def scenario_template with_engine = false
86 self.path_name(true) + '/scenario'
89 def element_face_template with_engine = false
90 self.path_name(false) + '/element_face'
94 ERB::Util.html_escape(self.caption.to_s) + self.balloon.scenario.to_s +
95 self.speech.scenario.to_s
99 self.caption.to_s + self.balloon.plain_scenario.to_s +
100 self.speech.plain_scenario.to_s