OSDN Git Service

fix license picture
[pettanr/pettanr.git] / app / models / speech_balloon.rb
1 class SpeechBalloon < Peta::Element
2   load_manifest
3   has_one :balloon, :dependent => :destroy
4   has_one :speech, :dependent => :destroy
5   belongs_to :speech_balloon_template
6   belongs_to :panel
7   
8   accepts_nested_attributes_for :balloon
9   accepts_nested_attributes_for :speech
10   
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}
17   
18   def self.by_author_list_includes
19     {
20       :panel => {
21         :author => {}
22       }
23     }
24   end
25   
26   def self.has_picture?
27     false
28   end
29   
30   def supply_default
31     if self.panel
32       self.t = self.panel.new_t 
33       self.z = self.panel.new_z 
34     end
35   end
36   
37   def overwrite pid
38     self.panel_id = pid
39   end
40   
41   def symbol_option
42     self.speech_balloon_template.symbol_option
43   end
44   
45   def self.public_list_where
46     'panels.publish > 0'
47   end
48   
49   def self.show_opt
50     {:include => {:panel => {:author => {}}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
51   end
52   
53   def scenario_template with_engine = false
54     self.path_name(true) + '/scenario'
55   end
56   
57   def element_face_template with_engine = false
58     self.path_name(false) + '/element_face'
59   end
60   
61   def scenario
62     ERB::Util.html_escape(self.caption.to_s) + self.balloon.scenario.to_s + 
63     self.speech.scenario.to_s
64   end
65   
66   def plain_scenario
67     self.caption.to_s + self.balloon.plain_scenario.to_s + 
68     self.speech.plain_scenario.to_s
69   end
70   
71 end