OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / models / speech_balloon_template.rb
index 3e8b44f..4660b97 100644 (file)
@@ -1,40 +1,48 @@
 #フキダシテンプレート
-class SpeechBalloonTemplate < Peta::SystemResource
+class SpeechBalloonTemplate < Peta::Template
   load_manifest
   has_many :speech_balloons
   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
   
-  def supply_default
+  scope :find_index, -> do
+    self
   end
   
-  def overwrite
-    self.t = SpeechBalloonTemplate.count.to_i if self.new_record?
+  scope :find_by_original_picture, -> (original_picture_id) do 
+    find_index.where(original_picture_id: original_picture_id)
   end
   
-  def symbol_option
-    self.system_picture.tmb_opt_img_tag
+  scope :with_panels, -> do
+    includes(speech_balloons: panel)
   end
   
-  def self.list_opt
-    {}
+  scope :find_by_panel, -> (panel_id) do 
+    with_panels.where(Panel.arel_table[:id].eq panel_id).references(:panel)
   end
   
-  def self.list_json_opt
-    {}
+  scope :find_by_system_picture, -> (system_picture_id) do 
+    find_index.where(system_picture_id: system_picture_id)
   end
   
-  def self.show_opt
-    {}
+  def supply_default
   end
   
-  def self.show_json_opt
+  def overwrite
+    self.t = SpeechBalloonTemplate.count.to_i if self.new_record?
+  end
+  
+  def symbol_option
+    self.system_picture.tmb_opt_img_tag
+  end
+  
+  def self.show_opt
     {}
   end