1 class GroundPicture < Peta::Element
7 validates :panel_id, :numericality => {:allow_blank => true}
8 validates :repeat, :numericality => true, :inclusion => { :in => 0..3 }
9 validates :x, :numericality => true
10 validates :y, :numericality => true
11 validates :picture_id, :numericality => true, :existence => {:both => false}
12 validates :z, :presence => true, :numericality => {:greater_than => 0}
13 validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
15 @@repeat_texts = ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']
17 def self.list_opt_for_panel
20 :picture => {:artist => {}, :license => {}}
25 def self.show_opt_for_panel
28 :picture => {:artist => {}, :license => {}}
33 def self.json_opt_for_panel
35 :picture => {:artist => {}, :license => {}}
48 self.t = self.panel.new_t
49 self.z = self.panel.new_z
57 def visible? operators
58 return false unless super
59 self.owner_model.visible? operators
62 def style spot = nil, opacity = 20
64 'position' => 'absolute', 'top' => '0px', 'left' => '0px', 'z-index' => self.z,
65 'background-image' => "url(#{self.picture.url})",
66 'background-repeat' => self.repeat_text,
67 'background-position' => "#{self.x}px #{self.y}px"
69 self.merge_opacity(r, opacity) if spot and spot != self
74 tw, th = PettanImager.thumbnail_size(self.picture.width, self.picture.height)
75 {:src => self.picture.url, :width => tw, :height => th, :alt => self.caption}
83 @@repeat_texts[self.repeat]
91 'ground_pictures.updated_at desc'
95 {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}} }
98 def self.list_json_opt
99 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
103 {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
106 def self.show_json_opt
107 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
112 self.panel.ground_pictures.build(self.attributes)
114 self.panel.ground_pictures.each do |ground_picture|
115 next unless ground_picture == self
116 attr = self.attributes
118 ground_picture.attributes = attr
122 self.panel.store({}, operators)
126 self.panel.remove_element(self, operators)
133 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'