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

master
Daniel Berteaud 11 years ago
parent 8473b831cf
commit 94f0be24f8
  1. 171
      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,67 +1332,90 @@ 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');
} }
}); });
$('#joinPassButton').change(function(){
var action = ($(this).is(':checked')) ? 'set':'unset';
if (action == 'set'){
$('#joinPassModal').modal('show');
// Uncheck the button now
// 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({
data: {
action: 'setPassword',
type: 'join',
room: roomName
},
error: function() {
$.notify(locale.ERROR_OCCURED, 'error');
},
success: function(data) {
$('#joinPass').val('');
$('#joinPassConfirm').val('');
if (data.status == 'success'){
$.notify(data.msg, 'success');
$('#joinPassLabel').removeClass('btn-danger active');
webrtc.sendToAll('password_protect', {action: 'unset'});
}
else{
$.notify(data.msg, 'error');
}
}
});
suspendButton($(this));
}
});
// Join password protection // Join password protection
$('#joinPassForm').submit(function(event) { $('#joinPassForm').submit(function(event) {
event.preventDefault(); event.preventDefault();
var pass = $('#joinPass').val(); var pass = $('#joinPass').val();
$('#joinPass').val(''); var pass2 = $('#joinPassConfirm').val();
$('#setJoinPassButton').addClass('disabled'); if (pass == pass2 && pass != ''){
$.ajax({ $('#setJoinPassButton').addClass('disabled');
data: { $.ajax({
action: 'setPassword', data: {
password: pass, action: 'setPassword',
type: 'join', password: pass,
room: roomName type: 'join',
}, room: roomName
error: function() { },
$.notify(locale.ERROR_OCCURED, 'error'); error: function() {
}, $.notify(locale.ERROR_OCCURED, 'error');
success: function(data) { },
$('#joinPass').val(''); success: function(data) {
if (data.status == 'success'){ $('#joinPass').val('');
$.notify(data.msg, 'success'); $('#joinPassConfirm').val('');
webrtc.sendToAll('password_protect', {action: 'set'}); if (data.status == 'success'){
} $.notify(data.msg, 'success');
else{ $('#joinPassModal').modal('hide');
$.notify(data.msg, 'error'); $('#joinPassLabel').addClass('btn-danger active');
} $('#joinPassButton').prop('checked', true);
} webrtc.sendToAll('password_protect', {action: 'set'});
}); }
}); else{
$.notify(data.msg, 'error');
// Remove password protection }
$('#removeJoinPassButton').click(function(event) {
$.ajax({
data: {
action: 'setPassword',
type: 'join',
room: roomName
},
error: function() {
$.notify(locale.ERROR_OCCURED, 'error');
},
success: function(data) {
$('#joinPass').val('');
if (data.status == 'success'){
$.notify(data.msg, 'success');
webrtc.sendToAll('password_protect', {action: 'unset'});
}
else{
$.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