OSDN Git Service

t#31715:speech_balloon boost
[pettanr/pettanr.git] / app / models / speech.rb
index daeec69..9bf34cd 100644 (file)
@@ -1,7 +1,9 @@
 class Speech < ActiveRecord::Base
   belongs_to :speech_balloon
+  belongs_to :writing_format
   
   validates :speech_balloon_id, :numericality => {:allow_blank => true}
+  validates :writing_format_id, :presence => true, :numericality => true, :existence => {:both => false}
   validates :x, :presence => true, :numericality => true
   validates :y, :presence => true, :numericality => true
   validates :width, :presence => true, :numericality => true, :natural_number => true
@@ -35,8 +37,16 @@ class Speech < ActiveRecord::Base
     self.speech_balloon.panel.visible? roles
   end
   
+  def new_speech_balloon
+    @new_speech_balloon
+  end
+  
+  def new_speech_balloon= v
+    @new_speech_balloon = v
+  end
+  
   def get_speech_balloon
-    self.speech_balloon
+    self.speech_balloon || @new_speech_balloon
   end
   
   def get_panel_id
@@ -80,8 +90,12 @@ class Speech < ActiveRecord::Base
     'speech'
   end
   
-  def field_tree f
-    'panels-' + self.tag_panel_id + '-speech_balloons_attributes-' + self.tag_element_id + '-speech_attributes-' + f.to_s
+  def tag_new_index
+    if self.get_speech_balloon == nil
+      nil
+    else
+      self.get_speech_balloon.tag_new_index
+    end
   end
   
   def self.default_page_size
@@ -150,8 +164,12 @@ class Speech < ActiveRecord::Base
     {'speech_attributes' => speech_attributes}
   end
   
+  def writing_format_engine_model
+    self.writing_format.engine_model
+  end
+  
   def scenario
-    ERB::Util.html_escape(self.content)
+    self.writing_format_engine_model.render self.content
   end
   
   def plain_scenario