OSDN Git Service

t#31779:element lib
[pettanr/pettanr.git] / app / models / speech_balloon.rb
index 6ca04cd..421127b 100644 (file)
@@ -1,4 +1,6 @@
 class SpeechBalloon < ActiveRecord::Base
+  include Element
+  include ElementInspire
   has_one :balloon, :dependent => :destroy
   has_one :speech, :dependent => :destroy
   belongs_to :speech_balloon_template
@@ -23,6 +25,28 @@ class SpeechBalloon < ActiveRecord::Base
     end
   end
   
+  def self.list_opt_for_panel
+    {
+      :speech_balloons => {:balloon => {}, :speech => {}}
+    }
+  end
+  
+  def self.show_opt_for_panel
+    {
+      :speech_balloons => {:balloon => {}, :speech => {}}
+    }
+  end
+  
+  def self.json_opt_for_panel
+    {
+      :balloon => {}, :speech => {}
+    }
+  end
+  
+  def self.has_picture?
+    false
+  end
+  
   def supply_default
     if self.panel
       self.t = self.panel.new_t 
@@ -44,6 +68,30 @@ class SpeechBalloon < ActiveRecord::Base
     self.panel.visible? roles
   end
   
+  def tag_id c = nil
+    'panel' + tag_panel_id + 'speech_balloon' + tag_element_id + c.to_s
+  end
+  
+  def field_tag_id f
+    self.tag_id + f.to_s
+  end
+  
+  def tag_panel_id
+    self.panel.new_record? ? '0' : self.panel.id.to_s
+  end
+  
+  def tag_element_id
+    self.new_record? ? '0' : self.id.to_s
+  end
+  
+  def tag_element_type
+    'speech_balloon'
+  end
+  
+  def field_tree f
+    'panels-' + self.tag_panel_id + '-speech_balloons_attributes-' + self.tag_element_id + '-' + f.to_s
+  end
+  
   def self.default_page_size
     25
   end
@@ -141,22 +189,11 @@ class SpeechBalloon < ActiveRecord::Base
   end
   
   def remove au
-    d = false
-    speech_balloons_attributes = {}
-    self.panel.speech_balloons.each do |speech_balloon|
-      attr = speech_balloon.attributes
-      if speech_balloon == self
-        attr['_destroy'] = true
-        d = true
-      else
-        if d
-          attr['t']  -= 1 
-        end
-      end
-      speech_balloons_attributes[speech_balloon.id] = attr
-    end
-    self.panel.attributes = {:speech_balloons_attributes => speech_balloons_attributes}
-    self.panel.store({}, au)
+    self.panel.remove_element(self, au)
+  end
+  
+  def parts
+    @parts ||= [self.balloon, self.speech]
   end
   
   def scenario