From dfda2f03f4a28709ff87f59b6a89cc94eb3f0c9a Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Wed, 4 Feb 2015 16:36:11 +0100 Subject: [PATCH] Allow several email addresses for invitations --- lib/Vroom/I18N/en.pm | 2 +- lib/Vroom/I18N/fr.pm | 2 +- public/js/vroom.js | 43 ++++++++++++------ templates/default/configure_modal.html.ep | 2 +- templates/default/invite_modal.html.ep | 14 ++++-- vroom.pl | 75 ++++++++++++++++++------------- 6 files changed, 87 insertions(+), 51 deletions(-) diff --git a/lib/Vroom/I18N/en.pm b/lib/Vroom/I18N/en.pm index 590960c..3cb078f 100644 --- a/lib/Vroom/I18N/en.pm +++ b/lib/Vroom/I18N/en.pm @@ -16,7 +16,7 @@ our %Lexicon = ( "ERROR_NOT_LOGGED_IN" => "Sorry, your not logged in", "JS_REQUIRED" => "VROOM needs javascript to work properly", "EMAIL_INVITATION" => "Video conference invitation", - "INVITE_SENT_TO_s" => "An invitation was sent to %s", + "INVITE_SENT_TO_s" => "An invitation was sent to the following addresses\n%s", "YOU_ARE_INVITED_TO_A_MEETING" => "You are awaited on a video conferecing room. " . "Before joining it, make sure you have all the necessary", "A_MODERN_BROWSER" => "A modern web browser, recent versions of Mozilla Firefox, Google Chrome or Opera will work", diff --git a/lib/Vroom/I18N/fr.pm b/lib/Vroom/I18N/fr.pm index 9cd6dd6..b2857b8 100644 --- a/lib/Vroom/I18N/fr.pm +++ b/lib/Vroom/I18N/fr.pm @@ -40,7 +40,7 @@ our %Lexicon = ( "FROM" => "De la part de", "GIVE_US_YOUR_FEEDBACK" => "Parlez-nous de votre expérience", "YOUR_FEEDBACK_HELPS_US" => "Votre retour d'expérience (bonne ou mauvaise) peut nous aider à améliorer ce service", - "INVITE_SENT_TO_s" => "Une invitation a été envoyée à %s", + "INVITE_SENT_TO_s" => "Une invitation a été envoyée aux adresses suivantes\n%s", "DATA_WIPED" => "Les données ont été supprimées", "ROOM_DATA_WIPED_BY_s" => "Les données du salon (historique du tchat, prise de notes) ont été supprimées par %s", "NOT_ENABLED" => "Cette fonctionalité n'est pas activée", diff --git a/public/js/vroom.js b/public/js/vroom.js index f69a9d3..1751404 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -175,22 +175,22 @@ function maxHeight(){ } // Create a new input field -function addEmailInputField(val){ - var parentEl = $('.email-list'), +function addEmailInputField(form, val){ + var parentEl = $('#' + form), currentEntry = parentEl.find('.email-entry:last'), newEntry = $(currentEntry.clone()).css('display', 'none').appendTo(parentEl); newEntry.find('input').val(val); newEntry.removeClass('has-error'); - adjustAddRemoveEmailButtons(); + adjustAddRemoveEmailButtons(form); newEntry.show(100); } // Adjust add and remove buttons foir email notifications -function adjustAddRemoveEmailButtons(){ - $('.email-list').find('.email-entry:not(:last) .btn-add-email') +function adjustAddRemoveEmailButtons(form){ + $('#' + form).find('.email-entry:not(:last) .btn-add-email') .removeClass('btn-primary').removeClass('btn-add-email') .addClass('btn-danger').addClass('btn-remove-email') .html(''); - $('.email-list').find('.email-entry:last .btn-remove-email') + $('#' + form).find('.email-entry:last .btn-remove-email') .removeClass('btn-danger').removeClass('btn-remove-email') .addClass('btn-primary').addClass('btn-add-email') .html(''); @@ -198,7 +198,7 @@ function adjustAddRemoveEmailButtons(){ // Add emails input fields $(document).on('click','button.btn-add-email',function(e){ e.preventDefault(); - addEmailInputField(''); + addEmailInputField($(this).parents('.email-list:first').attr('id'), ''); }); $(document).on('click','button.btn-remove-email',function(e){ e.preventDefault(); @@ -506,7 +506,7 @@ function initAdmin(){ // We keep it so we can clone it again $('.email-list').find('.email-entry:not(:first)').remove(); $.each(data.notif, function(index, obj){ - addEmailInputField(obj.email); + addEmailInputField('email-list-notification', obj.email); }); // Now, remove the first one if the list is not empty if (Object.keys(data.notif).length > 0){ @@ -652,7 +652,7 @@ function initVroom(room) { // We keep it so we can clone it again $('.email-list').find('.email-entry:not(:first)').remove(); $.each(data.notif, function(index, obj){ - addEmailInputField(obj.email); + addEmailInputField('email-list-notification', obj.email); }); // Now, remove the first one if the list is not empty if (Object.keys(data.notif).length > 0){ @@ -1597,20 +1597,35 @@ function initVroom(room) { // Handle Email Invitation $('#inviteEmail').submit(function(event) { event.preventDefault(); - var rcpt = $('#recipient').val(); + var rcpts = [], message = $('#message').val(); + $('input[name="invitation-recipients[]"]').each(function(){ + rcpts.push($(this).val()); + }); // Simple email address verification // not fullproof, but email validation is a real nightmare - if (!rcpt.match(/\S+@\S+\.\S+/)){ - $.notify(locale.ERROR_MAIL_INVALID, 'error'); - return; + var validEmail = true; + $('.email-list').find('input').each(function(index, input){ + if (!$(input).val().match(/\S+@\S+\.\S+/) && $(input).val() !== ''){ + $(input).parent().addClass('has-error'); + //$(input).parent().notify(locale.ERROR_MAIL_INVALID, 'error'); + validEmail = false; + // Break the each loop + return false; + } + else{ + $(input).parent().removeClass('has-error'); + } + }); + if (!validEmail){ + return false; } $.ajax({ data: { req: JSON.stringify({ action: 'invite_email', param: { - rcpt: rcpt, + rcpts: rcpts, message: message, room: roomName } diff --git a/templates/default/configure_modal.html.ep b/templates/default/configure_modal.html.ep index ab831aa..1a40d77 100644 --- a/templates/default/configure_modal.html.ep +++ b/templates/default/configure_modal.html.ep @@ -85,7 +85,7 @@ -
+