1 class GroundPicture < Peta::Element
6 validates :panel_id, :numericality => {:allow_blank => true}
7 validates :repeat, :numericality => true, :inclusion => { :in => 0..3 }
8 validates :x, :numericality => true
9 validates :y, :numericality => true
10 validates :picture_id, :numericality => true, :existence => {:both => false}
11 validates :z, :presence => true, :numericality => {:greater_than => 0}
12 validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
14 @@repeat_texts = ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']
16 def self.pickup_item_name
20 def self.pickup_column_name
21 self.pickup_item_name + '_id'
25 # get :picture_id if head revision
26 self.attributes[self.pickup_column_name]
33 def self.by_author_list_includes
50 self.t = self.panel.new_t
51 self.z = self.panel.new_z
59 def style spot = nil, opacity = 20
61 'position' => 'absolute', 'top' => '0px', 'left' => '0px', 'z-index' => self.z,
62 'background-image' => "url(#{self.picture.url})",
63 'background-repeat' => self.repeat_text,
64 'background-position' => "#{self.x}px #{self.y}px"
66 self.merge_opacity(r, opacity) if spot and spot != self
71 tw, th = PettanImager.thumbnail_size(self.picture.width, self.picture.height)
72 {:src => self.picture.url, :width => tw, :height => th, :alt => self.caption}
80 @@repeat_texts[self.repeat]
83 def self.public_list_where list
88 {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
95 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'