From 148d30f74e2ab0ab0eefc3ff0adeb06dec56417f Mon Sep 17 00:00:00 2001 From: Pavel Pavlov Date: Sat, 7 Dec 2013 19:35:44 +0400 Subject: [PATCH] Don't redirect or reload a page when confirmation dialog wasn't confirmed --- PHPCI/View/Project/view.phtml | 2 +- public/assets/js/phpci.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/PHPCI/View/Project/view.phtml b/PHPCI/View/Project/view.phtml index 2fd6cf6d..036f9837 100644 --- a/PHPCI/View/Project/view.phtml +++ b/PHPCI/View/Project/view.phtml @@ -94,7 +94,7 @@ e.preventDefault(); confirmDelete( "project/delete/getId(); ?>", "Project" - ).onClose = function () {window.location = '/'}; + ).onCloseConfirmed = function () {window.location = '/'}; }); }) diff --git a/public/assets/js/phpci.js b/public/assets/js/phpci.js index 179597c3..7cf07458 100644 --- a/public/assets/js/phpci.js +++ b/public/assets/js/phpci.js @@ -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) {