Fix email input field handling

master
Daniel Berteaud 10 years ago
parent 5d4ef19df2
commit 4e492de55a
  1. 17
      public/js/vroom.js

@ -178,11 +178,10 @@ function maxHeight(){
function addEmailInputField(form, val){ function addEmailInputField(form, val){
var parentEl = $('#' + form), var parentEl = $('#' + form),
currentEntry = parentEl.find('.email-entry:last'), currentEntry = parentEl.find('.email-entry:last'),
newEntry = $(currentEntry.clone()).css('display', 'none').appendTo(parentEl); newEntry = $(currentEntry.clone()).appendTo(parentEl);
newEntry.find('input').val(val); newEntry.find('input').val(val);
newEntry.removeClass('has-error'); newEntry.removeClass('has-error');
adjustAddRemoveEmailButtons(form); adjustAddRemoveEmailButtons(form);
newEntry.show(100);
} }
// Adjust add and remove buttons foir email notifications // Adjust add and remove buttons foir email notifications
function adjustAddRemoveEmailButtons(form){ function adjustAddRemoveEmailButtons(form){
@ -503,9 +502,9 @@ function initAdmin(){
$.notify(locale.ERROR_OCCURRED, 'error'); $.notify(locale.ERROR_OCCURRED, 'error');
}, },
success: function(data){ success: function(data){
// Reset the list of email displayed, so first remove evry input field but the first one // Reset the list of email displayed, so first remove evry input field but the last one
// We keep it so we can clone it again // We keep it so we can clone it again
$('.email-list').find('.email-entry:not(:first)').remove(); $('.email-list').find('.email-entry:not(:last)').remove();
$.each(data.notif, function(index, obj){ $.each(data.notif, function(index, obj){
addEmailInputField('email-list-notification', obj.email); addEmailInputField('email-list-notification', obj.email);
}); });
@ -513,6 +512,9 @@ function initAdmin(){
if (Object.keys(data.notif).length > 0){ if (Object.keys(data.notif).length > 0){
$('.email-list').find('.email-entry:first').remove(); $('.email-list').find('.email-entry:first').remove();
} }
else{
$('.email-list').find('.email-entry:first').find('input:first').val('');
}
adjustAddRemoveEmailButtons(); adjustAddRemoveEmailButtons();
// Update config switches // Update config switches
$('#lockedSet').bootstrapSwitch('state', data.locked == 'yes'); $('#lockedSet').bootstrapSwitch('state', data.locked == 'yes');
@ -649,9 +651,9 @@ function initVroom(room) {
if (data.role == 'owner'){ if (data.role == 'owner'){
$('.unauthEl').hide(500); $('.unauthEl').hide(500);
$('.ownerEl').show(500); $('.ownerEl').show(500);
// Reset the list of email displayed, so first remove evry input field but the first one // Reset the list of email displayed, so first remove evry input field but the last one
// We keep it so we can clone it again // We keep it so we can clone it again
$('.email-list').find('.email-entry:not(:first)').remove(); $('.email-list').find('.email-entry:not(:last)').remove();
$.each(data.notif, function(index, obj){ $.each(data.notif, function(index, obj){
addEmailInputField('email-list-notification', obj.email); addEmailInputField('email-list-notification', obj.email);
}); });
@ -659,6 +661,9 @@ function initVroom(room) {
if (Object.keys(data.notif).length > 0){ if (Object.keys(data.notif).length > 0){
$('.email-list').find('.email-entry:first').remove(); $('.email-list').find('.email-entry:first').remove();
} }
else{
$('.email-list').find('.email-entry:first').find('input:first').val('');
}
adjustAddRemoveEmailButtons(); adjustAddRemoveEmailButtons();
} }
// We're are not owner of the room // We're are not owner of the room

Loading…
Cancel
Save