Merge pull request #2042 from mikl/firefox-upload-button-fix

This commit is contained in:
Hannah Wolfe 2014-01-27 21:35:42 +00:00
commit d05b7641f3

View File

@ -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 @@
}));
}
});
}());
}());