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, $) {
$(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);

View File

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

View File

@ -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, _);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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