OSDN Git Service

element
[pettanr/pettanr.git] / app / models / balloon.rb
index fbfc8bf..b36a825 100644 (file)
@@ -1,5 +1,6 @@
-class Balloon < ActiveRecord::Base
-  include ElementPart
+class Balloon < Peta::Content
+  load_manifest
+  include Peta::ElementPart
   belongs_to :speech_balloon
   belongs_to :system_picture
   
@@ -13,15 +14,6 @@ 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 => {
@@ -34,14 +26,9 @@ class Balloon < ActiveRecord::Base
     '/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
@@ -53,6 +40,10 @@ class Balloon < ActiveRecord::Base
 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
@@ -61,51 +52,22 @@ self.system_picture_id = 1
     '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
+  def self.list_where
+    'panels.publish > 0'
   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
-  end
-  
-  def self.list page = 1, page_size = self.default_page_size
-    opt = {}
-    opt.merge!(Balloon.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => 'panels.publish > 0', :order => 'balloons.updated_at desc'})
-    Balloon.find(:all, opt)
+  def self.list_order
+    'balloons.updated_at desc'
   end
   
   def self.list_opt
-    {:include => {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}}
+    {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}
   end
   
   def self.list_json_opt
     {: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
@@ -114,6 +76,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'