module Peta
class Item < ActiveRecord::Base
self.abstract_class = true
+ attr :boosters
# Dynamic ClassMethods
define_singleton_method("valid_encode_columns") do
r
end
- define_singleton_method("parent_model") do |tree_name|
- self.my_manifest.tree[tree_name].parent_model
+ r = self.my_manifest.child_models
+ define_singleton_method("child_models") do
+ r
end
- define_singleton_method("child_models") do |tree_name|
- self.my_manifest.child_models tree_name
+ r = self.my_manifest.child_element_names
+ define_singleton_method("child_element_names") do
+ r
end
# Instance Methods
- define_method("parent_model") do |tree_name|
- self.__send__ self.class.parent_model(tree_name).item_name
- end
end
# ClassMethods
before_validation :valid_encode
+ def self.my_peta
+ Manifest.manifest.items[self.item_name]
+ end
+
def self.my_manifest
Manifest.manifest.models[self.item_name]
end
false
end
+ def self.element?
+ false
+ end
+
+ def self.root?
+ false
+ end
+
+ def self.parent_model
+ nil
+ end
+
def self.path_name with_engine = false
self.plural.underscore
end
+ def self.find_boost_name column_name
+ self.my_peta.find_boost_name column_name
+ end
+
+ def self.extend_column? column_name
+ self.my_peta.extend_column? column_name
+ end
+
def self.visible_count_options
nil
end
opt = {}
opt.merge!(self.show_opt)
item = self.find(item_id, opt)
+ item.boosts 'read'
raise ActiveRecord::Forbidden unless item.visible?(operators)
item
end
{}
end
- #InstanceMethods
-
def self.fold_extend_settings params
- speech_balloon_settings = params[:speech_balloon][:settings]
- if speech_balloon_settings.is_a?(Hash)
- params[:speech_balloon][:settings] = speech_balloon_settings.to_json
- end
- balloon_settings = params[:speech_balloon][:balloon_attributes][:settings]
- if balloon_settings.is_a?(Hash)
- params[:speech_balloon][:balloon_attributes][:settings] = balloon_settings.to_json
+ self.my_peta.boost.each do |name, manifest|
+ my_settings = params[self.item_name][manifest.settings_column_name]
+ if my_settings.is_a?(Hash)
+ params[self.item_name][manifest.settings_column_name] = my_settings.to_json
+ end
end
- speech_settings = params[:speech_balloon][:speech_attributes][:settings]
- if speech_settings.is_a?(Hash)
- params[:speech_balloon][:speech_attributes][:settings] = speech_settings.to_json
+ self.child_models.each do |child_model|
+ child_model.fold_extend_settings params
end
end
- def extend_engine_module
- self.extend self.speech_balloon_template.engine_speech_balloon_module
- self.elements.each do |element|
- element.extend_item
- end
- end
+ #InstanceMethods
def item_name
self.class.item_name
self.path_name(with_engine) + '/form'
end
- def extend_column
- nil
- end
-
- def extend_item_name
- self.extend_column ? self.attributes[self.extend_column] : self.item_name
- end
-
def form_name
- self.extend_item_name
+ self.extend_column ? self.attributes[self.extend_column] : self.item_name
end
def valid_encode
end
end
+ def boosts level
+ self.class.my_peta.boost.each do |boost_name, boost_manifest|
+ next if level == 'read' and boost_manifest.level == 'post'
+ self.boost boost_manifest
+ end
+ end
+
+ def boost boost_manifest
+ @boosters ||= {}
+ @boosters[boost_manifest.name] = Locmare::Booster.new(boost_manifest, self)
+ end
+
+ def boosters
+ @boosters
+ end
+
+ def extend_column? column_name
+ self.class.extend_column? column_name
+ end
+
def supply_default
+ self.class.my_peta.supply_defaults self
end
def overwrite
self.new_record? ? 'stored' : 'new'
end
+ def merge_dom_item_id attr, name = nil
+ if self.editize?
+ attr.merge({'id' => self.dom_item_id(name)})
+ else
+ attr
+ end
+ end
+
def tag_attributes 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(name)}) if self.editize?
+ r = self.merge_dom_item_id r, name
r.merge!(opt)
r
end
)
end
+ def post_attribute_key
+ self.dom_id
+ end
+
end
end