1 class Pettanr::Item < ActiveRecord::Base
2 self.abstract_class = true
7 before_validation :valid_encode
14 self.singular.pluralize
18 self.singular.underscore
29 def self.path_name with_engine = false
30 self.plural.underscore
33 def self.valid_encode_columns
37 def self.visible_count_options
53 def self.list_json_opt
57 def self.show item_id, operators
59 opt.merge!(self.show_opt)
60 item = self.find(item_id, opt)
61 raise ActiveRecord::Forbidden unless item.visible?(operators)
69 def self.show_json_opt
73 def self.visible_count
74 self.count self.visible_count_options
77 def self.visible_count_options
88 self.class.valid_encode_columns.each do |a|
89 next if attributes[a] == nil
90 raise Pettanr::BadRequest unless attributes[a].valid_encoding?
100 def visible? operators
101 if MagicNumber['run_mode'] == 0
102 return false unless operators.guest?
104 return false unless operators.resource_reader?
110 self.new_record? ? '0' : self.id.to_s
113 def tag_item_id c = nil
114 self.item_name + self.item_id + c.to_s
117 def dom_id_item_field field_name
118 self.tag_item_id + field_name.to_s
121 def path_name with_engine = false
122 self.class.path_name(with_engine)
125 def form_template with_engine = false
126 self.path_name(with_engine) + '/form'
129 def tag_item_attributes column = nil, opt = {}
131 :id => self.field_tag_id(column), :panel_id => self.tag_panel_id,
132 :element_id => self.tag_element_id, :element_type => self.tag_element_type
136 def field_tag_attributes column, no_attr, opt = {}
137 self.tag_attributes(column).merge(
138 {:column => column, :new_index => self.tag_new_index, :no_attr => no_attr}
142 #render element by body
143 def any_tag_attributes name = nil, opt = {}
144 r = self.tag_attributes(name)
146 {:new_index => self.tag_new_index}
151 def select_tag_attributes(selected, column, no_attr)
154 {:html => {:selected => selected}},
155 self.field_tag_attributes(column, no_attr)
159 def tag_attr column = nil, opt = {}
160 self.tag_attributes(column, opt).to_attr
163 def field_tag_attr column, no_attr, opt = {}
164 self.field_tag_attributes(column, no_attr, opt).to_attr
167 def any_tag_attr name = nil, opt = {}
168 self.any_tag_attributes(name, opt).to_attr