1 class Pettanr::Item < ActiveRecord::Base
2 self.abstract_class = true
7 before_validation :valid_encode
9 def self.valid_encode_columns
18 self.singular.pluralize
22 self.singular.underscore
25 def self.path_name with_engine = false
26 self.plural.underscore
41 def self.list_json_opt
45 def self.show item_id, operators
47 opt.merge!(self.show_opt)
48 item = self.find(item_id, opt)
49 raise ActiveRecord::Forbidden unless item.visible?(operators)
57 def self.show_json_opt
61 def self.visible_count
62 self.count self.visible_count_options
65 def self.visible_count_options
76 self.class.valid_encode_columns.each do |a|
77 next if attributes[a] == nil
78 raise Pettanr::BadRequest unless attributes[a].valid_encoding?
88 def visible? operators
89 if MagicNumber['run_mode'] == 0
90 return false unless operators.guest?
92 return false unless operators.resource_reader?
98 self.new_record? ? '0' : self.id.to_s
101 def tag_item_id c = nil
102 self.item_name + self.item_id + c.to_s
105 def dom_id_item_field field_name
106 self.tag_item_id + field_name.to_s
109 def path_name with_engine = false
110 self.class.path_name(with_engine)
113 def form_template with_engine = false
114 self.path_name(with_engine) + '/form'
117 def tag_item_attributes column = nil, opt = {}
119 :id => self.field_tag_id(column), :panel_id => self.tag_panel_id,
120 :element_id => self.tag_element_id, :element_type => self.tag_element_type
124 def field_tag_attributes column, no_attr, opt = {}
125 self.tag_attributes(column).merge(
126 {:column => column, :new_index => self.tag_new_index, :no_attr => no_attr}
130 #render element by body
131 def any_tag_attributes name = nil, opt = {}
132 r = self.tag_attributes(name)
134 {:new_index => self.tag_new_index}
139 def select_tag_attributes(selected, column, no_attr)
142 {:html => {:selected => selected}},
143 self.field_tag_attributes(column, no_attr)
147 def tag_attr column = nil, opt = {}
148 self.tag_attributes(column, opt).to_attr
151 def field_tag_attr column, no_attr, opt = {}
152 self.field_tag_attributes(column, no_attr, opt).to_attr
155 def any_tag_attr name = nil, opt = {}
156 self.any_tag_attributes(name, opt).to_attr