X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fmodels%2Fwriting_format.rb;h=ebcde004427cf458e608fc638f9190c127b18038;hb=HEAD;hp=9ea43fc7be9fc67372546e6bc1e8cfe2482f4cff;hpb=eada248d033161ff9797c40bac0fd24ed7d1d962;p=pettanr%2Fpettanr.git diff --git a/app/models/writing_format.rb b/app/models/writing_format.rb index 9ea43fc7..ebcde004 100644 --- a/app/models/writing_format.rb +++ b/app/models/writing_format.rb @@ -1,21 +1,21 @@ -class WritingFormat < ActiveRecord::Base +class WritingFormat < Peta::Template + load_manifest has_many :speeches belongs_to :system_picture validates :name, :presence => true, :uniqueness => true, :length => {:maximum => 50} - validates :classname, :presence => true, :length => {:maximum => 50} + validates :module_name, :presence => true, :length => {:maximum => 50} validates :caption, :presence => true, :length => {:maximum => 30} validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0} validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false} validates :settings, :presence => true - before_validation :valid_encode + scope :find_index, -> do + self + end - def valid_encode - ['name', 'classname', 'caption', 'settings'].each do |a| - next if attributes[a] == nil - raise Pettanr::BadRequest unless attributes[a].valid_encoding? - end + scope :find_by_system_picture, -> (system_picture_id) do + find_index.where(system_picture_id: system_picture_id) end def supply_default @@ -25,37 +25,27 @@ class WritingFormat < ActiveRecord::Base self.t = WritingFormat.count.to_i if self.new_record? end - def visible? author - true - end - - def self.list - opt = {} - opt.merge!(self.list_opt) - opt.merge!({:order => 'writing_formats.t asc'}) - WritingFormat.find(:all, opt) + def symbol_option + self.system_picture.tmb_opt_img_tag end - def self.enable_list - WritingFormat.list.delete_if {|wf| - wf.enable? == false - } + def self.list_order + 'writing_formats.t asc' end - def self.list_opt - {} - end - - def self.list_json_opt - {} - end - - def self.show rid, au - opt = {} - opt.merge!(self.show_opt) - res = WritingFormat.find(rid, opt) - raise ActiveRecord::Forbidden unless res.visible?(au) - res +#engine vw +def self.list + self.enable_list +end + + def self.enable_list include_available = false + r = WritingFormat.all + unless include_available + r.delete_if {|wf| + wf.enable? == false + } + end + r end def self.show_opt @@ -79,25 +69,11 @@ class WritingFormat < ActiveRecord::Base @parsed_settings ||= JSON.parse(self.settings) end - def engine_name - Pettanr::Application.manifest.system_resources.writing_formats[self.classname] - end - - def enable? - Pettanr::Application.manifest.system_resources.writing_formats.include? self.classname - end - - def engine_module_name - self.engine_name.camelize - end - - def engine - Object.const_get self.engine_module_name - end - - def engine_model - engine.const_get 'Renderer' - end + # get template model ex) PettanrSimpleFormat::Renderer + # render method written in template model + #def extend_model + # self.template_module.const_get 'Renderer' + #end def self.import filename WritingFormat.import_file(filename) {|name, attr| WritingFormat.store(name, attr)}