OSDN Git Service

t#31558:merge v06
[pettanr/pettanr.git] / app / models / panel_picture.rb
index f56adc8..b28a0fc 100644 (file)
@@ -62,9 +62,16 @@ class PanelPicture < ActiveRecord::Base
     '/pictures/' + self.filename
   end
   
+  def opt_div_style
+    "z-index:#{self.z}; "
+  end
+  
   def opt_img_tag spot = nil, opacity = 20
     o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
-    {:src => self.url, :vPicture => self.id, :width => self.width.abs, :height => self.height.abs, :alt => self.caption, :style => "top:#{self.y}px; left:#{self.x}px; z-index:#{self.z}; #{o}"}
+    {:id => self.tag_id(:img), :panel_id => self.tag_panel_id, :element_id => self.tag_element_id, :element_type => self.tag_element_type,
+    :class => "panel-picture", :vPicture => self.id, 
+    :src => self.url, :width => self.width.abs, :height => self.height.abs, :picture_id => self.picture_id, :ext => self.picture.ext, :alt => self.caption, 
+    :style => "top:#{self.y}px; left:#{self.x}px; z-index:#{self.z}; #{o}"}
   end
   
   def tmb_opt_img_tag
@@ -72,6 +79,30 @@ class PanelPicture < ActiveRecord::Base
     {:src => self.url, :width => tw, :height => th, :alt => self.caption}
   end
   
+  def tag_id c = nil
+    'panel' + tag_panel_id + 'panel_picture' + tag_element_id + c.to_s
+  end
+  
+  def field_tag_id f
+    self.tag_id + f.to_s
+  end
+  
+  def tag_panel_id
+    self.panel.new_record? ? '0' : self.panel.id.to_s
+  end
+  
+  def tag_element_id
+    self.new_record? ? '0' : self.id.to_s
+  end
+  
+  def tag_element_type
+    'panel_picture'
+  end
+  
+  def field_tree f
+    'panels-' + self.tag_panel_id + '-panel_pictures_attributes-' + self.tag_element_id + '-' + f.to_s
+  end
+  
   def self.default_page_size
     25
   end