OSDN Git Service

fix foreign_filter list includes
[pettanr/pettanr.git] / app / models / balloon.rb
index 611481f..ebca4ef 100644 (file)
@@ -1,5 +1,5 @@
-class Balloon < ActiveRecord::Base
-  include ElementPart
+class Balloon < Peta::Element
+  load_manifest
   belongs_to :speech_balloon
   belongs_to :system_picture
   
@@ -13,35 +13,13 @@ class Balloon < ActiveRecord::Base
 #  validates :caption, :presence => true
   validates :settings, :extend_balloon => true
 
-  before_validation :valid_encode
-  
-  def valid_encode
-    ['settings'].each do |a|
-      next if attributes[a] == nil
-      raise Pettanr::BadRequest unless attributes[a].valid_encoding?
-    end
-  end
-  
-  def self.colum_structures
-    @@colum_structures ||= {
-      :r => {
-        :helper => 'panels/tail_angle_helper'
-      }
-    }
-  end
-  
   def url
     '/system_pictures/' + self.system_picture.filename
   end
   
-  def visible? roles
-    if MagicNumber['run_mode'] == 0
-      return false unless guest_role_check(roles)
-    else
-      return false unless reader_role_check(roles)
-    end
-    return true if self.speech_balloon.panel.own?(roles)
-    self.speech_balloon.panel.visible? roles
+  def visible? operators
+    return false unless super
+    self.owner_model.visible? operators
   end
   
   def supply_default
@@ -54,56 +32,25 @@ self.system_picture_id = 1
   end
   
   def symbol_option
-    self.get_parent.speech_balloon_template.symbol_option
-  end
-  
-  def get_parent
-    self.speech_balloon || @new_parent
-  end
-  
-  def tag_element_part_type
-    'balloon'
-  end
-  
-  def self.default_page_size
-    25
-  end
-  
-  def self.max_page_size
-    100
-  end
-  
-  def self.page prm = nil
-    page = prm.to_i
-    page = 1 if page < 1
-    page
-  end
-  
-  def self.page_size prm = self.default_page_size
-    page_size = prm.to_i
-    page_size = self.max_page_size if page_size > self.max_page_size
-    page_size = self.default_page_size if page_size < 1
-    page_size
+    self.speech_balloon.speech_balloon_template.symbol_option
   end
   
   def self.list_where
     'panels.publish > 0'
   end
   
-  def self.list page = 1, page_size = self.default_page_size
-    Balloon.where(self.list_where()).includes(Balloon.list_opt).order('balloons.updated_at desc').offset((page -1) * page_size).limit(page_size)
-  end
-  
-  def self.list_paginate page = 1, page_size = self.default_page_size
-    Kaminari.paginate_array(Array.new(Balloon.where(self.list_where()).includes(Balloon.list_opt).count, nil)).page(page).per(page_size)
-  end
-  
-  def self.list_by_speech_balloon_where speech_balloon_id
-    ['balloons.speech_balloon_id = ?', speech_balloon_id]
+  def self.list_order
+    'balloons.updated_at desc'
   end
   
-  def self.list_by_speech_balloon speech_balloon_id, roles, page = 1, page_size = self.default_page_size
-    self.where(self.list_by_speech_balloon_where(speech_balloon_id)).includes(self.list_opt).order('balloons.updated_at desc').offset((page -1) * page_size).limit(page_size)
+  def self.by_author_list_includes
+    {
+      :speech_balloon => {
+        :panel => {
+          :author => {}
+        }
+      }
+    }
   end
   
   def self.list_opt
@@ -114,14 +61,6 @@ self.system_picture_id = 1
     {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}}
   end
   
-  def self.show cid, au
-    opt = {}
-    opt.merge!(Balloon.show_opt)
-    res = Balloon.find(cid, opt)
-    raise ActiveRecord::Forbidden unless res.visible?(au)
-    res
-  end
-  
   def self.show_opt
     {:include => {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}}
   end
@@ -130,6 +69,13 @@ self.system_picture_id = 1
     {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}}
   end
   
+  def style
+    {
+      'width' => self.width.to_s + 'px','height' => self.height.to_s + 'px',
+      'top' => self.y.to_s + 'px','left' => self.x.to_s + 'px'
+    }
+  end
+  
   def copy_attributes
     r = self.attributes
     r.delete 'id'