1 class PanelPicture < Peta::Element
6 validates :panel_id, :numericality => {:allow_blank => true}
7 validates :picture_id, :numericality => true, :existence => {:both => false}
8 validates :link, :length => {:maximum => 200}, :url => {:allow_blank => true, :message => I18n.t('errors.messages.url')}
9 validates :x, :presence => true, :numericality => true
10 validates :y, :presence => true, :numericality => true
11 validates :width, :presence => true, :numericality => true, :not_zero => true, :reverse => true, :sync_vh => true
12 validates :height, :presence => true, :numericality => true, :not_zero => true, :reverse => true, :sync_vh => true
13 validates :z, :presence => true, :numericality => {:greater_than => 0}
14 validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
20 def self.by_author_list_includes
36 self.width = self.picture.width
37 self.height = self.picture.height
40 self.t = self.panel.new_t
41 self.z = self.panel.new_z
50 res = (self.height > 0 ? '' : 'v') + (self.width > 0 ? '' : 'h')
51 res = res # format of /1.png?subdir=v
52 # res += '/' unless res.empty? # format of /v/1.png
57 self.picture.filename + '?subdir=' + self.flip
61 '/pictures/' + self.filename
65 "top:#{self._y}px; left:#{self.x}px; z-index:#{self.z}; position: absolute;"
68 def opt_img_tag spot = nil, opacity = 20
69 o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
70 self.tag_attributes(:img, {
71 :class => "panel-picture", :vPicture => self.id,
72 :src => self.url, :width => self.width.abs, :height => self.height.abs, :picture_id => self.picture_id, :ext => self.picture.ext, :alt => self.caption,
78 tw, th = PettanImager.thumbnail_size(self.width.abs, self.height.abs)
79 {:src => self.url, :width => tw, :height => th, :alt => self.caption}
83 self.picture.symbol_option
86 def self.public_list_where
91 {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
98 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'