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 opt_div_style full_url, spot = nil, opacity = 20
63 o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
64 "position: absolute; width:#{self.get_panel.width}px; height:#{self.get_panel.height}px; top: 0px; left: 0px; z-index:#{self.z}; background-image: url(#{full_url}); background-repeat: #{self.repeat_text}; background-position: #{self.x}px #{self.y}px; #{o}"
68 tw, th = PettanImager.thumbnail_size(self.picture.width, self.picture.height)
69 {:src => self.picture.url, :width => tw, :height => th, :alt => self.caption}
84 @@repeat_texts[self.repeat]
92 'ground_pictures.updated_at desc'
96 {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}} }
99 def self.list_json_opt
100 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
104 {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
107 def self.show_json_opt
108 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
113 self.panel.ground_pictures.build(self.attributes)
115 self.panel.ground_pictures.each do |ground_picture|
116 next unless ground_picture == self
117 attr = self.attributes
119 ground_picture.attributes = attr
123 self.panel.store({}, operators)
127 self.panel.remove_element(self, operators)
134 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'