From d665f4b251c16862ed7c2cfb3eb6e02b7ca8d646 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Fri, 17 Nov 2017 11:34:18 -0500 Subject: [PATCH] (js) Fix parsing of pasted email addresses We are now more clever when parsing the input text to add new attendees to an appointment. --- .../js/Scheduler/ComponentController.js | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/UI/WebServerResources/js/Scheduler/ComponentController.js b/UI/WebServerResources/js/Scheduler/ComponentController.js index 380b881d2..f7210fb82 100644 --- a/UI/WebServerResources/js/Scheduler/ComponentController.js +++ b/UI/WebServerResources/js/Scheduler/ComponentController.js @@ -288,13 +288,40 @@ var initOrganizer = (!vm.component.attendees || vm.component.attendees.length === 0), destinationCalendar = Calendar.$get(vm.component.destinationCalendar), options = initOrganizer? { organizerCalendar: destinationCalendar } : {}; + var emailRE = /([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)/i, + i, address; + + function createCard(str) { + var match = str.match(emailRE), + email = match[0], + name = str.replace(new RegExp(" *? *"), ''); + vm.showAttendeesEditor |= initOrganizer; + vm.searchText = ''; + return new Card({ c_cn: _.trim(name, ' "'), emails: [{ value: email }] }); + } + if (angular.isString(card)) { // User pressed "Enter" in search field, adding a non-matching card - if (card.isValidEmail()) { - vm.component.addAttendee(new Card({ emails: [{ value: card }] }), options); - vm.showAttendeesEditor |= initOrganizer; - vm.searchText = ''; + // Examples that are handled: + // Smith, John + // ; + // foo@bar.com abc@xyz.com + address = ''; + for (i = 0; i < card.length; i++) { + if ((card.charCodeAt(i) == 9 || // tab + card.charCodeAt(i) == 32 || // space + card.charCodeAt(i) == 44 || // , + card.charCodeAt(i) == 59) && // ; + emailRE.test(address)) { + vm.component.addAttendee(createCard(address), options); + address = ''; + } + else { + address += card.charAt(i); + } } + if (address) + vm.component.addAttendee(createCard(address), options); } else { vm.component.addAttendee(card, options); @@ -348,7 +375,7 @@ // Cancelling the creation of a component vm.component = null; } - $mdDialog.cancel(); + $mdDialog.hide(); } function edit(form) {