OSDN Git Service

t#31725:add panel inspire
[pettanr/pettanr.git] / app / models / panel.rb
index 58a0bcf..dd919d0 100644 (file)
@@ -188,11 +188,6 @@ class Panel < ActiveRecord::Base
   end
   
   def parts
-    res = []
-    self.parts_element.each do |e|
-      res[e.t] = e
-    end
-    res
   end
   
   def zorderd_elements
@@ -204,7 +199,11 @@ class Panel < ActiveRecord::Base
   end
   
   def panel_elements
-    parts
+    res = []
+    self.parts_element.each do |e|
+      res[e.t] = e
+    end
+    res
   end
   
   @@elm_json_opt = {
@@ -239,11 +238,11 @@ class Panel < ActiveRecord::Base
   end
   
   def new_t
-    self.parts.size
+    self.panel_elements.size
   end
   
   def new_z
-    self.parts.size + 1
+    self.panel_elements.size + 1
   end
   
   def scenario
@@ -364,32 +363,14 @@ class Panel < ActiveRecord::Base
     res
   end
   
-  def copy au
-    attr = self.attributes
-    attr.delete 'id'
-    self.panel_elements.each_with_index do |elm, index|
-      elm_attr = elm.attributes
-      elm_attr.delete 'id'
-      elm_attr.delete 'panel_id'
-      elm_attr.delete 'created_at'
-      elm_attr.delete 'updated_at'
-      case elm.class.to_s
-      when 'PanelPicture'
-      when 'SpeechBalloon'
-        balloon_attr = elm.balloon.attributes
-        balloon_attr.delete 'id'
-        balloon_attr.delete 'speech_balloon_id'
-        elm_attr['balloon_attributes'] = balloon_attr
-        speech_attr = elm.speech.attributes
-        speech_attr.delete 'id'
-        speech_attr.delete 'speech_balloon_id'
-        elm_attr['speech_attributes'] = speech_attr
-      when 'GroundPicture'
-      when 'GroundColor'
-      end
-      attr[elm.class.to_s.tableize + '_attributes'] ||= {}
-      attr[elm.class.to_s.tableize + '_attributes'][index] = elm_attr
-    end
+  def copy
+    attr = self.copy_attributes
+    attr.merge! PanelPicture.panelize(self.panel_pictures.map {|elm|  elm.copy_attributes})
+    attr.merge! SpeechBalloon.panelize(self.speech_balloons.map {|elm|  elm.copy_attributes})
+    attr.merge! GroundPicture.panelize(self.ground_pictures.map {|elm|  elm.copy_attributes})
+    attr.merge! GroundColor.panelize(self.ground_colors.map {|elm|  elm.copy_attributes})
+    p attr
+    attr
   end
   
   def copy_attributes