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 scope :with_panel, -> do
20 scope :find_index, -> do
21 with_panel.where(Panel.arel_table[:publish].gt 0).references(:panel)
24 scope :find_private, -> (operators) do
25 with_panel.where(Panel.arel_table[:author_id].eq operators.author.id).references(:panel)
28 scope :find_by_panel, -> (panel_id) do
29 find_index.where(panel_id: panel_id).references(:panel)
32 scope :find_by_author, -> (author_id) do
33 find_index.where(Panel.arel_table[:author_id].eq author_id).references(:panel)
36 def self.pickup_item_name
40 def self.pickup_column_name
41 self.pickup_item_name + '_id'
45 # get :picture_id if head revision
46 self.attributes[self.pickup_column_name]
53 def self.by_author_list_includes
69 self.width = self.picture.width
70 self.height = self.picture.height
73 self.t = self.panel.new_t
74 self.z = self.panel.new_z
83 res = (self.height > 0 ? '' : 'v') + (self.width > 0 ? '' : 'h')
84 res = res # format of /1.png?subdir=v
85 # res += '/' unless res.empty? # format of /v/1.png
90 q = self.flip.empty? ? '' : '?subdir=' + self.flip
91 self.picture.filename + q
95 '/pictures/' + self.filename
99 "top:#{self.y}px; left:#{self.x}px; z-index:#{self.z}; position: absolute;"
102 def opt_img_tag spot = nil, opacity = 20
103 o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
104 self.tag_attributes(:img, {
105 :class => "panel-picture", :vPicture => self.id,
106 :src => self.url, :width => self.width.abs, :height => self.height.abs, :picture_id => self.picture_id, :ext => self.picture.ext, :alt => self.caption,
112 tw, th = PettanImager.thumbnail_size(self.width.abs, self.height.abs)
113 {:src => self.url, :width => tw, :height => th, :alt => self.caption}
117 self.picture.symbol_option
120 def self.public_list_where list
125 {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
132 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'