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, :resize => true, :sync_vh => true
12 validates :height, :presence => true, :numericality => true, :not_zero => true, :reverse => true, :resize => 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.by_author_list_includes
24 def self.list_opt_for_panel
27 :picture => {:artist => {}, :license => {}}
32 def self.show_opt_for_panel
35 :picture => {:artist => {}, :license => {}}
40 def self.json_opt_for_panel
42 :picture => {:artist => {}, :license => {}}
54 self.width = self.picture.width
55 self.height = self.picture.height
58 self.t = self.panel.new_t
59 self.z = self.panel.new_z
68 res = (self.height > 0 ? '' : 'v') + (self.width > 0 ? '' : 'h')
69 res += '/' unless res.empty?
74 self.flip + self.picture.filename
78 '/pictures/' + self.filename
82 "top:#{self.y}px; left:#{self.x}px; z-index:#{self.z}; position: absolute;"
85 def opt_img_tag spot = nil, opacity = 20
86 o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
87 self.tag_attributes(:img, {
88 :class => "panel-picture", :vPicture => self.id,
89 :src => self.url, :width => self.width.abs, :height => self.height.abs, :picture_id => self.picture_id, :ext => self.picture.ext, :alt => self.caption,
95 tw, th = PettanImager.thumbnail_size(self.width.abs, self.height.abs)
96 {:src => self.url, :width => tw, :height => th, :alt => self.caption}
100 self.picture.symbol_option
103 def self.public_list_where
108 'panel_pictures.updated_at desc'
112 {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}} }
115 def self.list_json_opt
116 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
120 {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
123 def self.show_json_opt
124 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
129 self.panel.panel_pictures.build(self.attributes)
131 self.panel.panel_pictures.each do |panel_picture|
132 next unless panel_picture == self
133 attr = self.attributes
135 panel_picture.attributes = attr
139 self.panel.store({}, operators)
143 self.panel.remove_element(self, operators)
150 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'