2 class Item < ActiveRecord::Base
3 self.abstract_class = true
8 before_validation :valid_encode
15 self.singular.pluralize
19 self.singular.underscore
30 def self.path_name with_engine = false
31 self.plural.underscore
34 def self.valid_encode_columns
38 def self.visible_count_options
54 def self.list_json_opt
58 def self.show item_id, operators
60 opt.merge!(self.show_opt)
61 item = self.find(item_id, opt)
62 raise ActiveRecord::Forbidden unless item.visible?(operators)
70 def self.show_json_opt
74 def self.visible_count
75 self.count self.visible_count_options
78 def self.visible_count_options
84 def self.fold_extend_settings params
85 speech_balloon_settings = params[:speech_balloon][:settings]
86 if speech_balloon_settings.is_a?(Hash)
87 params[:speech_balloon][:settings] = speech_balloon_settings.to_json
89 balloon_settings = params[:speech_balloon][:balloon_attributes][:settings]
90 if balloon_settings.is_a?(Hash)
91 params[:speech_balloon][:balloon_attributes][:settings] = balloon_settings.to_json
93 speech_settings = params[:speech_balloon][:speech_attributes][:settings]
94 if speech_settings.is_a?(Hash)
95 params[:speech_balloon][:speech_attributes][:settings] = speech_settings.to_json
100 Object.const_get self.extend_column
103 def extend_engine_module
104 self.extend self.engine.extend_module
105 self.elements.each do |element|
119 self.class.table_name
122 def extend_column_name
127 self.extend_column ? self.attributes[self.extend_column] : self.item_name
131 self.class.valid_encode_columns.each do |a|
132 next if attributes[a] == nil
133 raise Pettanr::BadRequest unless attributes[a].valid_encoding?
143 def visible? operators
144 if Manifest.manifest.magic_numbers['run_mode'] == 0
145 return false unless operators.guest?
147 return false unless operators.resource_reader?
156 self.new_record? ? '0' : self.id.to_s
159 def tag_item_id c = nil
160 self.item_name + self.item_id + c.to_s
163 def dom_id_item_field field_name
164 self.tag_item_id + field_name.to_s
167 def path_name with_engine = false
168 self.class.path_name(with_engine)
171 def form_template with_engine = false
172 self.path_name(with_engine) + '/form'
175 def tag_item_attributes column = nil, opt = {}
177 :id => self.field_tag_id(column), :panel_id => self.tag_panel_id,
178 :element_id => self.tag_element_id, :element_type => self.tag_element_type
185 def field_tag_attributes column, no_attr, opt = {}
186 self.tag_attributes(column).merge(
187 {:column => column, :new_index => self.tag_new_index, :no_attr => no_attr}
191 #render element by body
192 def any_tag_attributes name = nil, opt = {}
193 r = self.tag_attributes(name)
195 {:new_index => self.tag_new_index}
200 def select_tag_attributes(selected, column, no_attr)
203 {:html => {:selected => selected}},
204 self.field_tag_attributes(column, no_attr)
208 def tag_attr column = nil, opt = {}
209 self.tag_attributes(column, opt).to_attr
212 def field_tag_attr column, no_attr, opt = {}
213 self.field_tag_attributes(column, no_attr, opt).to_attr
216 def any_tag_attr name = nil, opt = {}
217 self.any_tag_attributes(name, opt).to_attr