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}
16 def self.pickup_item_name
20 def self.pickup_column_name
21 self.pickup_item_name + '_id'
25 # get :picture_id if head revision
26 self.attributes[self.pickup_column_name]
33 def self.by_author_list_includes
49 self.width = self.picture.width
50 self.height = self.picture.height
53 self.t = self.panel.new_t
54 self.z = self.panel.new_z
63 res = (self.height > 0 ? '' : 'v') + (self.width > 0 ? '' : 'h')
64 res = res # format of /1.png?subdir=v
65 # res += '/' unless res.empty? # format of /v/1.png
70 self.picture.filename + '?subdir=' + self.flip
74 '/pictures/' + self.filename
78 "top:#{self.y}px; left:#{self.x}px; z-index:#{self.z}; position: absolute;"
81 def opt_img_tag spot = nil, opacity = 20
82 o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
83 self.tag_attributes(:img, {
84 :class => "panel-picture", :vPicture => self.id,
85 :src => self.url, :width => self.width.abs, :height => self.height.abs, :picture_id => self.picture_id, :ext => self.picture.ext, :alt => self.caption,
91 tw, th = PettanImager.thumbnail_size(self.width.abs, self.height.abs)
92 {:src => self.url, :width => tw, :height => th, :alt => self.caption}
96 self.picture.symbol_option
99 def self.public_list_where list
104 {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
111 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'