2015-01-07 11:28:16 +00:00
|
|
|
/* global $, jQuery */
|
2014-08-14 15:29:28 +00:00
|
|
|
var messageHandler = (function(my) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows a message to the user.
|
|
|
|
*
|
|
|
|
* @param titleString the title of the message
|
|
|
|
* @param messageString the text of the message
|
|
|
|
*/
|
2015-02-26 15:35:35 +00:00
|
|
|
my.openMessageDialog = function(titleKey, messageKey) {
|
2015-02-20 16:17:46 +00:00
|
|
|
var title = null;
|
|
|
|
if(titleKey)
|
|
|
|
{
|
2015-02-26 15:35:35 +00:00
|
|
|
title = APP.translation.generateTranslatonHTML(titleKey);
|
2015-02-20 16:17:46 +00:00
|
|
|
}
|
2015-02-26 15:35:35 +00:00
|
|
|
var message = APP.translation.generateTranslatonHTML(messageKey);
|
2015-02-20 16:17:46 +00:00
|
|
|
$.prompt(message,
|
2014-08-14 15:29:28 +00:00
|
|
|
{
|
2015-02-20 16:17:46 +00:00
|
|
|
title: title,
|
2014-08-14 15:29:28 +00:00
|
|
|
persistent: false
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows a message to the user with two buttons: first is given as a parameter and the second is Cancel.
|
|
|
|
*
|
|
|
|
* @param titleString the title of the message
|
|
|
|
* @param msgString the text of the message
|
|
|
|
* @param persistent boolean value which determines whether the message is persistent or not
|
|
|
|
* @param leftButton the fist button's text
|
|
|
|
* @param submitFunction function to be called on submit
|
|
|
|
* @param loadedFunction function to be called after the prompt is fully loaded
|
2014-10-24 13:33:48 +00:00
|
|
|
* @param closeFunction function to be called after the prompt is closed
|
2014-08-14 15:29:28 +00:00
|
|
|
*/
|
2015-02-20 16:17:46 +00:00
|
|
|
my.openTwoButtonDialog = function(titleKey, titleString, msgKey, msgString,
|
|
|
|
persistent, leftButtonKey, submitFunction, loadedFunction,
|
|
|
|
closeFunction)
|
|
|
|
{
|
|
|
|
var leftButton = APP.translation.generateTranslatonHTML(leftButtonKey);
|
2014-08-14 15:29:28 +00:00
|
|
|
var buttons = {};
|
2015-02-24 08:57:41 +00:00
|
|
|
buttons.button1 = {title: leftButton, value: true};
|
2015-02-26 15:35:35 +00:00
|
|
|
var cancelButton = APP.translation.generateTranslatonHTML("dialog.Cancel");
|
2015-02-24 08:57:41 +00:00
|
|
|
buttons.button2 = {title: cancelButton, value: false};
|
2015-02-20 16:17:46 +00:00
|
|
|
var message = msgString, title = titleString;
|
|
|
|
if(titleKey)
|
|
|
|
{
|
2015-02-26 15:35:35 +00:00
|
|
|
title = APP.translation.generateTranslatonHTML(titleKey);
|
2015-02-20 16:17:46 +00:00
|
|
|
}
|
|
|
|
if(msgKey) {
|
2015-02-26 15:35:35 +00:00
|
|
|
message = APP.translation.generateTranslatonHTML(msgKey);
|
2015-02-20 16:17:46 +00:00
|
|
|
}
|
|
|
|
$.prompt(message, {
|
|
|
|
title: title,
|
2014-08-14 15:29:28 +00:00
|
|
|
persistent: false,
|
|
|
|
buttons: buttons,
|
|
|
|
defaultButton: 1,
|
|
|
|
loaded: loadedFunction,
|
2014-10-24 13:33:48 +00:00
|
|
|
submit: submitFunction,
|
|
|
|
close: closeFunction
|
2014-08-14 15:29:28 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-09-24 14:35:35 +00:00
|
|
|
/**
|
|
|
|
* Shows a message to the user with two buttons: first is given as a parameter and the second is Cancel.
|
|
|
|
*
|
|
|
|
* @param titleString the title of the message
|
|
|
|
* @param msgString the text of the message
|
|
|
|
* @param persistent boolean value which determines whether the message is persistent or not
|
|
|
|
* @param buttons object with the buttons. The keys must be the name of the button and value is the value
|
|
|
|
* that will be passed to submitFunction
|
|
|
|
* @param submitFunction function to be called on submit
|
|
|
|
* @param loadedFunction function to be called after the prompt is fully loaded
|
|
|
|
*/
|
2015-02-26 15:35:35 +00:00
|
|
|
my.openDialog = function (titleString, msgString, persistent, buttons,
|
2015-01-07 11:28:16 +00:00
|
|
|
submitFunction, loadedFunction) {
|
|
|
|
var args = {
|
2014-09-24 14:35:35 +00:00
|
|
|
title: titleString,
|
2015-01-07 11:28:16 +00:00
|
|
|
persistent: persistent,
|
2014-09-24 14:35:35 +00:00
|
|
|
buttons: buttons,
|
|
|
|
defaultButton: 1,
|
|
|
|
loaded: loadedFunction,
|
|
|
|
submit: submitFunction
|
2015-01-07 11:28:16 +00:00
|
|
|
};
|
|
|
|
if (persistent) {
|
|
|
|
args.closeText = '';
|
|
|
|
}
|
|
|
|
return $.prompt(msgString, args);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes currently opened dialog.
|
|
|
|
*/
|
|
|
|
my.closeDialog = function () {
|
|
|
|
$.prompt.close();
|
2014-09-24 14:35:35 +00:00
|
|
|
};
|
|
|
|
|
2014-08-14 15:29:28 +00:00
|
|
|
/**
|
|
|
|
* Shows a dialog with different states to the user.
|
|
|
|
*
|
|
|
|
* @param statesObject object containing all the states of the dialog
|
|
|
|
* @param loadedFunction function to be called after the prompt is fully loaded
|
|
|
|
* @param stateChangedFunction function to be called when the state of the dialog is changed
|
|
|
|
*/
|
|
|
|
my.openDialogWithStates = function(statesObject, loadedFunction, stateChangedFunction) {
|
|
|
|
|
|
|
|
|
|
|
|
var myPrompt = $.prompt(statesObject);
|
|
|
|
|
|
|
|
myPrompt.on('impromptu:loaded', loadedFunction);
|
|
|
|
myPrompt.on('impromptu:statechanged', stateChangedFunction);
|
|
|
|
};
|
|
|
|
|
2014-12-16 13:54:13 +00:00
|
|
|
/**
|
|
|
|
* Opens new popup window for given <tt>url</tt> centered over current
|
|
|
|
* window.
|
|
|
|
*
|
|
|
|
* @param url the URL to be displayed in the popup window
|
|
|
|
* @param w the width of the popup window
|
|
|
|
* @param h the height of the popup window
|
|
|
|
* @param onPopupClosed optional callback function called when popup window
|
|
|
|
* has been closed.
|
2014-12-16 18:04:22 +00:00
|
|
|
*
|
|
|
|
* @returns popup window object if opened successfully or undefined
|
|
|
|
* in case we failed to open it(popup blocked)
|
2014-12-16 13:54:13 +00:00
|
|
|
*/
|
|
|
|
my.openCenteredPopup = function (url, w, h, onPopupClosed) {
|
|
|
|
var l = window.screenX + (window.innerWidth / 2) - (w / 2);
|
|
|
|
var t = window.screenY + (window.innerHeight / 2) - (h / 2);
|
|
|
|
var popup = window.open(
|
|
|
|
url, '_blank',
|
|
|
|
'top=' + t + ', left=' + l + ', width=' + w + ', height=' + h + '');
|
2014-12-16 18:04:22 +00:00
|
|
|
if (popup && onPopupClosed) {
|
2014-12-16 13:54:13 +00:00
|
|
|
var pollTimer = window.setInterval(function () {
|
|
|
|
if (popup.closed !== false) {
|
|
|
|
window.clearInterval(pollTimer);
|
|
|
|
onPopupClosed();
|
|
|
|
}
|
|
|
|
}, 200);
|
|
|
|
}
|
2014-12-16 18:04:22 +00:00
|
|
|
return popup;
|
2014-12-16 13:54:13 +00:00
|
|
|
};
|
|
|
|
|
2014-08-14 15:29:28 +00:00
|
|
|
/**
|
|
|
|
* Shows a dialog prompting the user to send an error report.
|
|
|
|
*
|
|
|
|
* @param titleString the title of the message
|
|
|
|
* @param msgString the text of the message
|
|
|
|
* @param error the error that is being reported
|
|
|
|
*/
|
2015-02-26 15:35:35 +00:00
|
|
|
my.openReportDialog = function(titleKey, msgKey, error) {
|
|
|
|
my.openMessageDialog(titleKey, msgKey);
|
2014-08-14 15:29:28 +00:00
|
|
|
console.log(error);
|
|
|
|
//FIXME send the error to the server
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows an error dialog to the user.
|
|
|
|
* @param title the title of the message
|
|
|
|
* @param message the text of the messafe
|
|
|
|
*/
|
2015-02-26 15:35:35 +00:00
|
|
|
my.showError = function(titleKey, msgKey) {
|
2015-02-20 16:17:46 +00:00
|
|
|
|
|
|
|
if(!titleKey) {
|
|
|
|
titleKey = "dialog.oops";
|
|
|
|
}
|
|
|
|
if(!msgKey)
|
|
|
|
{
|
|
|
|
msgKey = "dialog.defaultError";
|
2014-08-14 15:29:28 +00:00
|
|
|
}
|
2015-02-26 15:35:35 +00:00
|
|
|
messageHandler.openMessageDialog(titleKey, msgKey);
|
2014-08-14 15:29:28 +00:00
|
|
|
};
|
|
|
|
|
2015-02-26 15:35:35 +00:00
|
|
|
my.notify = function(displayName, displayNameKey,
|
|
|
|
cls, messageKey, messageArguments) {
|
2015-02-13 16:28:35 +00:00
|
|
|
var displayNameSpan = '<span class="nickname" ';
|
|
|
|
if(displayName)
|
|
|
|
{
|
|
|
|
displayNameSpan += ">" + displayName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
displayNameSpan += "data-i18n='" + displayNameKey +
|
2015-02-26 15:35:35 +00:00
|
|
|
"'>" + APP.translation.translateString(displayNameKey);
|
2015-02-13 16:28:35 +00:00
|
|
|
}
|
|
|
|
displayNameSpan += "</span>";
|
2014-10-30 16:07:11 +00:00
|
|
|
toastr.info(
|
2015-02-13 16:28:35 +00:00
|
|
|
displayNameSpan + '<br>' +
|
|
|
|
'<span class=' + cls + ' data-i18n="' + messageKey + '"' +
|
|
|
|
(messageArguments?
|
2015-02-27 18:05:32 +00:00
|
|
|
" data-i18n-options='" + JSON.stringify(messageArguments) + "'"
|
2015-02-13 16:28:35 +00:00
|
|
|
: "") + ">" +
|
2015-02-26 15:35:35 +00:00
|
|
|
APP.translation.translateString(messageKey,
|
|
|
|
messageArguments) +
|
2014-10-30 16:07:11 +00:00
|
|
|
'</span>');
|
|
|
|
};
|
|
|
|
|
2014-08-14 15:29:28 +00:00
|
|
|
return my;
|
|
|
|
}(messageHandler || {}));
|
|
|
|
|
2015-01-07 14:54:03 +00:00
|
|
|
module.exports = messageHandler;
|
|
|
|
|
2014-08-14 15:29:28 +00:00
|
|
|
|