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 => {}}
50 def visible? operators
51 return false unless super
52 self.owner_model.visible? operators
59 self.width = self.picture.width
60 self.height = self.picture.height
63 self.t = self.panel.new_t
64 self.z = self.panel.new_z
73 res = (self.height > 0 ? '' : 'v') + (self.width > 0 ? '' : 'h')
74 res += '/' unless res.empty?
79 self.flip + self.picture.filename
83 '/pictures/' + self.filename
87 "top:#{self.y}px; left:#{self.x}px; z-index:#{self.z}; position: absolute;"
90 def opt_img_tag spot = nil, opacity = 20
91 o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
92 self.tag_attributes(:img, {
93 :class => "panel-picture", :vPicture => self.id,
94 :src => self.url, :width => self.width.abs, :height => self.height.abs, :picture_id => self.picture_id, :ext => self.picture.ext, :alt => self.caption,
100 tw, th = PettanImager.thumbnail_size(self.width.abs, self.height.abs)
101 {:src => self.url, :width => tw, :height => th, :alt => self.caption}
105 self.picture.symbol_option
113 'panel_pictures.updated_at desc'
117 {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}} }
120 def self.list_json_opt
121 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
125 {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
128 def self.show_json_opt
129 {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
134 self.panel.panel_pictures.build(self.attributes)
136 self.panel.panel_pictures.each do |panel_picture|
137 next unless panel_picture == self
138 attr = self.attributes
140 panel_picture.attributes = attr
144 self.panel.store({}, operators)
148 self.panel.remove_element(self, operators)
155 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'