fix(calendar(js)): improve attendees editor when adding new attendees

Fixes #5049
pull/275/head
Francis Lachapelle 2020-06-23 12:02:31 -04:00
parent 4d517e992f
commit 3d3b17adb8
3 changed files with 35 additions and 20 deletions

View File

@ -254,13 +254,14 @@
md-selected-item-change="editor.addAttendee(card, editor.searchText)" md-selected-item-change="editor.addAttendee(card, editor.searchText)"
md-items="card in editor.cardFilter(editor.searchText)" md-items="card in editor.cardFilter(editor.searchText)"
md-item-text="card.empty" md-item-text="card.empty"
md-autoselect="true"
var:md-min-length="minimumSearchLength" var:md-min-length="minimumSearchLength"
md-delay="150" md-delay="150"
md-no-cache="true" md-no-cache="true"
sg-enter="editor.addAttendee(editor.searchText)"> sg-enter="editor.addAttendee(editor.searchText)">
<md-item-template> <md-item-template>
<div class="sg-tile-content"> <div class="sg-tile-content">
<div class="sg-md-subhead" md-highlight-text="editor.searchText" md-highlight-flags="gi">{{ card.$shortFormat(editor.searchText) }}</div> <div class="sg-md-subhead md-block" md-highlight-text="editor.searchText" md-highlight-flags="gi">{{ card.$shortFormat(editor.searchText) }}</div>
<div class="sg-md-body" md-colors="::{color: 'default-background-500'}">{{ card.containername }}</div> <div class="sg-md-body" md-colors="::{color: 'default-background-500'}">{{ card.containername }}</div>
</div> </div>
</md-item-template> </md-item-template>

View File

@ -85,17 +85,17 @@
* @param {object[]} excludedCards - a list of Card objects that must be excluded from the results * @param {object[]} excludedCards - a list of Card objects that must be excluded from the results
* @returns a collection of Cards instances * @returns a collection of Cards instances
*/ */
AddressBook.$filterAll = function(search, options, excludedCards) { AddressBook.$filterAll = function(search, cards, options, excludedCards) {
var params = { search: search }; var params = { search: search };
if (!search) { if (!search) {
// No query specified // No query specified
AddressBook.$cards = []; cards = [];
return AddressBook.$q.when(AddressBook.$cards); return AddressBook.$q.when(cards);
} }
if (angular.isUndefined(AddressBook.$cards)) { if (angular.isUndefined(cards)) {
// First session query // First session query
AddressBook.$cards = []; cards = [];
} }
angular.extend(params, options); angular.extend(params, options);
@ -115,23 +115,23 @@
results = response.contacts; results = response.contacts;
} }
// Remove cards that no longer match the search query // Remove cards that no longer match the search query
for (index = AddressBook.$cards.length - 1; index >= 0; index--) { for (index = cards.length - 1; index >= 0; index--) {
card = AddressBook.$cards[index]; card = cards[index];
if (_.isUndefined(_.find(results, _.bind(compareIds, card)))) { if (_.isUndefined(_.find(results, _.bind(compareIds, card)))) {
AddressBook.$cards.splice(index, 1); cards.splice(index, 1);
} }
} }
// Add new cards matching the search query // Add new cards matching the search query
_.forEach(results, function(data, index) { _.forEach(results, function(data, index) {
if (_.isUndefined(_.find(AddressBook.$cards, _.bind(compareIds, data)))) { if (_.isUndefined(_.find(cards, _.bind(compareIds, data)))) {
var card = new AddressBook.$Card(_.mapKeys(data, function(value, key) { var card = new AddressBook.$Card(_.mapKeys(data, function(value, key) {
return key.toLowerCase(); return key.toLowerCase();
}), search); }), search);
AddressBook.$cards.splice(index, 0, card); cards.splice(index, 0, card);
} }
}); });
AddressBook.$log.debug(AddressBook.$cards); AddressBook.$log.debug(cards);
return AddressBook.$cards; return cards;
}); });
}; };

View File

@ -283,8 +283,7 @@
// Autocomplete cards for attendees // Autocomplete cards for attendees
this.cardFilter = function ($query) { this.cardFilter = function ($query) {
AddressBook.$filterAll($query); return AddressBook.$filterAll($query);
return AddressBook.$cards;
}; };
this.addAttendee = function (card, partial) { this.addAttendee = function (card, partial) {
@ -301,7 +300,21 @@
name = str.replace(new RegExp(" *<?" + email + ">? *"), ''); name = str.replace(new RegExp(" *<?" + email + ">? *"), '');
vm.showAttendeesEditor |= initOrganizer; vm.showAttendeesEditor |= initOrganizer;
vm.searchText = ''; vm.searchText = '';
return new Card({ c_cn: _.trim(name, ' "'), emails: [{ value: email }] }); return vm.cardFilter(email).then(function (cards) {
if (cards.length) {
return cards[0];
} else {
return new Card({ c_cn: _.trim(name, ' "'), emails: [{ value: email }] });
}
}).catch(function (err) {
// Server error
return new Card({ c_cn: _.trim(name, ' "'), emails: [{ value: email }] });
});
}
function addCard(newCard) {
if (!vm.component.$attendees.hasAttendee(newCard))
vm.component.$attendees.add(newCard, options);
} }
if (angular.isString(card)) { if (angular.isString(card)) {
@ -317,18 +330,19 @@
card.charCodeAt(i) == 44 || // , card.charCodeAt(i) == 44 || // ,
card.charCodeAt(i) == 59) && // ; card.charCodeAt(i) == 59) && // ;
emailRE.test(address)) { emailRE.test(address)) {
this.component.$attendees.add(createCard(address), options); createCard(address).then(addCard);
address = ''; address = '';
} }
else { else {
address += card.charAt(i); address += card.charAt(i);
} }
} }
if (address) if (address && emailRE.test(address))
this.component.$attendees.add(createCard(address), options); createCard(address).then(addCard);
} }
else { else {
this.component.$attendees.add(card, options); if (!this.component.$attendees.hasAttendee(card))
this.component.$attendees.add(card, options);
this.showAttendeesEditor |= initOrganizer; this.showAttendeesEditor |= initOrganizer;
} }