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.load_manifest
12 return nil unless self.my_manifest
13 r = self._valid_encode_columns
14 define_singleton_method("valid_encode_columns") do
17 define_singleton_method("parent_model") do |tree_name|
18 self.my_manifest.tree[tree_name].parent_model
20 define_singleton_method("child_models") do |tree_name|
21 self.my_manifest.child_models tree_name
24 define_method("parent_model") do |tree_name|
25 self.__send__ self.class.parent_model(tree_name).item_name
33 before_validation :valid_encode
36 Manifest.manifest.models[self.item_name]
44 self.singular.pluralize
48 self.singular.underscore
59 def self.path_name with_engine = false
60 self.plural.underscore
63 def self.visible_count_options
79 def self.list_json_opt
83 def self.show item_id, operators
85 opt.merge!(self.show_opt)
86 item = self.find(item_id, opt)
87 raise ActiveRecord::Forbidden unless item.visible?(operators)
95 def self.show_json_opt
101 def self.fold_extend_settings params
102 speech_balloon_settings = params[:speech_balloon][:settings]
103 if speech_balloon_settings.is_a?(Hash)
104 params[:speech_balloon][:settings] = speech_balloon_settings.to_json
106 balloon_settings = params[:speech_balloon][:balloon_attributes][:settings]
107 if balloon_settings.is_a?(Hash)
108 params[:speech_balloon][:balloon_attributes][:settings] = balloon_settings.to_json
110 speech_settings = params[:speech_balloon][:speech_attributes][:settings]
111 if speech_settings.is_a?(Hash)
112 params[:speech_balloon][:speech_attributes][:settings] = speech_settings.to_json
116 def extend_engine_module
117 self.extend self.speech_balloon_template.engine_speech_balloon_module
118 self.elements.each do |element|
132 self.class.table_name
135 def path_name with_engine = false
136 self.class.path_name(with_engine)
139 def form_template with_engine = false
140 self.path_name(with_engine) + '/form'
148 self.extend_column ? self.attributes[self.extend_column] : self.item_name
152 self.extend_item_name
156 self.class.valid_encode_columns.each do |a|
157 next if attributes[a] == nil
158 raise Pettanr::BadRequest unless attributes[a].valid_encoding?
168 def visible? operators
169 if Manifest.manifest.magic_numbers['run_mode'] == 0
170 return false unless operators.guest?
172 return false unless operators.resource_reader?
178 self.respond_to? :editor
186 self.new_record? ? 'stored' : 'new'
189 def tag_attributes name = nil, opt = {}
191 'data-pool_type' => self.dom_pool_type, 'data-id' => self.dom_id,
192 'data-item_name' => self.item_name
194 r.merge!({'id' => self.dom_item_id(name)}) if self.editize?
199 def field_tag_attributes column_name, opt = {}
200 self.tag_attributes(column_name, opt).merge(
201 {'data-column_name' => column_name}