X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=blobdiff_plain;f=app%2Fassets%2Fjavascripts%2Fmodels%2Foriginal_picture.js.coffee;h=a49e44f7ce68d79e044f7ea973793570997a8500;hp=cb58ca350451febc38a4a2e2570ba7287b2ed01e;hb=d7c8065be895b67dc453b0e11ad0f259f1ca6706;hpb=10d7d403b74c06dcbf42a132b9712c3817547284 diff --git a/app/assets/javascripts/models/original_picture.js.coffee b/app/assets/javascripts/models/original_picture.js.coffee index cb58ca35..a49e44f7 100644 --- a/app/assets/javascripts/models/original_picture.js.coffee +++ b/app/assets/javascripts/models/original_picture.js.coffee @@ -1,25 +1,80 @@ -class OriginalPicture extends Item - @single: () -> +class Pettanr.OriginalPicture extends Peta.Content + + @singular: () -> 'OriginalPicture' @plural: () -> 'OriginalPictures' defaults: { - id: 11 + id: null, + artist_id: null } - initialize: () -> - confirm("Welcome to Panel") + 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' - @test: () -> - confirm( @single()) - confirm( @plural() ) - confirm( @class_name() ) - confirm( @element_name() ) - confirm( @table_name() ) - + initialize: (attr = {}, options = {}) -> + super(attr, options) - test: () -> - -@Panel = Panel