fix(calendar(js)): add attendee from search field when saving

Fixes #5185
pull/289/head
Francis Lachapelle 2020-10-15 17:43:17 -04:00
parent 5d1ac9db5d
commit 74acab0738
3 changed files with 34 additions and 26 deletions

View File

@ -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
@ -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,
@ -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;
});
@ -205,6 +205,8 @@
}
}
}
return promise;
};
/**

View File

@ -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

View File

@ -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 () {
@ -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;
@ -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)) {
@ -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() {
@ -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) {