OSDN Git Service

Merge branch 'v06sheet' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06sheet
[pettanr/pettanr.git] / app / models / panel.rb
index 49e6dcf..cc1dc82 100644 (file)
@@ -15,9 +15,6 @@ class Panel < ActiveRecord::Base
   validates :width, :presence => true, :numericality => true, :natural_number => true
   validates :height, :presence => true, :numericality => true, :natural_number => true
   validates :border, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
-  validates :x, :numericality => {:allow_blank => true}
-  validates :y, :numericality => {:allow_blank => true}
-  validates :z, :numericality => {:allow_blank => true, :greater_than => 0}
   validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
   validates :publish, :presence => true, :numericality => true
   
@@ -86,8 +83,8 @@ class Panel < ActiveRecord::Base
     self.publish > 0
   end
   
-  def tag_id
-    'panel' + self.tag_panel_id
+  def tag_id c = nil
+    'panel' + self.tag_panel_id + c.to_s
   end
   
   def tag_panel_id
@@ -98,6 +95,34 @@ class Panel < ActiveRecord::Base
     self.tag_id + f.to_s
   end
   
+  def tag_attributes column = nil, opt = {}
+    {
+      :id => self.field_tag_id(column), :panel_id => self.tag_panel_id
+    }.merge(opt)
+  end
+  
+  def select_tag_attributes(selected, column, opt = {})
+    [
+      :last, :first, 
+      {:html => {:selected => selected}}, 
+      self.field_tag_attributes(column, opt)
+    ]
+  end
+  
+  def field_tag_attributes column, opt = {}
+    self.tag_attributes(column).merge(
+      {:column => column}
+    ).merge(opt)
+  end
+  
+  def tag_attr column = nil, opt = {}
+    self.tag_attributes(column, opt).to_attr
+  end
+  
+  def field_tag_attr column, no_attr, opt = {}
+    self.field_tag_attributes(column, no_attr, opt).to_attr
+  end
+  
   def self.default_page_size
     25
   end