diff --git a/core/client/views/debug.js b/core/client/views/debug.js index 1b14616bc7..81fc29eba1 100644 --- a/core/client/views/debug.js +++ b/core/client/views/debug.js @@ -5,12 +5,17 @@ Ghost.Views.Debug = Ghost.View.extend({ events: { "click .settings-menu a": "handleMenuClick", + "click #startupload": "handleUploadClick", "click .js-delete": "handleDeleteClick" }, initialize: function () { + var view = this; + + this.uploadButton = this.$el.find('#startupload'); + // Disable import button and initizalize BlueImp file upload - $('#startupload').prop('disabled', true); + this.uploadButton.prop('disabled', 'disabled'); $('#importfile').fileupload({ url: Ghost.paths.apiRoot + '/db/', limitMultiFileUploads: 1, @@ -21,16 +26,12 @@ dataType: 'json', add: function (e, data) { /*jslint unparam:true*/ - // unregister click event to preveng duplicate binding - $('#startupload').off("click"); - data.context = $('#startupload').prop('disabled', false) - .click(function () { - $('#startupload').prop('disabled', true); - data.context = $('#startupload').text('Importing'); - data.submit(); - // unregister click event to allow different subsequent uploads - $('#startupload').off('click'); - }); + + // Bind the upload data to the view, so it is + // available to the click handler, and enable the + // upload button. + view.fileUploadData = data; + data.context = view.uploadButton.removeProp('disabled'); }, done: function (e, data) { /*jslint unparam:true*/ @@ -77,6 +78,18 @@ return false; }, + handleUploadClick: function (ev) { + ev.preventDefault(); + + if (!this.uploadButton.prop('disabled')) { + this.fileUploadData.context = this.uploadButton.text('Importing'); + this.fileUploadData.submit(); + } + + // Prevent double post by disabling the button. + this.uploadButton.prop('disabled', 'disabled'); + }, + handleDeleteClick: function (ev) { ev.preventDefault(); this.addSubview(new Ghost.Views.Modal({ @@ -141,4 +154,4 @@ })); } }); -}()); \ No newline at end of file +}());