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}, :allow_blank => true
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, :sync_vh => true
13 validates :height, :presence => true, :numericality => true, :not_zero => true, :reverse => 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 scope :with_panel, -> do
21 scope :find_index, -> do
22 with_panel.where(Panel.arel_table[:publish].gt 0).references(:panel)
25 scope :find_private, -> (operators) do
26 with_panel.where(Panel.arel_table[:author_id].eq operators.author.id).references(:panel)
29 scope :find_by_panel, -> (panel_id) do
30 find_index.where(panel_id: panel_id).references(:panel)
33 scope :find_by_author, -> (author_id) do
34 find_index.where(Panel.arel_table[:author_id].eq author_id).references(:panel)
37 def self.pickup_item_name
41 def self.pickup_column_name
42 self.pickup_item_name + '_id'
46 # get :picture_id if head revision
47 self.attributes[self.pickup_column_name]
54 def self.by_author_list_includes
70 self.width = self.picture.width
71 self.height = self.picture.height
74 self.t = self.panel.new_t
75 self.z = self.panel.new_z
84 res = (self.height > 0 ? '' : 'v') + (self.width > 0 ? '' : 'h')
85 res = res # format of /1.png?subdir=v
86 # res += '/' unless res.empty? # format of /v/1.png
91 q = self.flip.empty? ? '' : '?subdir=' + self.flip
92 self.picture.filename + q
96 '/pictures/' + self.filename
100 "top:#{self.y}px; left:#{self.x}px; z-index:#{self.z}; position: absolute;"
103 def opt_img_tag spot = nil, opacity = 20
104 o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
105 self.tag_attributes(:img, {
106 :class => "panel-picture", :vPicture => self.id,
107 :src => self.url, :width => self.width.abs, :height => self.height.abs, :picture_id => self.picture_id, :ext => self.picture.ext, :alt => self.caption,
113 tw, th = PettanImager.thumbnail_size(self.width.abs, self.height.abs)
114 {:src => self.url, :width => tw, :height => th, :alt => self.caption}
118 self.picture.symbol_option
121 def self.public_list_where list
126 {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
130 if self.link =~ /\:\/\//
141 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'