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.by_author_list_includes
24 def self.list_opt_for_panel
27 :picture => {:artist => {}, :license => {}}
32 def self.show_opt_for_panel
35 :picture => {:artist => {}, :license => {}}
40 def self.json_opt_for_panel
42 :picture => {:artist => {}, :license => {}}
55 self.t = self.panel.new_t
56 self.z = self.panel.new_z
64 def style spot = nil, opacity = 20
66 'position' => 'absolute', 'top' => '0px', 'left' => '0px', 'z-index' => self.z,
67 'background-image' => "url(#{self.picture.url})",
68 'background-repeat' => self.repeat_text,
69 'background-position' => "#{self.x}px #{self.y}px"
71 self.merge_opacity(r, opacity) if spot and spot != self
76 tw, th = PettanImager.thumbnail_size(self.picture.width, self.picture.height)
77 {:src => self.picture.url, :width => tw, :height => th, :alt => self.caption}
85 @@repeat_texts[self.repeat]
88 def self.public_list_where
93 'ground_pictures.updated_at desc'
97 {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}} }
100 def self.list_json_opt
101 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
105 {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
108 def self.show_json_opt
109 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
114 self.panel.ground_pictures.build(self.attributes)
116 self.panel.ground_pictures.each do |ground_picture|
117 next unless ground_picture == self
118 attr = self.attributes
120 ground_picture.attributes = attr
124 self.panel.store({}, operators)
128 self.panel.remove_element(self, operators)
135 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'