diff --git a/src/mibew/js/source/bans.js b/src/mibew/js/source/bans.js index 4bc3e869..bbce8b3c 100644 --- a/src/mibew/js/source/bans.js +++ b/src/mibew/js/source/bans.js @@ -19,10 +19,19 @@ (function(Mibew, $) { $(document).ready(function() { $('a.remove-link').click(function() { - return confirm(Mibew.Localization.trans( - 'Are you sure that you want to delete address {0} from the blocked list?', - $(this).data('ban-address') - )); + var url = $(this).attr('href'), + message = Mibew.Localization.trans( + 'Are you sure that you want to delete address {0} from the blocked list?', + $(this).data('ban-address') + ); + + Mibew.Utils.confirm(message, function(value) { + if (value) { + window.location.href = url; + } + }); + + return false; }); }); })(Mibew, jQuery); diff --git a/src/mibew/js/source/chat/model_views/controls/close.js b/src/mibew/js/source/chat/model_views/controls/close.js index 988d0db7..abd419dc 100644 --- a/src/mibew/js/source/chat/model_views/controls/close.js +++ b/src/mibew/js/source/chat/model_views/controls/close.js @@ -49,13 +49,15 @@ */ closeThread: function() { // Show confirmation message if can - var confirmMessage = Mibew.Localization.trans('Are you sure want to leave chat?'); + var confirmMessage = Mibew.Localization.trans('Are you sure want to leave chat?'), + context = this; if (confirmMessage !== false) { - if (! confirm(confirmMessage)) { - return; - } + Mibew.Utils.confirm(confirmMessage, function(value) { + if (value) { + context.model.closeThread(); + } + }); } - this.model.closeThread(); } } ); diff --git a/src/mibew/js/source/default/utils.js b/src/mibew/js/source/default/utils.js index c9705692..2a0932e4 100644 --- a/src/mibew/js/source/default/utils.js +++ b/src/mibew/js/source/default/utils.js @@ -123,4 +123,36 @@ ].join(','); } + /** + * Alerts a message. + * @param {String} message A message that should be displayed. + */ + Mibew.Utils.alert = function(message) { + alert(message); + } + + /** + * Requires user confirmation. + * @param {String} message An assertion that should be confirmed. + * @param {Function} callback A function that will be called when the + * dialog is closed. This function accepts only one argument which is + * boolean that represents confirmation result. + */ + Mibew.Utils.confirm = function(message, callback) { + var result = confirm(message); + callback(result); + } + + /** + * Requests some info from the user. + * @param {String} message A message that will be displayed to user. + * @param {Function} callback A function that will be called when the + * dialog is closed. This function accepts only one argument which is + * the entered result. + */ + Mibew.Utils.prompt = function(message, callback) { + var result = prompt(message); + callback(result); + } + })(Mibew, jQuery, _); \ No newline at end of file diff --git a/src/mibew/js/source/groups.js b/src/mibew/js/source/groups.js index e4a6a0ea..7ea7e33d 100644 --- a/src/mibew/js/source/groups.js +++ b/src/mibew/js/source/groups.js @@ -18,11 +18,20 @@ (function(Mibew, $) { $(document).ready(function(){ - $('a.remove-link').click(function(){ - return confirm(Mibew.Localization.trans( - 'Are you sure that you want to delete the group "{0}"?', - $(this).data('group-name') - )); + $('a.remove-link').click(function() { + var url = $(this).attr('href'), + message = Mibew.Localization.trans( + 'Are you sure that you want to delete the group "{0}"?', + $(this).data('group-name') + ); + + Mibew.Utils.confirm(message, function(value) { + if (value) { + window.location.href = url; + } + }); + + return false; }); }); })(Mibew, jQuery); diff --git a/src/mibew/js/source/operators.js b/src/mibew/js/source/operators.js index b25c4e6f..06889653 100644 --- a/src/mibew/js/source/operators.js +++ b/src/mibew/js/source/operators.js @@ -19,10 +19,19 @@ (function(Mibew, $) { $(document).ready(function(){ $('a.remove-link').click(function(){ - return confirm(Mibew.Localization.trans( - 'Are you sure that you want to delete operator "{0}"?', - $(this).data('operator-login') - )); + var url = $(this).attr('href'), + message = Mibew.Localization.trans( + 'Are you sure that you want to delete operator "{0}"?', + $(this).data('operator-login') + ); + + Mibew.Utils.confirm(message, function(value) { + if (value) { + window.location.href = url; + } + }); + + return false; }); }); })(Mibew, jQuery); diff --git a/src/mibew/js/source/plugins.js b/src/mibew/js/source/plugins.js index f38bb542..6bc0b7d5 100644 --- a/src/mibew/js/source/plugins.js +++ b/src/mibew/js/source/plugins.js @@ -19,10 +19,19 @@ (function(Mibew, $) { $(document).ready(function(){ $('a.uninstall-link').click(function(){ - return confirm(Mibew.Localization.trans( - 'Are you sure that you want to uninstall plugin "{0}"?', - $(this).data('plugin-name') - )); + var url = $(this).attr('href'), + message = Mibew.Localization.trans( + 'Are you sure that you want to uninstall plugin "{0}"?', + $(this).data('plugin-name') + ); + + Mibew.Utils.confirm(message, function(value) { + if (value) { + window.location.href = url; + } + }); + + return false; }); }); })(Mibew, jQuery); diff --git a/src/mibew/js/source/users/app.js b/src/mibew/js/source/users/app.js index ed64ae19..36b49045 100644 --- a/src/mibew/js/source/users/app.js +++ b/src/mibew/js/source/users/app.js @@ -33,7 +33,7 @@ badRequestsCount++; // Check if there is if (badRequestsCount == 10) { - alert(Mibew.Localization.trans('Network problems detected. Please refresh the page.')); + Mibew.Utils.alert(Mibew.Localization.trans('Network problems detected. Please refresh the page.')); badRequestsCount = 0; } } diff --git a/src/mibew/js/source/users/collection_views/threads_collection.js b/src/mibew/js/source/users/collection_views/threads_collection.js index dd406c7c..279ac268 100644 --- a/src/mibew/js/source/users/collection_views/threads_collection.js +++ b/src/mibew/js/source/users/collection_views/threads_collection.js @@ -190,7 +190,7 @@ // Show popup notification if need if (Mibew.Objects.Models.page.get('showPopup')) { this.once('render', function() { - alert( + Mibew.Utils.alert( Mibew.Localization.trans('A new visitor is waiting for an answer.') ); }) diff --git a/src/mibew/js/source/users/model_views/queued_thread.js b/src/mibew/js/source/users/model_views/queued_thread.js index 6f0bfd1a..0d8a78b1 100644 --- a/src/mibew/js/source/users/model_views/queued_thread.js +++ b/src/mibew/js/source/users/model_views/queued_thread.js @@ -242,7 +242,7 @@ showFirstMessage: function() { var message = this.model.get('firstMessage'); if (message) { - alert(message); + Mibew.Utils.alert(message); } }