2 class Item < ActiveRecord::Base
3 self.abstract_class = true
7 def self._valid_encode_columns
8 self.my_manifest.valid_encode_columns
11 def self._extend_column_name
12 self.my_manifest.extend_column_name
15 def self.load_manifest
16 return nil unless self.my_manifest
17 r = self._valid_encode_columns
18 define_singleton_method("valid_encode_columns") do
21 define_singleton_method("parent_model") do |tree_name|
22 self.my_manifest.tree[tree_name].parent_model
24 define_singleton_method("child_models") do |tree_name|
25 self.my_manifest.child_models tree_name
27 define_singleton_method("child_element_names") do |tree_name|
28 self.my_manifest.child_element_names tree_name
31 n = self._extend_column_name
32 define_singleton_method("extend_column_name") do
41 before_validation :valid_encode
44 Manifest.manifest.models[self.item_name]
52 self.singular.pluralize
56 self.singular.underscore
67 def self.path_name with_engine = false
68 self.plural.underscore
71 def self.visible_count_options
87 def self.list_json_opt
91 def self.show item_id, operators
93 opt.merge!(self.show_opt)
94 item = self.find(item_id, opt)
95 self.boost if self.boost_level_is_read?
96 raise ActiveRecord::Forbidden unless item.visible?(operators)
104 def self.show_json_opt
108 def self.fold_extend_settings params
109 self.my_peta.boost.each do |name, manifest|
110 my_settings = params[self.item_name][manifest.settings_column_name]
111 if my_settings.is_a?(Hash)
112 params[self.item_name][manifest.settings_column_name] = my_settings.to_json
115 self.child_models.each do |child_model|
116 child_model.fold_extend_settings params
131 self.class.table_name
134 def boost_level_is_read?
135 self.class.my_peta.level == 'show'
138 def extend_column_name
139 self.class.extend_column_name
142 def path_name with_engine = false
143 self.class.path_name(with_engine)
146 def form_template with_engine = false
147 self.path_name(with_engine) + '/form'
151 self.extend_column ? self.attributes[self.extend_column] : self.item_name
155 self.class.valid_encode_columns.each do |a|
156 next if attributes[a] == nil
157 raise Pettanr::BadRequest unless attributes[a].valid_encoding?
162 Object.const_get self.attributes[self.extend_column_name]
165 def my_engine_resource
166 Manifest.manifest.system_resources.engine_resources[self.table_name]
170 return false unless self.my_engine_resource
171 self.my_engine_resource.resource_items.include? self.attributes[self.extend_column_name]
175 return false unless self.engine?
176 self.engine.boost self
185 self.my_peta.boost.each do |name, manifest|
186 manifest.engine_model.engine_extend_module.supply_default
193 def visible? operators
194 if Manifest.manifest.magic_numbers['run_mode'] == 0
195 return false unless operators.guest?
197 return false unless operators.resource_reader?
203 self.respond_to? :editor
211 self.new_record? ? 'stored' : 'new'
214 def merge_dom_item_id attr, name = nil
216 attr.merge({'id' => self.dom_item_id(name)})
222 def tag_attributes name = nil, opt = {}
224 'data-pool_type' => self.dom_pool_type, 'data-id' => self.dom_id,
225 'data-item_name' => self.item_name
227 r = self.merge_dom_item_id r, name
232 def field_tag_attributes column_name, opt = {}
233 self.tag_attributes(column_name, opt).merge(
234 {'data-column_name' => column_name}
238 def post_attribute_key