OSDN Git Service

fix extend
[pettanr/pettanr.git] / lib / peta / element.rb
index 3587186..5f9f9e5 100644 (file)
@@ -1,9 +1,37 @@
 module Peta
-  class Element < Content
+  class Element < ElementNestableContent
     self.abstract_class = true
     
     # Dynamic ClassMethods
     
+    def self.load_manifest
+      super
+      # Class Methods
+      pm = Manifest.manifest.models[self.my_peta.parent_model_name].classify
+      define_singleton_method("parent_model") do 
+        pm
+      end
+      # Instance Methods
+    end
+    
+    def self.element?
+      true
+    end
+    
+    def self.root_model
+      if self.parent_model and self.parent_model.element?
+        self.parent_model.root_model
+      else
+        self
+      end
+    end
+    
+    # Instance Methods
+    
+    def visible? operators
+      return false unless super
+      true
+    end
     
     def self.list_opt_for_panel
       {}
@@ -17,6 +45,23 @@ module Peta
       {}
     end
     
+    def self.panelize elements_attributes
+      elements_attributes = [elements_attributes] unless elements_attributes.is_a?(Array)
+      hash = {}
+      index = 0
+      elements_attributes.each do |element_attributes|
+        hash[self.to_s.tableize + '_attributes'] ||= {}
+        n = if element_attributes['id']
+          element_attributes['id'].to_s
+        else
+          index += 1
+          'new' + index.to_s 
+        end
+        hash[self.to_s.tableize + '_attributes'][n] = element_attributes
+      end
+      hash
+    end
+    
     def has_picture?
       false
     end
@@ -47,7 +92,7 @@ module Peta
     
     def tag_attributes column = nil, opt = {}
       r = super
-      r.merge({'data-parent_dom_id' => self.parent.dom_item_id}) if self.editor
+      r.merge({'data-parent_dom_id' => self.parent.dom_item_id}) if self.editize?
       r
     end
     
@@ -58,6 +103,17 @@ module Peta
       })
     end
     
+    def copy_attributes opt = {}
+      r = self.attributes
+      r.delete 'id'
+    r.delete 'panel_id'
+      r.delete 't' unless opt[:all]
+      r.delete 'z' unless opt[:all]
+      r.delete 'created_at'
+      r.delete 'updated_at'
+      r
+    end
+    
   end
 end