class Pettanr.OriginalPicture extends Peta.Content @singular: () -> 'OriginalPicture' @plural: () -> 'OriginalPictures' defaults: { id: null, artist_id: null } is_visible: (operators = Pettanr.cache.operators) -> @is_own(operators) filename: () -> @get('id') + '.' + @get('ext') mime_type: () -> 'image/' + @get('ext') r_url: () -> '/original_pictures/' + @filename() license_url: () -> '/original_picture_license_groups/new/' + @get('id') symbol_option: (context, options) -> @retrieve(this, { success: (symbol_item) => options.success.call(context, symbol_item.symbol_file()) fail: (response, opt) => options.fail.call(context, response, opt) }) filer_caption: (context, options) -> controller = Manifest.manifest().controllers['original_pictures'] action = controller.actions['history'] list = action.find(id: @get('id')) list.open(this, { success: (pictures) => caption = if _.isEmpty(pictures) 'unpublished' else head = _.first(pictures) Pettanr.to_s(head.get('revision')) options.success.call(context, caption) fail: (response, opt) => options.fail.call(context, response, opt) }) 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: (attr = {}, options = {}) -> super(attr, options)