2 class LicenseGroup < Pettanr::Item
5 validates :name, :presence => true, :length => {:maximum => 50}, :uniqueness => true
6 validates :classname, :presence => true, :length => {:maximum => 50}
7 validates :caption, :presence => true, :length => {:maximum => 30}
8 validates :url, :presence => true, :length => {:maximum => 200}, :url => {:message => I18n.t('errors.messages.url')}
10 def self.valid_encode_columns
11 super + ['name', 'classname', 'caption', 'url']
25 'license_groups.name asc'
29 {:include => {:licenses => {}}}
32 def self.list_json_opt
33 {:include => {:licenses => {}}}
37 {:include => {:licenses => {}}}
40 def self.show_json_opt
41 {:include => {:licenses => {}}}
44 def self.store name, attr
45 #ライセンスデータがあるとライセンスグループのデータ生成で邪魔するので移しておく
46 lattr = attr["licenses_attributes"]
47 attr.delete "licenses_attributes"
48 #ライセンスグループを先に保存してidを決める
49 r = LicenseGroup.modify_object name, attr
51 #取っておいたライセンスデータとidでライセンス作成
52 if (c = License.stores(lattr, r.id)) > 0
53 r.errors.add :base, License.model_name.human + I18n.t('errors.not_create')
58 def self.import filename
59 LicenseGroup.import_file(filename) {|name, attr| LicenseGroup.store(name, attr)}
62 def self.disp_import_error r
64 puts "json file error. file does not exist or broken"
68 put lg.errors.full_messages