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.list_opt_for_panel
19 :picture => {:artist => {}, :license => {}}
24 def self.show_opt_for_panel
27 :picture => {:artist => {}, :license => {}}
32 def self.json_opt_for_panel
34 :picture => {:artist => {}, :license => {}}
42 def visible? operators
43 return false unless super
44 self.owner_model.visible? operators
51 self.width = self.picture.width
52 self.height = self.picture.height
55 self.t = self.panel.new_t
56 self.z = self.panel.new_z
65 res = (self.height > 0 ? '' : 'v') + (self.width > 0 ? '' : 'h')
66 res += '/' unless res.empty?
71 self.flip + self.picture.filename
75 '/pictures/' + self.filename
79 "top:#{self.y}px; left:#{self.x}px; z-index:#{self.z}; position: absolute;"
82 def opt_img_tag spot = nil, opacity = 20
83 o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
84 self.tag_attributes(:img, {
85 :class => "panel-picture", :vPicture => self.id,
86 :src => self.url, :width => self.width.abs, :height => self.height.abs, :picture_id => self.picture_id, :ext => self.picture.ext, :alt => self.caption,
92 tw, th = PettanImager.thumbnail_size(self.width.abs, self.height.abs)
93 {:src => self.url, :width => tw, :height => th, :alt => self.caption}
97 self.picture.symbol_option
105 'panel_pictures.updated_at desc'
109 {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}} }
112 def self.list_json_opt
113 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
117 {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
120 def self.show_json_opt
121 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
126 self.panel.panel_pictures.build(self.attributes)
128 self.panel.panel_pictures.each do |panel_picture|
129 next unless panel_picture == self
130 attr = self.attributes
132 panel_picture.attributes = attr
136 self.panel.store({}, operators)
140 self.panel.remove_element(self, operators)
147 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'