2015-03-13 14:01:42 +00:00
|
|
|
/* global $, APP, config*/
|
|
|
|
|
2015-12-15 12:09:44 +00:00
|
|
|
var messageHandler = require('../util/MessageHandler');
|
2015-03-13 14:01:42 +00:00
|
|
|
|
2015-12-17 15:31:11 +00:00
|
|
|
function getPasswordInputHtml() {
|
|
|
|
let placeholder = config.hosts.authdomain
|
|
|
|
? "user identity"
|
|
|
|
: "user@domain.net";
|
|
|
|
let passRequiredMsg = APP.translation.translateString(
|
|
|
|
"dialog.passwordRequired"
|
|
|
|
);
|
|
|
|
return `
|
|
|
|
<h2 data-i18n="dialog.passwordRequired">${passRequiredMsg}</h2>
|
|
|
|
<input name="username" type="text" placeholder=${placeholder} autofocus>
|
|
|
|
<input name="password" type="password"
|
|
|
|
data-i18n="[placeholder]dialog.userPassword"
|
|
|
|
placeholder="user password">
|
|
|
|
`;
|
|
|
|
}
|
2015-03-13 14:01:42 +00:00
|
|
|
|
2015-12-15 12:09:44 +00:00
|
|
|
function Dialog(successCallback, cancelCallback) {
|
2015-12-17 15:31:11 +00:00
|
|
|
const states = {
|
2015-03-13 14:01:42 +00:00
|
|
|
login: {
|
2015-12-17 15:31:11 +00:00
|
|
|
html: getPasswordInputHtml(),
|
|
|
|
buttons: [{
|
|
|
|
title: APP.translation.generateTranslationHTML("dialog.Ok"),
|
|
|
|
value: true
|
|
|
|
}, {
|
|
|
|
title: APP.translation.generateTranslationHTML("dialog.Cancel"),
|
|
|
|
value: false
|
|
|
|
}],
|
2015-03-13 14:01:42 +00:00
|
|
|
focus: ':input:first',
|
|
|
|
submit: function (e, v, m, f) {
|
|
|
|
e.preventDefault();
|
|
|
|
if (v) {
|
2015-12-17 15:31:11 +00:00
|
|
|
let jid = f.username;
|
|
|
|
let password = f.password;
|
2015-03-13 14:01:42 +00:00
|
|
|
if (jid && password) {
|
|
|
|
connDialog.goToState('connecting');
|
2015-12-15 12:09:44 +00:00
|
|
|
successCallback(jid, password);
|
2015-03-13 14:01:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// User cancelled
|
2015-12-15 12:09:44 +00:00
|
|
|
cancelCallback();
|
2015-03-13 14:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
connecting: {
|
|
|
|
title: APP.translation.translateString('dialog.connecting'),
|
|
|
|
html: '<div id="connectionStatus"></div>',
|
|
|
|
buttons: [],
|
|
|
|
defaultButton: 0
|
|
|
|
},
|
|
|
|
finished: {
|
|
|
|
title: APP.translation.translateString('dialog.error'),
|
|
|
|
html: '<div id="errorMessage"></div>',
|
2015-12-17 15:31:11 +00:00
|
|
|
buttons: [{
|
|
|
|
title: APP.translation.translateString('dialog.retry'),
|
|
|
|
value: 'retry'
|
|
|
|
}, {
|
|
|
|
title: APP.translation.generateTranslationHTML("dialog.Cancel"),
|
|
|
|
value: false
|
|
|
|
}],
|
2015-03-13 14:01:42 +00:00
|
|
|
defaultButton: 0,
|
|
|
|
submit: function (e, v, m, f) {
|
|
|
|
e.preventDefault();
|
2015-12-15 12:09:44 +00:00
|
|
|
if (v === 'retry') {
|
2015-03-13 14:01:42 +00:00
|
|
|
connDialog.goToState('login');
|
2015-12-15 12:09:44 +00:00
|
|
|
} else {
|
2015-12-17 15:31:11 +00:00
|
|
|
// User cancelled
|
2015-12-15 12:09:44 +00:00
|
|
|
cancelCallback();
|
|
|
|
}
|
2015-03-13 14:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-12-15 12:09:44 +00:00
|
|
|
var connDialog = messageHandler.openDialogWithStates(
|
|
|
|
states, { persistent: true, closeText: '' }, null
|
|
|
|
);
|
2015-03-13 14:01:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays error message in 'finished' state which allows either to cancel
|
|
|
|
* or retry.
|
|
|
|
* @param message the final message to be displayed.
|
|
|
|
*/
|
|
|
|
this.displayError = function (message) {
|
|
|
|
|
|
|
|
var finishedState = connDialog.getState('finished');
|
|
|
|
|
|
|
|
var errorMessageElem = finishedState.find('#errorMessage');
|
|
|
|
errorMessageElem.text(message);
|
|
|
|
|
|
|
|
connDialog.goToState('finished');
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes LoginDialog.
|
|
|
|
*/
|
|
|
|
this.close = function () {
|
|
|
|
connDialog.close();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-12-17 15:31:11 +00:00
|
|
|
const LoginDialog = {
|
2015-03-13 14:01:42 +00:00
|
|
|
|
2015-12-17 15:31:11 +00:00
|
|
|
showAuthDialog: function (successCallback, cancelCallback) {
|
2015-12-15 12:09:44 +00:00
|
|
|
return new Dialog(successCallback, cancelCallback);
|
|
|
|
},
|
|
|
|
|
|
|
|
showExternalAuthDialog: function (url, callback) {
|
|
|
|
var dialog = messageHandler.openCenteredPopup(
|
|
|
|
url, 910, 660,
|
|
|
|
// On closed
|
|
|
|
callback
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!dialog) {
|
|
|
|
messageHandler.openMessageDialog(null, "dialog.popupError");
|
|
|
|
}
|
|
|
|
|
|
|
|
return dialog;
|
2015-12-15 16:29:37 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
showAuthRequiredDialog: function (roomName, onAuthNow) {
|
|
|
|
var title = APP.translation.generateTranslationHTML(
|
|
|
|
"dialog.WaitingForHost"
|
|
|
|
);
|
|
|
|
var msg = APP.translation.generateTranslationHTML(
|
|
|
|
"dialog.WaitForHostMsg", {room: roomName}
|
|
|
|
);
|
|
|
|
|
|
|
|
var buttonTxt = APP.translation.generateTranslationHTML(
|
|
|
|
"dialog.IamHost"
|
|
|
|
);
|
|
|
|
var buttons = [{title: buttonTxt, value: "authNow"}];
|
|
|
|
|
|
|
|
return APP.UI.messageHandler.openDialog(
|
|
|
|
title,
|
|
|
|
msg,
|
|
|
|
true,
|
|
|
|
buttons,
|
2015-12-17 15:31:11 +00:00
|
|
|
function (e, submitValue) {
|
2015-12-15 16:29:37 +00:00
|
|
|
|
|
|
|
// Do not close the dialog yet
|
2015-12-17 15:31:11 +00:00
|
|
|
e.preventDefault();
|
2015-12-15 16:29:37 +00:00
|
|
|
|
|
|
|
// Open login popup
|
|
|
|
if (submitValue === 'authNow') {
|
|
|
|
onAuthNow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2015-03-13 14:01:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-12-17 15:31:11 +00:00
|
|
|
export default LoginDialog;
|