2016-10-12 00:08:24 +00:00
|
|
|
/* global $, APP, JitsiMeetJS */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Substate for password
|
|
|
|
* @type {{LOCKED: string, UNLOCKED: string}}
|
|
|
|
*/
|
|
|
|
const States = {
|
|
|
|
LOCKED: 'locked',
|
|
|
|
UNLOCKED: 'unlocked'
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class representing view for Invite dialog
|
|
|
|
* @class InviteDialogView
|
|
|
|
*/
|
|
|
|
export default class InviteDialogView {
|
|
|
|
constructor(model) {
|
|
|
|
this.unlockHint = "unlockHint";
|
|
|
|
this.lockHint = "lockHint";
|
|
|
|
this.model = model;
|
|
|
|
|
|
|
|
if (this.model.inviteUrl === null) {
|
2016-10-21 17:11:22 +00:00
|
|
|
this.inviteAttributes = `data-i18n="[value]inviteUrlDefaultMsg"`;
|
2016-10-12 00:08:24 +00:00
|
|
|
} else {
|
2016-10-21 17:11:22 +00:00
|
|
|
this.inviteAttributes
|
|
|
|
= `value="${this.model.getEncodedInviteUrl()}"`;
|
2016-10-12 00:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.initDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialization of dialog property
|
|
|
|
*/
|
|
|
|
initDialog() {
|
|
|
|
let dialog = {};
|
|
|
|
dialog.closeFunction = this.closeFunction.bind(this);
|
|
|
|
dialog.submitFunction = this.submitFunction.bind(this);
|
|
|
|
dialog.loadedFunction = this.loadedFunction.bind(this);
|
|
|
|
|
2016-10-17 23:14:38 +00:00
|
|
|
dialog.titleKey = "dialog.shareLink";
|
2016-10-12 00:08:24 +00:00
|
|
|
this.dialog = dialog;
|
|
|
|
|
|
|
|
this.dialog.states = this.getStates();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for submitting dialog
|
|
|
|
* @param e
|
|
|
|
* @param v
|
|
|
|
*/
|
|
|
|
submitFunction(e, v) {
|
|
|
|
if (v && this.model.inviteUrl) {
|
|
|
|
JitsiMeetJS.analytics.sendEvent('toolbar.invite.button');
|
|
|
|
} else {
|
|
|
|
JitsiMeetJS.analytics.sendEvent('toolbar.invite.cancel');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for load dialog
|
|
|
|
* @param event
|
|
|
|
*/
|
|
|
|
loadedFunction(event) {
|
|
|
|
if (this.model.inviteUrl) {
|
|
|
|
document.getElementById('inviteLinkRef').select();
|
|
|
|
} else {
|
|
|
|
if (event && event.target) {
|
|
|
|
$(event.target).find('button[value=true]')
|
|
|
|
.prop('disabled', true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for closing dialog
|
|
|
|
* @param e
|
|
|
|
* @param v
|
|
|
|
* @param m
|
|
|
|
* @param f
|
|
|
|
*/
|
|
|
|
closeFunction(e, v, m, f) {
|
|
|
|
$(document).off('click', '.copyInviteLink', this.copyToClipboard);
|
|
|
|
|
|
|
|
if(!v && !m && !f)
|
|
|
|
JitsiMeetJS.analytics.sendEvent('toolbar.invite.close');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns all states of the dialog
|
|
|
|
* @returns {{}}
|
|
|
|
*/
|
|
|
|
getStates() {
|
|
|
|
let {
|
2016-10-17 23:14:38 +00:00
|
|
|
titleKey
|
2016-10-12 00:08:24 +00:00
|
|
|
} = this.dialog;
|
2016-10-21 17:11:22 +00:00
|
|
|
let doneMsg = APP.translation.generateTranslationHTML('dialog.done');
|
2016-10-12 00:08:24 +00:00
|
|
|
let states = {};
|
2016-10-18 13:53:28 +00:00
|
|
|
let buttons = {};
|
|
|
|
buttons[`${doneMsg}`] = true;
|
2016-10-12 00:08:24 +00:00
|
|
|
|
|
|
|
states[States.UNLOCKED] = {
|
2016-10-17 23:14:38 +00:00
|
|
|
titleKey,
|
2016-10-18 13:53:28 +00:00
|
|
|
html: this.getShareLinkBlock() + this.getAddPasswordBlock(),
|
|
|
|
buttons
|
2016-10-12 00:08:24 +00:00
|
|
|
};
|
|
|
|
states[States.LOCKED] = {
|
2016-10-17 23:14:38 +00:00
|
|
|
titleKey,
|
2016-10-18 13:53:28 +00:00
|
|
|
html: this.getShareLinkBlock() + this.getPasswordBlock(),
|
|
|
|
buttons
|
2016-10-12 00:08:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return states;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Layout for invite link input
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
getShareLinkBlock() {
|
|
|
|
let classes = 'button-control button-control_light copyInviteLink';
|
|
|
|
return (
|
2016-11-08 15:46:59 +00:00
|
|
|
`<div class="form-control">
|
|
|
|
<label class="form-control__label" for="inviteLinkRef"
|
2016-10-21 17:11:22 +00:00
|
|
|
data-i18n="${this.dialog.titleKey}"></label>
|
2016-11-08 15:46:59 +00:00
|
|
|
<div class="form-control__container">
|
2016-11-09 16:46:58 +00:00
|
|
|
<input class="input-control inviteLink"
|
2016-10-12 00:08:24 +00:00
|
|
|
id="inviteLinkRef" type="text"
|
|
|
|
${this.inviteAttributes} readonly>
|
2016-10-21 17:11:22 +00:00
|
|
|
<button data-i18n="dialog.copy" class="${classes}"></button>
|
2016-10-12 00:08:24 +00:00
|
|
|
</div>
|
2016-11-08 15:46:59 +00:00
|
|
|
<p class="form-control__hint ${this.lockHint}">
|
2016-10-12 00:08:24 +00:00
|
|
|
<span class="icon-security-locked"></span>
|
2016-10-21 17:11:22 +00:00
|
|
|
<span data-i18n="dialog.roomLocked"></span>
|
2016-10-12 00:08:24 +00:00
|
|
|
</p>
|
2016-11-08 15:46:59 +00:00
|
|
|
<p class="form-control__hint ${this.unlockHint}">
|
2016-10-12 00:08:24 +00:00
|
|
|
<span class="icon-security"></span>
|
2016-10-21 17:11:22 +00:00
|
|
|
<span data-i18n="roomUnlocked"></span>
|
2016-10-12 00:08:24 +00:00
|
|
|
</p>
|
|
|
|
</div>`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Layout for adding password input
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
getAddPasswordBlock() {
|
|
|
|
let html;
|
|
|
|
|
|
|
|
if (this.model.isModerator) {
|
|
|
|
html = (`
|
2016-11-08 15:46:59 +00:00
|
|
|
<div class="form-control">
|
|
|
|
<label class="form-control__label"
|
2016-10-21 17:11:22 +00:00
|
|
|
for="newPasswordInput" data-i18n="dialog.addPassword">
|
|
|
|
</label>
|
2016-11-08 15:46:59 +00:00
|
|
|
<div class="form-control__container">
|
2016-11-09 16:46:58 +00:00
|
|
|
<input class="input-control"
|
|
|
|
id="newPasswordInput"
|
2016-10-25 20:18:56 +00:00
|
|
|
type="text"
|
|
|
|
data-i18n="[placeholder]dialog.createPassword">
|
2016-10-12 00:08:24 +00:00
|
|
|
<button id="addPasswordBtn" id="inviteDialogAddPassword"
|
2016-10-21 17:11:22 +00:00
|
|
|
disabled data-i18n="dialog.add"
|
2016-10-12 00:08:24 +00:00
|
|
|
class="button-control button-control_light">
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`);
|
|
|
|
} else {
|
|
|
|
html = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Layout for password (when room is locked)
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
getPasswordBlock() {
|
2016-10-31 19:01:22 +00:00
|
|
|
let password = this.model.getPassword();
|
|
|
|
let { isModerator } = this.model;
|
2016-10-12 00:08:24 +00:00
|
|
|
|
|
|
|
if (isModerator) {
|
|
|
|
return (`
|
2016-11-08 15:46:59 +00:00
|
|
|
<div class="form-control">
|
|
|
|
<label class="form-control__label"
|
2016-10-21 17:11:22 +00:00
|
|
|
data-i18n="dialog.passwordLabel"></label>
|
2016-11-08 15:46:59 +00:00
|
|
|
<div class="form-control__container">
|
2016-10-21 17:11:22 +00:00
|
|
|
<p>
|
2016-11-08 15:46:59 +00:00
|
|
|
<span class="form-control__text"
|
2016-10-21 17:11:22 +00:00
|
|
|
data-i18n="dialog.currentPassword"></span>
|
2016-10-12 00:08:24 +00:00
|
|
|
<span id="inviteDialogPassword"
|
2016-11-08 15:46:59 +00:00
|
|
|
class="form-control__em">
|
2016-10-12 00:08:24 +00:00
|
|
|
${password}
|
|
|
|
</span>
|
|
|
|
</p>
|
2016-11-08 15:46:59 +00:00
|
|
|
<a class="link form-control__right"
|
2016-10-12 00:08:24 +00:00
|
|
|
id="inviteDialogRemovePassword"
|
2016-10-21 17:11:22 +00:00
|
|
|
data-i18n="dialog.removePassword"></a>
|
2016-10-12 00:08:24 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`);
|
|
|
|
} else {
|
|
|
|
return (`
|
2016-11-08 15:46:59 +00:00
|
|
|
<div class="form-control">
|
2016-10-12 00:08:24 +00:00
|
|
|
<p>A participant protected this call with a password.</p>
|
|
|
|
</div>
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opening the dialog
|
|
|
|
*/
|
|
|
|
open() {
|
|
|
|
let {
|
|
|
|
submitFunction,
|
|
|
|
loadedFunction,
|
|
|
|
closeFunction
|
|
|
|
} = this.dialog;
|
|
|
|
|
|
|
|
let states = this.getStates();
|
|
|
|
let initial = this.model.roomLocked ? States.LOCKED : States.UNLOCKED;
|
|
|
|
|
|
|
|
APP.UI.messageHandler.openDialogWithStates(states, {
|
|
|
|
submit: submitFunction,
|
|
|
|
loaded: loadedFunction,
|
|
|
|
close: closeFunction,
|
|
|
|
size: 'medium'
|
|
|
|
});
|
|
|
|
$.prompt.goToState(initial);
|
|
|
|
|
|
|
|
this.registerListeners();
|
|
|
|
this.updateView();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setting event handlers
|
|
|
|
* used in dialog
|
|
|
|
*/
|
|
|
|
registerListeners() {
|
2016-10-17 12:51:55 +00:00
|
|
|
const ENTER_KEY = 13;
|
|
|
|
let addPasswordBtn = '#addPasswordBtn';
|
|
|
|
let copyInviteLink = '.copyInviteLink';
|
|
|
|
let newPasswordInput = '#newPasswordInput';
|
|
|
|
let removePassword = '#inviteDialogRemovePassword';
|
|
|
|
|
|
|
|
$(document).on('click', copyInviteLink, this.copyToClipboard);
|
|
|
|
$(removePassword).on('click', () => {
|
2016-10-12 00:08:24 +00:00
|
|
|
this.model.setRoomUnlocked();
|
|
|
|
});
|
2016-10-18 14:20:48 +00:00
|
|
|
let boundSetPassword = this._setPassword.bind(this);
|
2016-10-17 12:51:55 +00:00
|
|
|
$(document).on('click', addPasswordBtn, boundSetPassword);
|
|
|
|
let boundDisablePass = this.disableAddPassIfInputEmpty.bind(this);
|
|
|
|
$(document).on('keypress', newPasswordInput, boundDisablePass);
|
|
|
|
|
|
|
|
// We need to handle keydown event because impromptu
|
|
|
|
// is listening to it too for closing the dialog
|
|
|
|
$(newPasswordInput).on('keydown', (e) => {
|
|
|
|
if (e.keyCode === ENTER_KEY) {
|
|
|
|
e.stopPropagation();
|
2016-10-18 14:20:48 +00:00
|
|
|
this._setPassword();
|
2016-10-17 12:51:55 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-10-18 14:20:48 +00:00
|
|
|
/**
|
|
|
|
* Marking room as locked
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_setPassword() {
|
2016-10-17 12:51:55 +00:00
|
|
|
let $passInput = $('#newPasswordInput');
|
|
|
|
let newPass = $passInput.val();
|
|
|
|
|
|
|
|
if(newPass) {
|
|
|
|
this.model.setRoomLocked(newPass);
|
|
|
|
}
|
2016-10-12 00:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checking input and if it's empty then
|
|
|
|
* disable add pass button
|
|
|
|
*/
|
|
|
|
disableAddPassIfInputEmpty() {
|
|
|
|
let $passInput = $('#newPasswordInput');
|
|
|
|
let $addPassBtn = $('#addPasswordBtn');
|
|
|
|
|
|
|
|
if(!$passInput.val()) {
|
|
|
|
$addPassBtn.prop('disabled', true);
|
|
|
|
} else {
|
|
|
|
$addPassBtn.prop('disabled', false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copying text to clipboard
|
|
|
|
*/
|
|
|
|
copyToClipboard() {
|
|
|
|
$('.inviteLink').each(function () {
|
|
|
|
let $el = $(this).closest('.jqistate');
|
|
|
|
|
|
|
|
// TOFIX: We can select only visible elements
|
|
|
|
if($el.css('display') === 'block') {
|
|
|
|
this.select();
|
|
|
|
|
|
|
|
try {
|
|
|
|
document.execCommand('copy');
|
|
|
|
this.blur();
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
console.error('error when copy the text');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method syncing the view and the model
|
|
|
|
*/
|
|
|
|
updateView() {
|
|
|
|
let pass = this.model.getPassword();
|
2016-10-31 19:01:22 +00:00
|
|
|
let { isModerator } = this.model;
|
2016-10-31 19:40:46 +00:00
|
|
|
if (this.model.getRoomLocker().lockedElsewhere || !pass) {
|
2016-10-21 17:11:22 +00:00
|
|
|
$('#inviteDialogPassword').attr("data-i18n", "passwordSetRemotely");
|
2016-10-31 19:40:46 +00:00
|
|
|
APP.translation.translateElement($('#inviteDialogPassword'));
|
|
|
|
} else {
|
|
|
|
$('#inviteDialogPassword').removeAttr("data-i18n");
|
2016-10-21 17:11:22 +00:00
|
|
|
$('#inviteDialogPassword').text(pass);
|
2016-10-31 19:40:46 +00:00
|
|
|
}
|
2016-10-21 17:11:22 +00:00
|
|
|
|
|
|
|
// if we are not moderator we cannot remove password
|
2016-10-31 19:01:22 +00:00
|
|
|
if (isModerator)
|
2016-10-21 17:11:22 +00:00
|
|
|
$('#inviteDialogRemovePassword').show();
|
|
|
|
else
|
|
|
|
$('#inviteDialogRemovePassword').hide();
|
2016-10-12 00:08:24 +00:00
|
|
|
|
|
|
|
$('#newPasswordInput').val('');
|
|
|
|
this.disableAddPassIfInputEmpty();
|
|
|
|
|
|
|
|
this.updateInviteLink();
|
|
|
|
|
|
|
|
$.prompt.goToState(
|
|
|
|
(this.model.isLocked())
|
|
|
|
? States.LOCKED
|
|
|
|
: States.UNLOCKED);
|
|
|
|
|
|
|
|
let roomLocked = `.${this.lockHint}`;
|
|
|
|
let roomUnlocked = `.${this.unlockHint}`;
|
|
|
|
|
|
|
|
let showDesc = this.model.isLocked() ? roomLocked : roomUnlocked;
|
|
|
|
let hideDesc = !this.model.isLocked() ? roomLocked : roomUnlocked;
|
|
|
|
|
|
|
|
$(showDesc).show();
|
|
|
|
$(hideDesc).hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates invite link
|
|
|
|
*/
|
|
|
|
updateInviteLink() {
|
|
|
|
// If the invite dialog has been already opened we update the
|
|
|
|
// information.
|
|
|
|
let inviteLink = document.querySelectorAll('.inviteLink');
|
|
|
|
let list = Array.from(inviteLink);
|
|
|
|
list.forEach((inviteLink) => {
|
|
|
|
inviteLink.value = this.model.inviteUrl;
|
|
|
|
inviteLink.select();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#inviteLinkRef').parent()
|
|
|
|
.find('button[value=true]').prop('disabled', false);
|
|
|
|
}
|
|
|
|
}
|