OSDN Git Service

v07
[pettanr/pettanr.git] / app / models / ground_picture.rb
index 0959c61..bd1d16d 100644 (file)
@@ -1,6 +1,5 @@
-class GroundPicture < Pettanr::Content
-  include Element
-  include ElementInspire
+class GroundPicture < Peta::Element
+  load_manifest
   belongs_to :panel
   belongs_to :picture
   
@@ -12,35 +11,50 @@ class GroundPicture < Pettanr::Content
   validates :z, :presence => true, :numericality => {:greater_than => 0}
   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
   
+  scope :with_panel, -> do
+    includes(:panel)
+  end
+  
+  scope :find_index, -> do
+    with_panel.where(Panel.arel_table[:publish].gt 0).references(:panel)
+  end
+  
+  scope :find_private, -> (operators) do 
+    with_panel.where(Panel.arel_table[:author_id].eq operators.author.id).references(:panel)
+  end
+  
+  scope :find_by_panel, -> (panel_id) do 
+    find_index.where(panel_id: panel_id).references(:panel)
+  end
+  
+  scope :find_by_author, -> (author_id) do 
+    find_index.where(Panel.arel_table[:author_id].eq author_id).references(:panel)
+  end
+  
   @@repeat_texts = ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']
   
-  def self.owner_model
-    Panel
+  def self.pickup_item_name
+    Picture.item_name
   end
   
-  def self.valid_encode_columns
-    super + ['caption']
+  def self.pickup_column_name
+    self.pickup_item_name + '_id'
   end
   
-  def self.list_opt_for_panel
-    {
-      :ground_pictures => {
-        :picture => {:artist => {}, :license => {}}
-      }
-    }
+  def pickup_id
+    # get :picture_id if head revision
+    self.attributes[self.pickup_column_name]
   end
   
-  def self.show_opt_for_panel
-    {
-      :ground_pictures => {
-        :picture => {:artist => {}, :license => {}}
-      }
-    }
+  def y
+    self.attributes['y']
   end
   
-  def self.json_opt_for_panel
+  def self.by_author_list_includes
     {
-      :picture => {:artist => {}, :license => {}}
+      :panel => {
+        :author => {}
+      }
     }
   end
   
@@ -62,14 +76,15 @@ class GroundPicture < Pettanr::Content
     self.panel_id = pid
   end
   
-  def visible? operators
-    return false unless super
-    self.owner_model.visible? operators
-  end
-  
-  def opt_div_style full_url, spot = nil, opacity = 20
-    o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
-    "position: absolute; width:#{self.get_panel.width}px; height:#{self.get_panel.height}px; top: 0px; left: 0px;  z-index:#{self.z}; background-image: url(#{full_url}); background-repeat: #{self.repeat_text}; background-position: #{self.x}px #{self.y}px; #{o}"
+  def style spot = nil, opacity = 20
+    r = {
+      'position' => 'absolute', 'top' => '0px', 'left' => '0px', 'z-index' => self.z, 
+      'background-image' => "url(#{self.picture.url})", 
+      'background-repeat' => self.repeat_text, 
+      'background-position' => "#{self.x}px #{self.y}px"
+    }
+    self.merge_opacity(r, opacity) if spot and spot != self
+    r
   end
   
   def tmb_opt_img_tag
@@ -81,60 +96,18 @@ class GroundPicture < Pettanr::Content
     self.tmb_opt_img_tag
   end
   
-  def boost
-  end
-  
-  def tag_element_type
-    'ground_picture'
-  end
-  
   def repeat_text
     @@repeat_texts[self.repeat]
   end
   
-  def self.list_where
+  def self.public_list_where list
     'panels.publish > 0'
   end
   
-  def self.list_order
-    'ground_pictures.updated_at desc'
-  end
-  
-  def self.list_opt
-    {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}} }
-  end
-  
-  def self.list_json_opt
-    {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
-  end
-  
   def self.show_opt
     {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
   end
   
-  def self.show_json_opt
-    {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
-  end
-  
-  def store operators
-    if self.new_record?
-      self.panel.ground_pictures.build(self.attributes)
-    else
-      self.panel.ground_pictures.each do |ground_picture|
-        next unless ground_picture == self
-        attr = self.attributes
-        attr.delete 'id'
-        ground_picture.attributes = attr
-        break
-      end
-    end
-    self.panel.store({}, operators)
-  end
-  
-  def remove operators
-    self.panel.remove_element(self, operators)
-  end
-  
   def scenario
     if caption.blank?
       ''