module Peta
class Item < ActiveRecord::Base
self.abstract_class = true
+
+ # Dynamic ClassMethods
+
+ def self._valid_encode_columns
+ self.my_manifest.valid_encode_columns
+ end
+
+ def self.load_manifest
+ return nil unless self.my_manifest
+ r = self._valid_encode_columns
+ define_singleton_method("valid_encode_columns") do
+ r
+ end
+ end
+
# ClassMethods
# class_name
# table_name
before_validation :valid_encode
+ def self.my_manifest
+ Manifest.manifest.models[self.item_name]
+ end
+
def self.singular
self.to_s
end
self.plural.underscore
end
- def self.valid_encode_columns
- []
- end
-
def self.visible_count_options
nil
end
self.class.table_name
end
+ def path_name with_engine = false
+ self.class.path_name(with_engine)
+ end
+
+ def form_template with_engine = false
+ self.path_name(with_engine) + '/form'
+ end
+
def extend_column
nil
end
true
end
- def dom_id_item
- self.new_record? ? '0' : self.id.to_s
+ def pool
+ @pool
end
- def tag_item_id c = nil
- self.item_name + self.item_id + c.to_s
+ def dom_id
+ self.new_record? ? '1' : self.id.to_s
end
- def dom_id_item_field field_name
- self.tag_item_id + field_name.to_s
+ def dom_pool_type
+ self.new_record? ? 'stored' : 'new'
end
- def path_name with_engine = false
- self.class.path_name(with_engine)
+ def dom_item_id column_name = nil
+ r = self.dom_pool_type + '-' + self.item_name + '-' + self.dom_id
+ r += '-' + column_name.to_s if column_name
+ r
end
- def form_template with_engine = false
- self.path_name(with_engine) + '/form'
- end
-
- def tag_item_attributes column = nil, opt = {}
- {
- :id => self.field_tag_id(column), :panel_id => self.tag_panel_id,
- :element_id => self.tag_element_id, :element_type => self.tag_element_type
- }.merge(opt)
+ def tag_attributes column_name = nil, opt = {}
+ r = {
+ 'data-pool_type' => self.dom_pool_type, 'data-id' => self.dom_id,
+ 'data-item_name' => self.item_name
+ }
+ r.merge!({'id' => self.dom_item_id(column_name)}) if self.pool
+ # 'data-parent_dom_id' => self.parent.dom_item_id
+ r.merge!(opt)
+ r
end
- def tag_new_index
- end
-
- def field_tag_attributes column, no_attr, opt = {}
- self.tag_attributes(column).merge(
- {:column => column, :new_index => self.tag_new_index, :no_attr => no_attr}
- ).merge(opt)
+ def field_tag_attributes column_name, opt = {}
+ self.tag_attributes(column_name, opt).merge(
+ {'data-column_name' => column_name}
+ )
end
#render element by body
r.merge(opt)
end
- def select_tag_attributes(selected, column, no_attr)
- [
- :last, :first,
- {:html => {:selected => selected}},
- self.field_tag_attributes(column, no_attr)
- ]
- end
-
- def tag_attr column = nil, opt = {}
- self.tag_attributes(column, opt).to_attr
- end
-
- def field_tag_attr column, no_attr, opt = {}
- self.field_tag_attributes(column, no_attr, opt).to_attr
- end
-
- def any_tag_attr name = nil, opt = {}
- self.any_tag_attributes(name, opt).to_attr
- end
-
end
end