1 class PanelPicture < Peta::Element
7 validates :panel_id, :numericality => {:allow_blank => true}
8 validates :picture_id, :numericality => true, :existence => {:both => false}
9 validates :link, :length => {:maximum => 200}, :url => {:allow_blank => true, :message => I18n.t('errors.messages.url')}
10 validates :x, :presence => true, :numericality => true
11 validates :y, :presence => true, :numericality => true
12 validates :width, :presence => true, :numericality => true, :not_zero => true, :reverse => true, :resize => true, :sync_vh => true
13 validates :height, :presence => true, :numericality => true, :not_zero => true, :reverse => true, :resize => true, :sync_vh => true
14 validates :z, :presence => true, :numericality => {:greater_than => 0}
15 validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
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 => {}}
43 def visible? operators
44 return false unless super
45 self.owner_model.visible? operators
52 self.width = self.picture.width
53 self.height = self.picture.height
56 self.t = self.panel.new_t
57 self.z = self.panel.new_z
66 res = (self.height > 0 ? '' : 'v') + (self.width > 0 ? '' : 'h')
67 res += '/' unless res.empty?
72 self.flip + self.picture.filename
76 '/pictures/' + self.filename
80 "top:#{self.y}px; left:#{self.x}px; z-index:#{self.z}; position: absolute;"
83 def opt_img_tag spot = nil, opacity = 20
84 o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
85 self.tag_attributes(:img, {
86 :class => "panel-picture", :vPicture => self.id,
87 :src => self.url, :width => self.width.abs, :height => self.height.abs, :picture_id => self.picture_id, :ext => self.picture.ext, :alt => self.caption,
93 tw, th = PettanImager.thumbnail_size(self.width.abs, self.height.abs)
94 {:src => self.url, :width => tw, :height => th, :alt => self.caption}
98 self.picture.symbol_option
106 'panel_pictures.updated_at desc'
110 {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}} }
113 def self.list_json_opt
114 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
118 {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
121 def self.show_json_opt
122 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
127 self.panel.panel_pictures.build(self.attributes)
129 self.panel.panel_pictures.each do |panel_picture|
130 next unless panel_picture == self
131 attr = self.attributes
133 panel_picture.attributes = attr
137 self.panel.store({}, operators)
141 self.panel.remove_element(self, operators)
148 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'