OSDN Git Service

t#31648:fix elm position
[pettanr/pettanr.git] / app / models / panel_picture.rb
index 59f04a9..57a3a4b 100644 (file)
@@ -44,7 +44,8 @@ class PanelPicture < ActiveRecord::Base
     end
   end
   
-  def overwrite 
+  def overwrite  pid
+    self.panel_id = pid
   end
   
   def flip
@@ -61,9 +62,16 @@ class PanelPicture < ActiveRecord::Base
     '/pictures/' + self.filename
   end
   
+  def opt_div_style
+    "top:#{self.y}px; left:#{self.x}px; z-index:#{self.z}; position: absolute;"
+  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, :id => "panel-picture#{self.id}", :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 => "#{o}"}
   end
   
   def tmb_opt_img_tag
@@ -71,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