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
23 before_validation :valid_encode
26 Manifest.manifest.models[self.item_name]
34 self.singular.pluralize
38 self.singular.underscore
49 def self.path_name with_engine = false
50 self.plural.underscore
53 def self.visible_count_options
69 def self.list_json_opt
73 def self.show item_id, operators
75 opt.merge!(self.show_opt)
76 item = self.find(item_id, opt)
77 raise ActiveRecord::Forbidden unless item.visible?(operators)
85 def self.show_json_opt
91 def self.fold_extend_settings params
92 speech_balloon_settings = params[:speech_balloon][:settings]
93 if speech_balloon_settings.is_a?(Hash)
94 params[:speech_balloon][:settings] = speech_balloon_settings.to_json
96 balloon_settings = params[:speech_balloon][:balloon_attributes][:settings]
97 if balloon_settings.is_a?(Hash)
98 params[:speech_balloon][:balloon_attributes][:settings] = balloon_settings.to_json
100 speech_settings = params[:speech_balloon][:speech_attributes][:settings]
101 if speech_settings.is_a?(Hash)
102 params[:speech_balloon][:speech_attributes][:settings] = speech_settings.to_json
106 def extend_engine_module
107 self.extend self.speech_balloon_template.engine_speech_balloon_module
108 self.elements.each do |element|
122 self.class.table_name
125 def path_name with_engine = false
126 self.class.path_name(with_engine)
129 def form_template with_engine = false
130 self.path_name(with_engine) + '/form'
138 self.extend_column ? self.attributes[self.extend_column] : self.item_name
142 self.extend_item_name
146 self.class.valid_encode_columns.each do |a|
147 next if attributes[a] == nil
148 raise Pettanr::BadRequest unless attributes[a].valid_encoding?
158 def visible? operators
159 if Manifest.manifest.magic_numbers['run_mode'] == 0
160 return false unless operators.guest?
162 return false unless operators.resource_reader?
188 self.new_record? ? 'stored' : 'new'
191 def dom_item_id name = nil
192 r = [self.editor.eid, self.dom_pool_type, self.item_name, self.dom_id]
193 r += name.to_s if column_name
197 def tag_attributes name = nil, opt = {}
199 'data-pool_type' => self.dom_pool_type, 'data-id' => self.dom_id,
200 'data-item_name' => self.item_name
202 r.merge!({'id' => self.dom_item_id(name)}) if self.editor
207 def field_tag_attributes column_name, opt = {}
208 self.tag_attributes(column_name, opt).merge(
209 {'data-column_name' => column_name}