OSDN Git Service

t#31779:element lib
[pettanr/pettanr.git] / app / models / panel_picture.rb
index 5394038..64f990c 100644 (file)
@@ -1,4 +1,6 @@
 class PanelPicture < ActiveRecord::Base
+  include Element
+  include ElementInspire
   belongs_to :panel
   belongs_to :picture
   
@@ -21,6 +23,32 @@ class PanelPicture < ActiveRecord::Base
     end
   end
   
+  def self.list_opt_for_panel
+    {
+      :panel_pictures => {
+        :picture => {:artist => {}, :license => {}}
+      }
+    }
+  end
+  
+  def self.show_opt_for_panel
+    {
+      :panel_pictures => {
+        :picture => {:artist => {}, :license => {}}
+      }
+    }
+  end
+  
+  def self.json_opt_for_panel
+    {
+      :picture => {:artist => {}, :license => {}}
+    }
+  end
+  
+  def self.has_picture?
+    true
+  end
+  
   def visible? roles
     if MagicNumber['run_mode'] == 0
       return false unless guest_role_check(roles)
@@ -44,7 +72,8 @@ class PanelPicture < ActiveRecord::Base
     end
   end
   
-  def overwrite 
+  def overwrite  pid
+    self.panel_id = pid
   end
   
   def flip
@@ -62,7 +91,7 @@ class PanelPicture < ActiveRecord::Base
   end
   
   def opt_div_style
-    "z-index:#{self.z}; "
+    "top:#{self.y}px; left:#{self.x}px; z-index:#{self.z}; position: absolute;"
   end
   
   def opt_img_tag spot = nil, opacity = 20
@@ -70,7 +99,7 @@ class PanelPicture < ActiveRecord::Base
     {: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}"}
+    :style => "#{o}"}
   end
   
   def tmb_opt_img_tag
@@ -199,22 +228,7 @@ class PanelPicture < ActiveRecord::Base
   end
   
   def remove au
-    d = false
-    panel_pictures_attributes = {}
-    self.panel.panel_pictures.each do |panel_picture|
-      attr = panel_picture.attributes
-      if panel_picture == self
-        attr['_destroy'] = true
-        d = true
-      else
-        if d
-          attr['t']  -= 1 
-        end
-      end
-      panel_pictures_attributes[panel_picture.id] = attr
-    end
-    self.panel.attributes = {:panel_pictures_attributes => panel_pictures_attributes}
-    self.panel.store({}, au)
+    self.panel.remove_element(self, au)
   end
   
   def scenario