Use async notice for alert, confirm and prompt functions

This commit is contained in:
Dmitriy Simushev 2015-02-03 14:08:52 +00:00
parent ebd6684d4a
commit c1850f0bb3
9 changed files with 95 additions and 25 deletions

View File

@ -19,10 +19,19 @@
(function(Mibew, $) { (function(Mibew, $) {
$(document).ready(function() { $(document).ready(function() {
$('a.remove-link').click(function() { $('a.remove-link').click(function() {
return confirm(Mibew.Localization.trans( var url = $(this).attr('href'),
'Are you sure that you want to delete address {0} from the blocked list?', message = Mibew.Localization.trans(
$(this).data('ban-address') '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); })(Mibew, jQuery);

View File

@ -49,13 +49,15 @@
*/ */
closeThread: function() { closeThread: function() {
// Show confirmation message if can // 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 (confirmMessage !== false) {
if (! confirm(confirmMessage)) { Mibew.Utils.confirm(confirmMessage, function(value) {
return; if (value) {
} context.model.closeThread();
}
});
} }
this.model.closeThread();
} }
} }
); );

View File

@ -123,4 +123,36 @@
].join(','); ].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, _); })(Mibew, jQuery, _);

View File

@ -18,11 +18,20 @@
(function(Mibew, $) { (function(Mibew, $) {
$(document).ready(function(){ $(document).ready(function(){
$('a.remove-link').click(function(){ $('a.remove-link').click(function() {
return confirm(Mibew.Localization.trans( var url = $(this).attr('href'),
'Are you sure that you want to delete the group "{0}"?', message = Mibew.Localization.trans(
$(this).data('group-name') '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); })(Mibew, jQuery);

View File

@ -19,10 +19,19 @@
(function(Mibew, $) { (function(Mibew, $) {
$(document).ready(function(){ $(document).ready(function(){
$('a.remove-link').click(function(){ $('a.remove-link').click(function(){
return confirm(Mibew.Localization.trans( var url = $(this).attr('href'),
'Are you sure that you want to delete operator "{0}"?', message = Mibew.Localization.trans(
$(this).data('operator-login') '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); })(Mibew, jQuery);

View File

@ -19,10 +19,19 @@
(function(Mibew, $) { (function(Mibew, $) {
$(document).ready(function(){ $(document).ready(function(){
$('a.uninstall-link').click(function(){ $('a.uninstall-link').click(function(){
return confirm(Mibew.Localization.trans( var url = $(this).attr('href'),
'Are you sure that you want to uninstall plugin "{0}"?', message = Mibew.Localization.trans(
$(this).data('plugin-name') '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); })(Mibew, jQuery);

View File

@ -33,7 +33,7 @@
badRequestsCount++; badRequestsCount++;
// Check if there is // Check if there is
if (badRequestsCount == 10) { 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; badRequestsCount = 0;
} }
} }

View File

@ -190,7 +190,7 @@
// Show popup notification if need // Show popup notification if need
if (Mibew.Objects.Models.page.get('showPopup')) { if (Mibew.Objects.Models.page.get('showPopup')) {
this.once('render', function() { this.once('render', function() {
alert( Mibew.Utils.alert(
Mibew.Localization.trans('A new visitor is waiting for an answer.') Mibew.Localization.trans('A new visitor is waiting for an answer.')
); );
}) })

View File

@ -242,7 +242,7 @@
showFirstMessage: function() { showFirstMessage: function() {
var message = this.model.get('firstMessage'); var message = this.model.get('firstMessage');
if (message) { if (message) {
alert(message); Mibew.Utils.alert(message);
} }
} }