class Pettanr.PanelPicture extends Peta.Element url: '/panel_pictures/' @singular: () -> 'PanelPicture' @plural: () -> 'PanelPictures' defaults: { id: null } picture: () -> new Pettanr.Picture({id: @get('picture_id')}) @has_picture: () -> true flip: () -> v = if @get('height') > 0 '' else 'v' h = if @get('width') > 0 '' else 'h' res = v + h res = res # format of /1.png?subdir=v # res += '/' unless res.empty? # format of /v/1.png res filename: () -> @picture().filename() + '?subdir=' + @flip() r_url: () -> '/pictures/' + @filename() opt_div_style: () -> "top:#{@get('y')}px; left:#{@get('x')}px; z-index:#{@get('z')}; position: absolute;" opt_img_tag: (spot = null, opacity = 20) -> o = if spot and spot != this "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" else '' @tag_attributes('img', { class: "panel-picture", vPicture: @get('id'), src: @r_url(), width: Math.abs(@get('width')), height: Math.abs(@get('height')), picture_id: @get('picture_id'), ext: @picture.ext, alt: @get('caption'), style: "#{o}" }) tmb_opt_img_tag: (picture) -> wh = Pettanr.Imager.thumbnail_size(@get('width'), @get('height')) new Pettanr.AppHelperImg({src: picture.r_url(), size: Math.abs(wh[0]), alt: @get('caption')}) symbol_option: (cb) -> i = @picture() _this = this i.fetch().done -> cb(_this.tmb_opt_img_tag(i)) initialize: () -> if @id @url = @url + @id class Pettanr.PanelPicture.Collection extends Backbone.Collection model: Pettanr.PanelPicture url: '/panel_pictures'