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=06441e30507b28baef0f8e084620e1cff5c4e951;hb=d7c8065be895b67dc453b0e11ad0f259f1ca6706;hpb=00f1b75256d14796fa5b6f75c79dabe4ecbe35ed diff --git a/app/assets/javascripts/models/original_picture.js.coffee b/app/assets/javascripts/models/original_picture.js.coffee index 06441e30..a49e44f7 100644 --- a/app/assets/javascripts/models/original_picture.js.coffee +++ b/app/assets/javascripts/models/original_picture.js.coffee @@ -30,23 +30,25 @@ class Pettanr.OriginalPicture extends Peta.Content @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) -> - history = @history() - history.fetch({cache: true}).done => - caption = if _.isEmpty(history.models) - 'unpublished' - else - head = _.first(history.models) - Pettanr.to_s(head.get('revision')) - options.success.call(context, caption) - - revision: () -> - new Pettanr.OriginalPicture.Head({original_picture: this}) - - history: () -> - new Pettanr.OriginalPicture.History({original_picture: this}) + 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 @@ -76,27 +78,3 @@ class Pettanr.OriginalPicture extends Peta.Content initialize: (attr = {}, options = {}) -> super(attr, options) -class Pettanr.OriginalPicture.History extends Backbone.Collection - - initialize: (options) -> - @original_picture = options.original_picture - @model = Pettanr.Picture - @url = @original_picture.default_url() + '/history' - -class Pettanr.OriginalPicture.Head extends Pettanr.View - tagName: 'span' - - initialize: (options) -> - @original_picture = options.original_picture - @pictures = new Pettanr.OriginalPicture.History({id: @original_picture.get('id')}) - - render: () -> - @pictures.fetch({cache: true}).done => - head = @pictures.models[0] - value = if head - head.get('revision') - else - 'unpublished' - this.$el.html(value) - this -