Adapt JS part to the new modal dialog for persistent rooms

master
Daniel Berteaud 11 years ago
parent 21776096d6
commit 4e5f6b7ffa
  1. 71
      public/js/vroom.js

@ -58,7 +58,8 @@ var locale = {
REMOVE_THIS_ADDRESS: '', REMOVE_THIS_ADDRESS: '',
DISPLAY_NAME_REQUIRED: '', DISPLAY_NAME_REQUIRED: '',
A_ROOM_ADMIN: '', A_ROOM_ADMIN: '',
A_PARTICIPANT: '' A_PARTICIPANT: '',
PASSWORDS_DOES_NOT_MATCH: ''
}; };
// Localize the strings we need // Localize the strings we need
@ -287,6 +288,10 @@ function initVroom(room) {
$.each(notif.email, function(index, val){ $.each(notif.email, function(index, val){
addNotifiedEmail(val); addNotifiedEmail(val);
}); });
if (data.owner_auth == 'yes'){
$('#persistentLabel').addClass('btn-danger active');
$('#persistentButton').prop('checked', true);
}
} }
// We're are not owner of the room // We're are not owner of the room
else{ else{
@ -930,9 +935,13 @@ function initVroom(room) {
if (peers.local.role == 'owner'){ if (peers.local.role == 'owner'){
if (data.payload.action == 'set'){ if (data.payload.action == 'set'){
$.notify(sprintf(locale.OWNER_PASSWORD_CHANGED_BY_s, stringEscape(peers[data.id].displayName)), 'warn'); $.notify(sprintf(locale.OWNER_PASSWORD_CHANGED_BY_s, stringEscape(peers[data.id].displayName)), 'warn');
$('#persistentLabel').addClass('btn-danger active');
$('#persistentButton').prop('checked', true);
} }
else{ else{
$.notify(sprintf(locale.OWNER_PASSWORD_REMOVED_BY_s, stringEscape(peers[data.id].displayName)), 'warn'); $.notify(sprintf(locale.OWNER_PASSWORD_REMOVED_BY_s, stringEscape(peers[data.id].displayName)), 'warn');
$('#persistentLabel').removeClass('btn-danger active');
$('#persistentButton').prop('checked', false);
} }
} }
else{ else{
@ -1378,19 +1387,61 @@ function initVroom(room) {
suspendButton($(this)); suspendButton($(this));
}); });
// Set owner password $('#persistentButton').change(function(){
$('#ownerPass').on('input', function() { var action = ($(this).is(':checked')) ? 'set':'unset';
if ($('#ownerPass').val() == ''){ if (action == 'set'){
$('#setOwnerPassButton').addClass('disabled'); $('#persistentModal').modal('show');
// Uncheck the button now
// so it's not inconsistent if we just close the modal dialog
// submitting the form will recheck it
$('#persistentButton').prop('checked', false);
$('#persistentLabel').removeClass('active');
} }
else{ else{
$.ajax({
data: {
action: 'setPassword',
type: 'owner',
room: roomName
},
error: function() {
$.notify(locale.ERROR_OCCURED, 'error');
},
success: function(data) {
$('#ownerPass').val('');
if (data.status == 'success'){
$.notify(data.msg, 'success');
webrtc.sendToAll('owner_password', {action: 'remove'});
$('#persistentLabel').removeClass('btn-danger active');
}
else{
$.notify(data.msg, 'error');
}
}
});
suspendButton($(this));
}
});
// Set owner password
$('#ownerPassConfirm').on('input', function() {
if ($('#ownerPassConfirm').val() == $('#ownerPass').val() &&
$('#ownerPassConfirm').val() != ''){
$('#setOwnerPassButton').removeClass('disabled'); $('#setOwnerPassButton').removeClass('disabled');
$('#ownerPassConfirm').parent().removeClass('has-error');
}
else{
$('#setOwnerPassButton').addClass('disabled');
$('#ownerPassConfirm').parent().addClass('has-error');
} }
}); });
$('#ownerPassForm').submit(function(event) { $('#persistentForm').submit(function(event) {
event.preventDefault(); event.preventDefault();
var pass = $('#ownerPass').val(); var pass = $('#ownerPass').val();
var pass2 = $('#ownerPassConfirm').val();
if (pass == pass2 && pass != ''){
$('#ownerPass').val(''); $('#ownerPass').val('');
$('#ownerPassConfirm').val('');
$('#setOwnerPassButton').addClass('disabled'); $('#setOwnerPassButton').addClass('disabled');
$.ajax({ $.ajax({
data: { data: {
@ -1401,10 +1452,14 @@ function initVroom(room) {
}, },
error: function() { error: function() {
$.notify(locale.ERROR_OCCURED, 'error'); $.notify(locale.ERROR_OCCURED, 'error');
$('#persistentLabel').removeClass('btn-danger active');
}, },
success: function(data) { success: function(data) {
$('#ownerPass').val(''); $('#ownerPass').val('');
if (data.status == 'success'){ if (data.status == 'success'){
$('#persistentModal').modal('hide');
$('#persistentLabel').addClass('btn-danger active');
$('#persistentButton').prop('checked', true);
$.notify(data.msg, 'success'); $.notify(data.msg, 'success');
webrtc.sendToAll('owner_password', {action: 'set'}); webrtc.sendToAll('owner_password', {action: 'set'});
} }
@ -1413,6 +1468,10 @@ function initVroom(room) {
} }
} }
}); });
}
else{
$('#ownerPassConfirm').notify(locale.PASSWORDS_DOES_NOT_MATCH, 'error');
}
}); });
// Remove the owner password // Remove the owner password

Loading…
Cancel
Save