From 30cbfa63825f5def3ce22c2059cbc9150359a85d Mon Sep 17 00:00:00 2001 From: Zach Geis Date: Sat, 1 Feb 2014 16:32:13 -0600 Subject: [PATCH] Disable publish button until deffered is resolved closes #2040 - save post disables the publish button - publish button remains disabled until deffered object is resolved --- ghost/admin/views/editor.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ghost/admin/views/editor.js b/ghost/admin/views/editor.js index ecc802ff11..4ebd2dbda1 100644 --- a/ghost/admin/views/editor.js +++ b/ghost/admin/views/editor.js @@ -220,11 +220,22 @@ }, savePost: function (data) { + var publishButton = $('.js-publish-button'), + saved, + enablePublish = function (deferred) { + deferred.always(function () { + publishButton.prop('disabled', false); + }); + return deferred; + }; + + publishButton.prop('disabled', true); + _.each(this.model.blacklist, function (item) { this.model.unset(item); }, this); - var saved = this.model.save(_.extend({ + saved = this.model.save(_.extend({ title: $('#entry-title').val(), markdown: Ghost.currentView.getEditorValue() }, data)); @@ -232,9 +243,10 @@ // TODO: Take this out if #2489 gets merged in Backbone. Or patch Backbone // ourselves for more consistent promises. if (saved) { - return saved; + return enablePublish(saved); } - return $.Deferred().reject(); + + return enablePublish($.Deferred().reject()); }, reportSaveSuccess: function (status, prevStatus) {