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 scope :with_panel, -> do
18 scope :find_index, -> do
19 with_panel.where(Panel.arel_table[:publish].gt 0).references(:panel)
22 scope :find_private, -> (operators) do
23 with_panel.where(Panel.arel_table[:author_id].eq operators.author.id).references(:panel)
26 scope :find_by_panel, -> (panel_id) do
27 find_index.where(panel_id: panel_id).references(:panel)
30 scope :find_by_author, -> (author_id) do
31 find_index.where(Panel.arel_table[:author_id].eq author_id).references(:panel)
34 @@repeat_texts = ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']
36 def self.pickup_item_name
40 def self.pickup_column_name
41 self.pickup_item_name + '_id'
45 # get :picture_id if head revision
46 self.attributes[self.pickup_column_name]
53 def self.by_author_list_includes
70 self.t = self.panel.new_t
71 self.z = self.panel.new_z
79 def style spot = nil, opacity = 20
81 'position' => 'absolute', 'top' => '0px', 'left' => '0px', 'z-index' => self.z,
82 'background-image' => "url(#{self.picture.url})",
83 'background-repeat' => self.repeat_text,
84 'background-position' => "#{self.x}px #{self.y}px"
86 self.merge_opacity(r, opacity) if spot and spot != self
91 tw, th = PettanImager.thumbnail_size(self.picture.width, self.picture.height)
92 {:src => self.picture.url, :width => tw, :height => th, :alt => self.caption}
100 @@repeat_texts[self.repeat]
103 def self.public_list_where list
108 {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
115 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'