OSDN Git Service

t#31687:fiix remove_element
[pettanr/pettanr.git] / app / models / panel.rb
index 8970687..108681a 100644 (file)
@@ -331,6 +331,27 @@ class Panel < ActiveRecord::Base
     res
   end
   
+  def remove_element target, au
+    ct = target.t
+    cz = target.z
+    panel_attributes = {}
+    self.panel_elements.each do |elm|
+      attr = elm.attributes
+      if elm == target
+        attr['_destroy'] = true
+      end
+      if elm.t > ct
+        attr['t']  -= 1 
+      end
+      if elm.z > cz
+        attr['z']  -= 1 
+      end
+      panel_attributes[elm.class.to_s.tableize + '_attributes'] ||= {}
+      panel_attributes[elm.class.to_s.tableize + '_attributes'][elm.id] = attr
+    end
+    self.store(panel_attributes, au)
+  end
+  
   def destroy_with_elements
     res = false
     Panel.transaction do