+ def field_tag_attributes column_name, opt = {}
+ self.tag_attributes(column_name, opt).merge(
+ {'data-column_name' => column_name}
+ )
+ end
+
+ def post_attribute_key
+ self.dom_id
+ end
+
+ ##################################################################
+ # importer
+ ##################################################################
+
+ def self.each_import data
+ data.each do |n, d|
+ yield n, d
+ end
+ end
+
+ def self.import_system_picture attr
+ d = attr["text"]
+ return false if d.blank?
+ imager = PettanImager.load(Base64.decode64(d.to_s))
+ return false unless imager
+ sp = SystemPicture.store(imager)
+ return false unless sp
+ sp.id
+ end
+
+ def self.replace_system_picture attr
+ attr.each do |name, value|
+ if value.is_a? Hash
+ r = if name.to_s =~ /_id$/
+ self.import_system_picture value
+ else
+ self.replace_system_picture value
+ end
+ return false unless r
+ attr[name] = r
+ end
+ end
+ end
+
+ def self.modify_object(name, attr, key = 'name')
+ c = 'find_by_' + key.to_s
+ r = self.__send__ c, name
+ if r
+ r.attributes = attr
+ else
+ r = self.new attr
+ r[key] = name
+ end
+ r
+ end
+
+ def self.import_list(attrs, &blk)
+ res = []
+ self.transaction do
+ attrs.each do |name, item|
+ m = blk.call(name, item)
+ res.push(m) unless m.valid?
+ end
+ raise ActiveRecord::Rollback unless res.empty?
+ end
+ res
+ end
+
+ def self.import_text(text, &blk)
+ attrs = JSON.parse(text)
+ self.import_list attrs, &blk
+ end
+
+ def self.import_file(filename, &blk)
+ text = File.open(filename, 'r').read
+ self.import_text text, &blk