Skip to content

Commit

Permalink
fix(calendar(js)): add attendee from search field when saving
Browse files Browse the repository at this point in the history
Fixes #5185
  • Loading branch information
cgx committed Oct 15, 2020
1 parent 5d1ac9d commit 74acab0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
8 changes: 5 additions & 3 deletions UI/WebServerResources/js/Scheduler/Attendees.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
* @param {Object} card - an Card object instance to be added to the attendees list
*/
Attendees.prototype.add = function(card, options) {
var _this = this, attendee, list, url, params;
var _this = this, attendee, list, url, params, promise = Attendees.$q.when();
if (card) {
if (!this.component.attendees || (options && options.organizerCalendar)) {
// No attendee yet; initialize the organizer
Expand All @@ -145,7 +145,7 @@
if (card.$isList({expandable: true})) {
// Decompose list members
list = Attendees.$Card.$find(card.container, card.c_name);
list.$id().then(function(listId) {
promise = list.$id().then(function(listId) {
_.forEach(list.refs, function(ref) {
attendee = {
name: ref.c_cn,
Expand Down Expand Up @@ -189,7 +189,7 @@
})) {
if (card.$isList() && Attendees.$Preferences.defaults.SOGoLDAPGroupExpansionEnabled) {
// LDAP list -- preload members
card.$members().then(function(members) {
promise = card.$members().then(function(members) {
attendee.members = members;
attendee.isExpandableGroup = true;
});
Expand All @@ -205,6 +205,8 @@
}
}
}

return promise;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion UI/WebServerResources/js/Scheduler/Component.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@

return new Date(parseInt(date[0]), parseInt(date[1]) - 1, parseInt(date[2]),
parseInt(time[0]), parseInt(time[1]), 0, 0);
};
};

/**
* @function init
Expand Down
50 changes: 28 additions & 22 deletions UI/WebServerResources/js/Scheduler/ComponentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@
/**
* @ngInject
*/
ComponentEditorController.$inject = ['$rootScope', '$scope', '$log', '$timeout', '$window', '$element', '$mdDialog', '$mdToast', 'sgFocus', 'User', 'CalendarSettings', 'Calendar', 'Component', 'Attendees', 'AddressBook', 'Card', 'Preferences', 'stateComponent'];
function ComponentEditorController($rootScope, $scope, $log, $timeout, $window, $element, $mdDialog, $mdToast, focus, User, CalendarSettings, Calendar, Component, Attendees, AddressBook, Card, Preferences, stateComponent) {
ComponentEditorController.$inject = ['$rootScope', '$scope', '$q', '$log', '$timeout', '$window', '$element', '$mdDialog', '$mdToast', 'sgFocus', 'User', 'CalendarSettings', 'Calendar', 'Component', 'Attendees', 'AddressBook', 'Card', 'Preferences', 'stateComponent'];
function ComponentEditorController($rootScope, $scope, $q, $log, $timeout, $window, $element, $mdDialog, $mdToast, focus, User, CalendarSettings, Calendar, Component, Attendees, AddressBook, Card, Preferences, stateComponent) {
var vm = this, component, oldStartDate, oldEndDate, oldDueDate, dayStartTime, dayEndTime;

this.$onInit = function () {
Expand Down Expand Up @@ -291,7 +291,8 @@
this.addAttendee = function (card, partial) {
var initOrganizer = (!this.component.attendees || this.component.attendees.length === 0),
destinationCalendar = Calendar.$get(this.component.destinationCalendar),
options = initOrganizer? { organizerCalendar: destinationCalendar } : {};
options = initOrganizer? { organizerCalendar: destinationCalendar } : {},
promises = [];
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;
if (partial) options.partial = partial;
Expand All @@ -316,7 +317,7 @@

function addCard(newCard) {
if (!vm.component.$attendees.hasAttendee(newCard))
vm.component.$attendees.add(newCard, options);
return vm.component.$attendees.add(newCard, options);
}

if (angular.isString(card)) {
Expand All @@ -332,23 +333,26 @@
card.charCodeAt(i) == 44 || // ,
card.charCodeAt(i) == 59) && // ;
emailRE.test(address)) {
createCard(address).then(addCard);
promises.push(createCard(address).then(addCard));
address = '';
}
else {
address += card.charAt(i);
}
}
if (address && emailRE.test(address))
createCard(address).then(addCard);
if (address && emailRE.test(address)) {
promises.push(createCard(address).then(addCard));
}
}
else if (angular.isDefined(card)) {
if (!this.component.$attendees.hasAttendee(card))
this.component.$attendees.add(card, options);
promises.push(this.component.$attendees.add(card, options));
this.showAttendeesEditor |= initOrganizer;
}

$timeout(scrollToStart);

return $q.all(promises);
};

function scrollToStart() {
Expand Down Expand Up @@ -466,20 +470,22 @@
this.adjustStartTime();
this.adjustEndTime();
this.changeAlarmRelation(form);
if (form.$valid) {
this.component.$save(options)
.then(function(data) {
$rootScope.$emit('calendars:list');
Preferences.getAlarms();
$mdDialog.hide();
}, function(response) {
if (response.status == CalendarSettings.ConflictHTTPErrorCode &&
_.isObject(response.data.message))
vm.attendeeConflictError = response.data.message;
else
vm.edit(form);
});
}
this.addAttendee(this.searchText).then(function () {
if (form.$valid) {
vm.component.$save(options)
.then(function(data) {
$rootScope.$emit('calendars:list');
Preferences.getAlarms();
$mdDialog.hide();
}, function(response) {
if (response.status == CalendarSettings.ConflictHTTPErrorCode &&
_.isObject(response.data.message))
vm.attendeeConflictError = response.data.message;
else
vm.edit(form);
});
}
});
};

this.reset = function (form) {
Expand Down

0 comments on commit 74acab0

Please sign in to comment.