1 class PanelPicture < Peta::Content
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}
21 def self.valid_encode_columns
22 super + ['link', 'caption']
25 def self.colum_structures
26 @@colum_structures ||= {
28 :helper => 'panels/size_helper'
31 :helper => 'panels/size_helper'
36 def self.list_opt_for_panel
39 :picture => {:artist => {}, :license => {}}
44 def self.show_opt_for_panel
47 :picture => {:artist => {}, :license => {}}
52 def self.json_opt_for_panel
54 :picture => {:artist => {}, :license => {}}
62 def visible? operators
63 return false unless super
64 self.owner_model.visible? operators
71 self.width = self.picture.width
72 self.height = self.picture.height
75 self.t = self.panel.new_t
76 self.z = self.panel.new_z
85 res = (self.height > 0 ? '' : 'v') + (self.width > 0 ? '' : 'h')
86 res += '/' unless res.empty?
91 self.flip + self.picture.filename
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 {:id => self.tag_id(:img), :panel_id => self.tag_panel_id, :element_id => self.tag_element_id, :element_type => self.tag_element_type,
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,
111 tw, th = PettanImager.thumbnail_size(self.width.abs, self.height.abs)
112 {:src => self.url, :width => tw, :height => th, :alt => self.caption}
116 self.picture.symbol_option
131 'panel_pictures.updated_at desc'
135 {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}} }
138 def self.list_json_opt
139 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
143 {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
146 def self.show_json_opt
147 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
152 self.panel.panel_pictures.build(self.attributes)
154 self.panel.panel_pictures.each do |panel_picture|
155 next unless panel_picture == self
156 attr = self.attributes
158 panel_picture.attributes = attr
162 self.panel.store({}, operators)
166 self.panel.remove_element(self, operators)
173 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'