OSDN Git Service

test speech balloon extended
[pettanr/pettanr.git] / app / models / writing_format.rb
index 4cdfd73..5e54402 100644 (file)
@@ -1,4 +1,5 @@
-class WritingFormat < ActiveRecord::Base
+class WritingFormat < Peta::SystemResource
+  load_manifest
   has_many :speeches
   belongs_to :system_picture
   
@@ -9,15 +10,6 @@ class WritingFormat < ActiveRecord::Base
   validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
   validates :settings, :presence => true
   
-  before_validation :valid_encode
-  
-  def valid_encode
-    ['name', 'classname', 'caption', 'settings'].each do |a|
-      next if attributes[a] == nil
-      raise Pettanr::BadRequest unless attributes[a].valid_encoding?
-    end
-  end
-  
   def supply_default
   end
   
@@ -25,19 +17,21 @@ class WritingFormat < ActiveRecord::Base
     self.t = WritingFormat.count.to_i if self.new_record?
   end
   
-  def visible? author
-    true
+  def self.list_where
+    nil
   end
   
-  def self.list
-    opt = {}
-    opt.merge!(self.list_opt)
-    opt.merge!({:order => 'writing_formats.t asc'})
-    WritingFormat.find(:all, opt)
+  def self.list_order
+    'writing_formats.t asc'
   end
   
+#engine vw
+def self.list
+  self.enable_list
+end
+
   def self.enable_list
-    WritingFormat.list.delete_if {|wf|
+    WritingFormat.find(:all).delete_if {|wf|
       wf.enable? == false
     }
   end
@@ -50,14 +44,6 @@ class WritingFormat < ActiveRecord::Base
     {}
   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
-  end
-  
   def self.show_opt
     {}
   end
@@ -79,12 +65,16 @@ class WritingFormat < ActiveRecord::Base
     @parsed_settings ||= JSON.parse(self.settings)
   end
   
+  def my_engine_resource
+    Manifest.manifest.system_resources.engine_resources['writing_formats']
+  end
+  
   def engine_name
-    Pettanr::Application.writing_formats[self.classname]
+    self.my_engine_resource.resource_items[self.classname]
   end
   
   def enable?
-    Pettanr::Application.writing_formats.include? self.classname
+    self.my_engine_resource.resource_items.include? self.classname
   end
   
   def engine_module_name