Don't redirect or reload a page when confirmation dialog wasn't confirmed

This commit is contained in:
Pavel Pavlov 2013-12-07 19:35:44 +04:00
parent 6c0aed7f28
commit 148d30f74e
2 changed files with 33 additions and 1 deletions

View file

@ -94,7 +94,7 @@
e.preventDefault();
confirmDelete(
"<?= PHPCI_URL ?>project/delete/<?php print $project->getId(); ?>", "Project"
).onClose = function () {window.location = '/'};
).onCloseConfirmed = function () {window.location = '/'};
});
})
</script>

View file

@ -82,6 +82,12 @@ var PHPCIConfirmDialogOptions = {
};
var PHPCIConfirmDialog = Class.extend({
/**
* @private
* @var {bool} Determines whether the dialog has been confirmed
*/
confirmed: false,
/**
* @param {PHPCIConfirmDialogOptions} options
*/
@ -148,13 +154,25 @@ var PHPCIConfirmDialog = Class.extend({
this.$confirmBtn.click(this.onConfirm.bind(this));
this.$confirmBtn.unbind('hidden.bs.modal');
/*
Bind the close event of the dialog to the set of onClose* methods
*/
this.$dialog.on('hidden.bs.modal', function () {this.onClose()}.bind(this));
this.$dialog.on('hidden.bs.modal', function () {
if (this.confirmed) {
this.onCloseConfirmed();
} else {
this.onCloseCanceled();
}
}.bind(this));
/*
Restore state if was changed previously
*/
this.$cancelBtn.show();
this.$confirmBtn.show();
this.confirmed = false;
},
/**
@ -172,10 +190,24 @@ var PHPCIConfirmDialog = Class.extend({
},
onConfirm: function (e) {
this.confirmed = true;
$(this).attr('disabled', 'disabled');
this.confirmBtnClick(e);
},
/**
* Called only when confirmed dialog was closed
*/
onCloseConfirmed: function () {},
/**
* Called only when canceled dialog was closed
*/
onCloseCanceled: function () {},
/**
* Called always when the dialog was closed
*/
onClose: function () {},
showStatusMessage: function (message, closeTimeout) {