-class LicenseGroup < ActiveRecord::Base
+#ライセンスグループ
+class LicenseGroup < Pettanr::Item
has_many :licenses
validates :name, :presence => true, :length => {:maximum => 50}, :uniqueness => true
validates :classname, :presence => true, :length => {:maximum => 50}
validates :caption, :presence => true, :length => {:maximum => 30}
- validates :url, :presence => true, :length => {:maximum => 200}, :url => true
+ validates :url, :presence => true, :length => {:maximum => 200}, :url => {:message => I18n.t('errors.messages.url')}
- def self.store name, attr
- lattr = attr["licenses_attributes"]
- attr.delete "licenses_attributes"
- r = LicenseGroup.modify_object name, attr
- if (c = License.stores(lattr)) > 0
- r.errors.add :base, 'licenses can not create'
- end
- r.save
- r
+ def self.valid_encode_columns
+ super + ['name', 'classname', 'caption', 'url']
end
- def self.import filename
- LicenseGroup.import_file(filename) {|name, attr| LicenseGroup.store(name, attr)}
+ def supply_default
+ end
+
+ def overwrite
end
- def self.list opt = {}
- opt.merge!(self.list_opt) unless opt[:include]
- opt.merge!({:order => 'license_groups.name asc'})
- LicenseGroup.find(:all, opt)
+ def self.list_where
+ ''
+ end
+
+ def self.list_order
+ 'license_groups.name asc'
+ end
+
+ def self.enable_list
+ LicenseGroup.find(:all).delete_if {|lg|
+ lg.enable? == false
+ }
end
def self.list_opt
{:include => {:licenses => {}}}
end
- def self.show rid, opt = {}
- r = LicenseGroup.find(rid, :include => self.show_include_opt(opt))
-# raise ActiveRecord::Forbidden unless c.visible?(au)
- r
+ def self.show_opt
+ {:include => {:licenses => {}}}
end
- def self.show_include_opt opt = {}
- res = {:licenses => {}}
- res.push(opt[:include]) if opt[:include]
- res
+ def self.show_json_opt
+ {:include => {:licenses => {}}}
end
- def self.show_json_include_opt
- {:include => {:licenses => {}}}
+ def my_engine_resource
+ Manifest.manifest.system_resources.engine_resources['system_resources']
+ end
+
+ def engine_name
+ self.my_engine_resource.resource_items[self.classname]
end
+ def enable?
+ self.my_engine_resource.resource_items.include? self.classname
+ end
+
+ def engine_module_name
+ self.engine_name.camelize
+ end
+
+ def engine
+ Object.const_get self.engine_module_name
+ end
+ def self.store name, attr
+ #ライセンスデータがあるとライセンスグループのデータ生成で邪魔するので移しておく
+ lattr = attr["licenses_attributes"]
+ attr.delete "licenses_attributes"
+ #ライセンスグループを先に保存してidを決める
+ r = LicenseGroup.modify_object name, attr
+ r.save
+ #取っておいたライセンスデータとidでライセンス作成
+ if (c = License.stores(lattr, r.id)) > 0
+ r.errors.add :base, License.model_name.human + I18n.t('errors.not_create')
+ end
+ r
+ end
+
+ def self.import filename
+ LicenseGroup.import_file(filename) {|name, attr| LicenseGroup.store(name, attr)}
+ end
+
+ def self.disp_import_error r
+ if r == false
+ puts "json file error. file does not exist or broken"
+ else
+ unless r.empty?
+ r.each do |lg|
+ put lg.errors.full_messages
+ end
+ end
+ end
+ end
end