Adapt the client side JS to the new modal dialog for join password

master
Daniel Berteaud 11 years ago
parent 8473b831cf
commit 94f0be24f8
  1. 101
      public/js/vroom.js

@ -288,10 +288,6 @@ 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{
@ -312,6 +308,14 @@ function initVroom(room) {
$('#askForNameLabel').addClass('btn-danger active'); $('#askForNameLabel').addClass('btn-danger active');
$('#askForNameButton').prop('checked', true); $('#askForNameButton').prop('checked', true);
} }
if (data.join_auth == 'yes'){
$('#joinPassLabel').addClass('btn-danger active');
$('#joinPassButton').prop('checked', true);
}
if (data.owner_auth == 'yes'){
$('#persistentLabel').addClass('btn-danger active');
$('#persistentButton').prop('checked', true);
}
} }
}); });
} }
@ -923,9 +927,13 @@ function initVroom(room) {
} }
if (data.payload.action == 'set'){ if (data.payload.action == 'set'){
$.notify(sprintf(locale.PASSWORD_PROTECT_ON_BY_s, stringEscape(peers[data.id].displayName)), 'info'); $.notify(sprintf(locale.PASSWORD_PROTECT_ON_BY_s, stringEscape(peers[data.id].displayName)), 'info');
$('#joinPassLabel').addClass('btn-danger active');
$('#joinPassButton').prop('checked', true);
} }
else{ else{
$.notify(sprintf(locale.PASSWORD_PROTECT_OFF_BY_s, stringEscape(peers[data.id].displayName)), 'info'); $.notify(sprintf(locale.PASSWORD_PROTECT_OFF_BY_s, stringEscape(peers[data.id].displayName)), 'info');
$('#joinPassLabel').removeClass('btn-danger active');
$('#joinPassButton').prop('checked', false);
} }
}); });
webrtc.on('owner_password', function(data){ webrtc.on('owner_password', function(data){
@ -1324,25 +1332,32 @@ function initVroom(room) {
}); });
// Enable the submit button when the corresponding input is filled // Enable the submit button when the corresponding input is filled
$('#joinPass').on('input', function() { $('#joinPassConfirm').on('input', function() {
if ($('#joinPass').val() == ''){ if ($('#joinPass').val() == $('#joinPassConfirm').val() &&
$('#setJoinPassButton').addClass('disabled'); $('#joinPass').val() != ''){
$('#setJoinPassButton').removeClass('disabled');
$('#joinPassConfirm').parent().removeClass('has-error');
} }
else{ else{
$('#setJoinPassButton').removeClass('disabled'); $('#setJoinPassButton').addClass('disabled');
$('#joinPassConfirm').parent().addClass('has-error');
} }
}); });
// Join password protection $('#joinPassButton').change(function(){
$('#joinPassForm').submit(function(event) { var action = ($(this).is(':checked')) ? 'set':'unset';
event.preventDefault(); if (action == 'set'){
var pass = $('#joinPass').val(); $('#joinPassModal').modal('show');
$('#joinPass').val(''); // Uncheck the button now
$('#setJoinPassButton').addClass('disabled'); // so it's not inconsistent if we just close the modal dialog
// submitting the form will recheck it
$('#joinPassButton').prop('checked', false);
$('#joinPassLabel').removeClass('active');
}
else{
$.ajax({ $.ajax({
data: { data: {
action: 'setPassword', action: 'setPassword',
password: pass,
type: 'join', type: 'join',
room: roomName room: roomName
}, },
@ -1351,22 +1366,31 @@ function initVroom(room) {
}, },
success: function(data) { success: function(data) {
$('#joinPass').val(''); $('#joinPass').val('');
$('#joinPassConfirm').val('');
if (data.status == 'success'){ if (data.status == 'success'){
$.notify(data.msg, 'success'); $.notify(data.msg, 'success');
webrtc.sendToAll('password_protect', {action: 'set'}); $('#joinPassLabel').removeClass('btn-danger active');
webrtc.sendToAll('password_protect', {action: 'unset'});
} }
else{ else{
$.notify(data.msg, 'error'); $.notify(data.msg, 'error');
} }
} }
}); });
suspendButton($(this));
}
}); });
// Join password protection
// Remove password protection $('#joinPassForm').submit(function(event) {
$('#removeJoinPassButton').click(function(event) { event.preventDefault();
var pass = $('#joinPass').val();
var pass2 = $('#joinPassConfirm').val();
if (pass == pass2 && pass != ''){
$('#setJoinPassButton').addClass('disabled');
$.ajax({ $.ajax({
data: { data: {
action: 'setPassword', action: 'setPassword',
password: pass,
type: 'join', type: 'join',
room: roomName room: roomName
}, },
@ -1375,16 +1399,23 @@ function initVroom(room) {
}, },
success: function(data) { success: function(data) {
$('#joinPass').val(''); $('#joinPass').val('');
$('#joinPassConfirm').val('');
if (data.status == 'success'){ if (data.status == 'success'){
$.notify(data.msg, 'success'); $.notify(data.msg, 'success');
webrtc.sendToAll('password_protect', {action: 'unset'}); $('#joinPassModal').modal('hide');
$('#joinPassLabel').addClass('btn-danger active');
$('#joinPassButton').prop('checked', true);
webrtc.sendToAll('password_protect', {action: 'set'});
} }
else{ else{
$.notify(data.msg, 'error'); $.notify(data.msg, 'error');
} }
} }
}); });
suspendButton($(this)); }
else{
$('#joinPassConfirm').notify(locale.PASSWORDS_DOES_NOT_MATCH, 'error');
}
}); });
$('#persistentButton').change(function(){ $('#persistentButton').change(function(){
@ -1440,8 +1471,6 @@ function initVroom(room) {
var pass = $('#ownerPass').val(); var pass = $('#ownerPass').val();
var pass2 = $('#ownerPassConfirm').val(); var pass2 = $('#ownerPassConfirm').val();
if (pass == pass2 && pass != ''){ if (pass == pass2 && pass != ''){
$('#ownerPass').val('');
$('#ownerPassConfirm').val('');
$('#setOwnerPassButton').addClass('disabled'); $('#setOwnerPassButton').addClass('disabled');
$.ajax({ $.ajax({
data: { data: {
@ -1456,6 +1485,7 @@ function initVroom(room) {
}, },
success: function(data) { success: function(data) {
$('#ownerPass').val(''); $('#ownerPass').val('');
$('#ownerPassConfirm').val('');
if (data.status == 'success'){ if (data.status == 'success'){
$('#persistentModal').modal('hide'); $('#persistentModal').modal('hide');
$('#persistentLabel').addClass('btn-danger active'); $('#persistentLabel').addClass('btn-danger active');
@ -1474,31 +1504,6 @@ function initVroom(room) {
} }
}); });
// Remove the owner password
$('#removeOwnerPassButton').click(function(event) {
$.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'});
}
else{
$.notify(data.msg, 'error');
}
}
});
suspendButton($(this));
});
// Add an email to be notified when someone joins // Add an email to be notified when someone joins
// First, enable the add button when the input looks like an email address // First, enable the add button when the input looks like an email address
$('#newEmailNotification').on('input', function() { $('#newEmailNotification').on('input', function() {

Loading…
Cancel
Save