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.list_opt_for_panel
19 :picture => {:artist => {}, :license => {}}
24 def self.show_opt_for_panel
27 :picture => {:artist => {}, :license => {}}
32 def self.json_opt_for_panel
34 :picture => {:artist => {}, :license => {}}
47 self.t = self.panel.new_t
48 self.z = self.panel.new_z
56 def visible? operators
57 return false unless super
58 self.owner_model.visible? operators
61 def style spot = nil, opacity = 20
63 'position' => 'absolute', 'top' => '0px', 'left' => '0px', 'z-index' => self.z,
64 'background-image' => "url(#{self.picture.url})",
65 'background-repeat' => self.repeat_text,
66 'background-position' => "#{self.x}px #{self.y}px"
68 self.merge_opacity(r, opacity) if spot and spot != self
73 tw, th = PettanImager.thumbnail_size(self.picture.width, self.picture.height)
74 {:src => self.picture.url, :width => tw, :height => th, :alt => self.caption}
82 @@repeat_texts[self.repeat]
90 'ground_pictures.updated_at desc'
94 {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}} }
97 def self.list_json_opt
98 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
102 {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
105 def self.show_json_opt
106 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
111 self.panel.ground_pictures.build(self.attributes)
113 self.panel.ground_pictures.each do |ground_picture|
114 next unless ground_picture == self
115 attr = self.attributes
117 ground_picture.attributes = attr
121 self.panel.store({}, operators)
125 self.panel.remove_element(self, operators)
132 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'