X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=lib%2Fpeta%2Felement.rb;h=e1abd935a5cfeafeb3176575f3408b22d9e512ef;hb=db2ae5f3a07c071851a78dd76fc007db3dfda570;hp=3587186c3b04bc1d102759d81d760a768e5ec52e;hpb=bef6152463093529c01b67c2c2523d9e8912667c;p=pettanr%2Fpettanr.git diff --git a/lib/peta/element.rb b/lib/peta/element.rb index 3587186c..e1abd935 100644 --- a/lib/peta/element.rb +++ b/lib/peta/element.rb @@ -1,9 +1,30 @@ 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 + self.parent_model.root_model + else + self + end + end def self.list_opt_for_panel {} @@ -17,6 +38,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 +85,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 +96,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