class Pettanr.OriginalPicture extends Peta.Content url: '/original_pictures/' @singular: () -> 'OriginalPicture' @plural: () -> 'OriginalPictures' defaults: { id: null, artist_id: null } picture: () -> new Pettanr.Picture({id: @get('picture_id')}) is_visible: (operators) -> @is_own(operators) filename: () -> @get('id') + '.' + @get('ext') mime_type: () -> 'image/' + @get('ext') r_url: () -> '/original_pictures/' + @filename() opt_img_tag: () -> {src: @r_url(), width: @get('width'), height: @get('height')} tmb_opt_img_tag: () -> new Pettanr.Image.SymbolPicture({ attr: { src: @r_url() }, picture: this }) symbol_option: (cb) -> _this = this this.fetch({cache: true}).done -> cb(_this.tmb_opt_img_tag()) revision: () -> new Pettanr.OriginalPicture.Head({original_picture: this}) history: () -> new Pettanr.OriginalPicture.History({original_picture: this}) is_unpublished: () -> @get('published_at') == null and @get('stopped_at') == null is_stopped: () -> @get('stopped_at') != null is_unlicensed: () -> dt = @get('published_at') || @get('stopped_at') return false if not dt @get('uploaded_at') > dt is_published: () -> @get('published_at') != null state: () -> switch true when @is_unpublished() 'unpublished' when @is_unlicensed() 'unlicensed' when @is_stopped() 'stopped' when @is_published() 'published' initialize: () -> if @id @url = @url + @id class Pettanr.OriginalPicture.History extends Backbone.Collection url: '/original_pictures/' initialize: (options) -> @model = Pettanr.Picture @url = @url + options.id + '/history' class Pettanr.OriginalPicture.Head extends Backbone.View tagName: 'span' initialize: (options) -> @original_picture = options.original_picture @pictures = new Pettanr.OriginalPicture.History({id: @original_picture.get('id')}) render: () -> _this = this @pictures.fetch({cache: true}).done -> head = _this.pictures.models[0] value = if head head.get('revision') else 'unpublished' _this.$el.html(value) this