1 class PanelPicture < Peta::Element
7 validates :panel_id, :numericality => {:allow_blank => true}
8 validates :picture_id, :numericality => true, :existence => {:both => false}
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, :resize => true, :sync_vh => true
13 validates :height, :presence => true, :numericality => true, :not_zero => true, :reverse => true, :resize => 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 def self.colum_structures
18 @@colum_structures ||= {
20 :helper => 'panels/size_helper'
23 :helper => 'panels/size_helper'
28 def self.list_opt_for_panel
31 :picture => {:artist => {}, :license => {}}
36 def self.show_opt_for_panel
39 :picture => {:artist => {}, :license => {}}
44 def self.json_opt_for_panel
46 :picture => {:artist => {}, :license => {}}
54 def visible? operators
55 return false unless super
56 self.owner_model.visible? operators
63 self.width = self.picture.width
64 self.height = self.picture.height
67 self.t = self.panel.new_t
68 self.z = self.panel.new_z
77 res = (self.height > 0 ? '' : 'v') + (self.width > 0 ? '' : 'h')
78 res += '/' unless res.empty?
83 self.flip + self.picture.filename
87 '/pictures/' + self.filename
91 "top:#{self.y}px; left:#{self.x}px; z-index:#{self.z}; position: absolute;"
94 def opt_img_tag spot = nil, opacity = 20
95 o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
96 self.tag_attributes(:img, {
97 :class => "panel-picture", :vPicture => self.id,
98 :src => self.url, :width => self.width.abs, :height => self.height.abs, :picture_id => self.picture_id, :ext => self.picture.ext, :alt => self.caption,
104 tw, th = PettanImager.thumbnail_size(self.width.abs, self.height.abs)
105 {:src => self.url, :width => tw, :height => th, :alt => self.caption}
109 self.picture.symbol_option
124 'panel_pictures.updated_at desc'
128 {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}} }
131 def self.list_json_opt
132 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
136 {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
139 def self.show_json_opt
140 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
145 self.panel.panel_pictures.build(self.attributes)
147 self.panel.panel_pictures.each do |panel_picture|
148 next unless panel_picture == self
149 attr = self.attributes
151 panel_picture.attributes = attr
155 self.panel.store({}, operators)
159 self.panel.remove_element(self, operators)
166 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'