Adapt JS part to the new modal dialog for persistent rooms

master
Daniel Berteaud 11 years ago
parent 21776096d6
commit 4e5f6b7ffa
  1. 117
      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,41 +1387,91 @@ 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();
$('#ownerPass').val(''); var pass2 = $('#ownerPassConfirm').val();
$('#setOwnerPassButton').addClass('disabled'); if (pass == pass2 && pass != ''){
$.ajax({ $('#ownerPass').val('');
data: { $('#ownerPassConfirm').val('');
action: 'setPassword', $('#setOwnerPassButton').addClass('disabled');
password: pass, $.ajax({
type: 'owner', data: {
room: roomName action: 'setPassword',
}, password: pass,
error: function() { type: 'owner',
$.notify(locale.ERROR_OCCURED, 'error'); room: roomName
}, },
success: function(data) { error: function() {
$('#ownerPass').val(''); $.notify(locale.ERROR_OCCURED, 'error');
if (data.status == 'success'){ $('#persistentLabel').removeClass('btn-danger active');
$.notify(data.msg, 'success'); },
webrtc.sendToAll('owner_password', {action: 'set'}); success: function(data) {
} $('#ownerPass').val('');
else{ if (data.status == 'success'){
$.notify(data.msg, 'error'); $('#persistentModal').modal('hide');
$('#persistentLabel').addClass('btn-danger active');
$('#persistentButton').prop('checked', true);
$.notify(data.msg, 'success');
webrtc.sendToAll('owner_password', {action: 'set'});
}
else{
$.notify(data.msg, 'error');
}
} }
} });
}); }
else{
$('#ownerPassConfirm').notify(locale.PASSWORDS_DOES_NOT_MATCH, 'error');
}
}); });
// Remove the owner password // Remove the owner password

Loading…
Cancel
Save