OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / models / ground_picture.rb
index 225db2d..086e5dd 100644 (file)
@@ -9,6 +9,8 @@ class GroundPicture < ActiveRecord::Base
   validates :picture_id, :numericality => true, :existence => {:both => false}
   validates :z, :presence => true, :numericality => {:greater_than => 0}
   
+  @@repeat_texts = ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']
+  
   def supply_default
     self.repeat = 0
     self.x = 0
@@ -28,6 +30,20 @@ class GroundPicture < ActiveRecord::Base
     self.panel.visible? roles
   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});" : ''
+    "width:#{self.panel.width}px; height:#{self.panel.height}px; z-index:#{self.z}; background-image: url(#{full_url}); background-repeat: #{self.repeat_text}; background-position: #{self.x}px, #{self.y}px; #{o}"
+  end
+  
+  def tmb_opt_img_tag
+    tw, th = PettanImager.thumbnail_size(self.picture.width, self.picture.height)
+    {:src => self.picture.url, :width => tw, :height => th, :alt => self.caption}
+  end
+  
+  def repeat_text
+    @@repeat_texts[self.repeat]
+  end
+  
   def self.default_page_size
     25
   end
@@ -109,6 +125,40 @@ class GroundPicture < ActiveRecord::Base
     {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
   end
   
+  def store au
+    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({}, au)
+  end
+  
+  def remove au
+    d = false
+    ground_pictures_attributes = {}
+    self.panel.ground_pictures.each do |ground_picture|
+      attr = ground_picture.attributes
+      if ground_picture == self
+        attr['_destroy'] = true
+        d = true
+      else
+        if d
+ #         attr['t']  -= 1 
+        end
+      end
+      ground_pictures_attributes[ground_picture.id] = attr
+    end
+    self.panel.attributes = {:ground_pictures_attributes => ground_pictures_attributes}
+    self.panel.store({}, au)
+  end
+  
   def scenario
     ''
   end