2017-10-10 23:43:22 +00:00
|
|
|
/* global $, APP */
|
2017-10-12 23:02:29 +00:00
|
|
|
import UIUtil from '../../util/UIUtil';
|
|
|
|
import UIEvents from '../../../../service/UI/UIEvents';
|
2016-09-11 21:54:32 +00:00
|
|
|
import Settings from '../../../settings/Settings';
|
|
|
|
|
2017-12-11 18:48:32 +00:00
|
|
|
import {
|
|
|
|
AUTHENTICATE_LOGIN_CLICKED,
|
|
|
|
AUTHENTICATE_LOGOUT_CLICKED,
|
|
|
|
sendAnalyticsEvent
|
|
|
|
} from '../../../../react/features/analytics';
|
2017-10-10 23:43:22 +00:00
|
|
|
|
2016-11-02 14:58:43 +00:00
|
|
|
const sidePanelsContainerId = 'sideToolbarContainer';
|
|
|
|
const htmlStr = `
|
2017-10-12 23:02:29 +00:00
|
|
|
<div id='profile_container' class='sideToolbarContainer__inner'>
|
|
|
|
<div class='title' data-i18n='profile.title'></div>
|
|
|
|
<div class='sideToolbarBlock first'>
|
|
|
|
<label class='first' data-i18n='profile.setDisplayNameLabel'>
|
2016-10-25 13:16:15 +00:00
|
|
|
</label>
|
2017-10-12 23:02:29 +00:00
|
|
|
<input class='input-control' type='text' id='setDisplayName'
|
|
|
|
data-i18n='[placeholder]settings.name'>
|
2016-10-25 13:16:15 +00:00
|
|
|
</div>
|
2017-10-12 23:02:29 +00:00
|
|
|
<div class='sideToolbarBlock'>
|
|
|
|
<label data-i18n='profile.setEmailLabel'></label>
|
|
|
|
<input id='setEmail' type='text' class='input-control'
|
|
|
|
data-i18n='[placeholder]profile.setEmailInput'>
|
2016-10-25 13:16:15 +00:00
|
|
|
</div>
|
2017-10-12 23:02:29 +00:00
|
|
|
<div id='profile_auth_container'
|
|
|
|
class='sideToolbarBlock auth_container'>
|
|
|
|
<p data-i18n='toolbar.authenticate'></p>
|
2016-10-25 13:16:15 +00:00
|
|
|
<ul>
|
2017-10-12 23:02:29 +00:00
|
|
|
<li id='profile_auth_identity'></li>
|
|
|
|
<li id='profile_button_login'>
|
|
|
|
<a class='authButton' data-i18n='toolbar.login'></a>
|
2016-10-25 13:16:15 +00:00
|
|
|
</li>
|
2017-10-12 23:02:29 +00:00
|
|
|
<li id='profile_button_logout'>
|
|
|
|
<a class='authButton' data-i18n='toolbar.logout'></a>
|
2016-10-25 13:16:15 +00:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2016-11-02 14:58:43 +00:00
|
|
|
</div>`;
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2016-10-25 13:16:15 +00:00
|
|
|
function initHTML() {
|
2016-11-02 14:58:43 +00:00
|
|
|
$(`#${sidePanelsContainerId}`)
|
|
|
|
.append(htmlStr);
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2017-04-06 20:21:04 +00:00
|
|
|
// make sure we translate the panel, as adding it can be after i18n
|
|
|
|
// library had initialized and translated already present html
|
|
|
|
APP.translation.translateElement($(`#${sidePanelsContainerId}`));
|
2016-10-25 13:16:15 +00:00
|
|
|
}
|
|
|
|
|
2016-09-11 21:54:32 +00:00
|
|
|
export default {
|
2017-10-12 23:02:29 +00:00
|
|
|
init(emitter) {
|
2016-10-25 13:16:15 +00:00
|
|
|
initHTML();
|
2017-10-12 23:02:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates display name.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function updateDisplayName() {
|
2016-09-11 21:54:32 +00:00
|
|
|
emitter.emit(UIEvents.NICKNAME_CHANGED, $('#setDisplayName').val());
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#setDisplayName')
|
|
|
|
.val(Settings.getDisplayName())
|
2017-10-12 23:02:29 +00:00
|
|
|
.keyup(event => {
|
2016-09-11 21:54:32 +00:00
|
|
|
if (event.keyCode === 13) { // enter
|
|
|
|
updateDisplayName();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.focusout(updateDisplayName);
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
/**
|
|
|
|
* Updates the email.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function updateEmail() {
|
2016-09-11 21:54:32 +00:00
|
|
|
emitter.emit(UIEvents.EMAIL_CHANGED, $('#setEmail').val());
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#setEmail')
|
|
|
|
.val(Settings.getEmail())
|
2017-10-12 23:02:29 +00:00
|
|
|
.keyup(event => {
|
2016-09-11 21:54:32 +00:00
|
|
|
if (event.keyCode === 13) { // enter
|
|
|
|
updateEmail();
|
|
|
|
}
|
2017-10-12 23:02:29 +00:00
|
|
|
})
|
|
|
|
.focusout(updateEmail);
|
2016-11-23 21:24:55 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function loginClicked() {
|
2017-12-11 18:48:32 +00:00
|
|
|
sendAnalyticsEvent(AUTHENTICATE_LOGIN_CLICKED);
|
2016-11-23 21:24:55 +00:00
|
|
|
emitter.emit(UIEvents.AUTH_CLICKED);
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#profile_button_login').click(loginClicked);
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function logoutClicked() {
|
|
|
|
const titleKey = 'dialog.logoutTitle';
|
|
|
|
const msgKey = 'dialog.logoutQuestion';
|
|
|
|
|
2017-12-11 18:48:32 +00:00
|
|
|
sendAnalyticsEvent(AUTHENTICATE_LOGOUT_CLICKED);
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2016-11-23 21:24:55 +00:00
|
|
|
// Ask for confirmation
|
|
|
|
APP.UI.messageHandler.openTwoButtonDialog({
|
2017-10-12 23:02:29 +00:00
|
|
|
titleKey,
|
|
|
|
msgKey,
|
|
|
|
leftButtonKey: 'dialog.Yes',
|
|
|
|
submitFunction(evt, yes) {
|
2016-11-23 21:24:55 +00:00
|
|
|
if (yes) {
|
|
|
|
emitter.emit(UIEvents.LOGOUT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#profile_button_logout').click(logoutClicked);
|
2016-09-11 21:54:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if settings menu is visible or not.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
isVisible() {
|
|
|
|
return UIUtil.isVisible(document.getElementById('profile_container'));
|
2016-09-11 21:54:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change user display name in the settings menu.
|
|
|
|
* @param {string} newDisplayName
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
changeDisplayName(newDisplayName) {
|
2016-09-11 21:54:32 +00:00
|
|
|
$('#setDisplayName').val(newDisplayName);
|
|
|
|
},
|
|
|
|
|
2017-03-23 18:01:33 +00:00
|
|
|
/**
|
|
|
|
* Change the value of the field for the user email.
|
|
|
|
* @param {string} email the new value that will be displayed in the field.
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
changeEmail(email) {
|
2017-03-23 18:01:33 +00:00
|
|
|
$('#setEmail').val(email);
|
|
|
|
},
|
|
|
|
|
2016-11-23 21:24:55 +00:00
|
|
|
/**
|
|
|
|
* Shows or hides authentication related buttons
|
|
|
|
* @param {boolean} show <tt>true</tt> to show or <tt>false</tt> to hide
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
showAuthenticationButtons(show) {
|
|
|
|
const id = 'profile_auth_container';
|
|
|
|
|
2016-11-29 21:07:18 +00:00
|
|
|
UIUtil.setVisible(id, show);
|
2016-11-23 21:24:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows/hides login button.
|
|
|
|
* @param {boolean} show <tt>true</tt> to show or <tt>false</tt> to hide
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
showLoginButton(show) {
|
|
|
|
const id = 'profile_button_login';
|
2016-11-23 21:24:55 +00:00
|
|
|
|
2016-11-29 21:07:18 +00:00
|
|
|
UIUtil.setVisible(id, show);
|
2016-11-23 21:24:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows/hides logout button.
|
|
|
|
* @param {boolean} show <tt>true</tt> to show or <tt>false</tt> to hide
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
showLogoutButton(show) {
|
|
|
|
const id = 'profile_button_logout';
|
2016-11-23 21:24:55 +00:00
|
|
|
|
2016-11-29 21:07:18 +00:00
|
|
|
UIUtil.setVisible(id, show);
|
2016-11-23 21:24:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays user's authenticated identity name (login).
|
|
|
|
* @param {string} authIdentity identity name to be displayed.
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
setAuthenticatedIdentity(authIdentity) {
|
|
|
|
const id = 'profile_auth_identity';
|
2016-11-23 21:24:55 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
UIUtil.setVisible(id, Boolean(authIdentity));
|
2016-11-23 21:24:55 +00:00
|
|
|
|
|
|
|
$(`#${id}`).text(authIdentity ? authIdentity : '');
|
2016-09-11 21:54:32 +00:00
|
|
|
}
|
2016-10-03 16:12:04 +00:00
|
|
|
};
|