parent
4d517e992f
commit
3d3b17adb8
|
@ -254,13 +254,14 @@
|
|||
md-selected-item-change="editor.addAttendee(card, editor.searchText)"
|
||||
md-items="card in editor.cardFilter(editor.searchText)"
|
||||
md-item-text="card.empty"
|
||||
md-autoselect="true"
|
||||
var:md-min-length="minimumSearchLength"
|
||||
md-delay="150"
|
||||
md-no-cache="true"
|
||||
sg-enter="editor.addAttendee(editor.searchText)">
|
||||
<md-item-template>
|
||||
<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>
|
||||
</md-item-template>
|
||||
|
|
|
@ -85,17 +85,17 @@
|
|||
* @param {object[]} excludedCards - a list of Card objects that must be excluded from the results
|
||||
* @returns a collection of Cards instances
|
||||
*/
|
||||
AddressBook.$filterAll = function(search, options, excludedCards) {
|
||||
AddressBook.$filterAll = function(search, cards, options, excludedCards) {
|
||||
var params = { search: search };
|
||||
|
||||
if (!search) {
|
||||
// No query specified
|
||||
AddressBook.$cards = [];
|
||||
return AddressBook.$q.when(AddressBook.$cards);
|
||||
cards = [];
|
||||
return AddressBook.$q.when(cards);
|
||||
}
|
||||
if (angular.isUndefined(AddressBook.$cards)) {
|
||||
if (angular.isUndefined(cards)) {
|
||||
// First session query
|
||||
AddressBook.$cards = [];
|
||||
cards = [];
|
||||
}
|
||||
|
||||
angular.extend(params, options);
|
||||
|
@ -115,23 +115,23 @@
|
|||
results = response.contacts;
|
||||
}
|
||||
// Remove cards that no longer match the search query
|
||||
for (index = AddressBook.$cards.length - 1; index >= 0; index--) {
|
||||
card = AddressBook.$cards[index];
|
||||
for (index = cards.length - 1; index >= 0; index--) {
|
||||
card = cards[index];
|
||||
if (_.isUndefined(_.find(results, _.bind(compareIds, card)))) {
|
||||
AddressBook.$cards.splice(index, 1);
|
||||
cards.splice(index, 1);
|
||||
}
|
||||
}
|
||||
// Add new cards matching the search query
|
||||
_.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) {
|
||||
return key.toLowerCase();
|
||||
}), search);
|
||||
AddressBook.$cards.splice(index, 0, card);
|
||||
cards.splice(index, 0, card);
|
||||
}
|
||||
});
|
||||
AddressBook.$log.debug(AddressBook.$cards);
|
||||
return AddressBook.$cards;
|
||||
AddressBook.$log.debug(cards);
|
||||
return cards;
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -283,8 +283,7 @@
|
|||
|
||||
// Autocomplete cards for attendees
|
||||
this.cardFilter = function ($query) {
|
||||
AddressBook.$filterAll($query);
|
||||
return AddressBook.$cards;
|
||||
return AddressBook.$filterAll($query);
|
||||
};
|
||||
|
||||
this.addAttendee = function (card, partial) {
|
||||
|
@ -301,8 +300,22 @@
|
|||
name = str.replace(new RegExp(" *<?" + email + ">? *"), '');
|
||||
vm.showAttendeesEditor |= initOrganizer;
|
||||
vm.searchText = '';
|
||||
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)) {
|
||||
// User pressed "Enter" in search field, adding a non-matching card
|
||||
|
@ -317,17 +330,18 @@
|
|||
card.charCodeAt(i) == 44 || // ,
|
||||
card.charCodeAt(i) == 59) && // ;
|
||||
emailRE.test(address)) {
|
||||
this.component.$attendees.add(createCard(address), options);
|
||||
createCard(address).then(addCard);
|
||||
address = '';
|
||||
}
|
||||
else {
|
||||
address += card.charAt(i);
|
||||
}
|
||||
}
|
||||
if (address)
|
||||
this.component.$attendees.add(createCard(address), options);
|
||||
if (address && emailRE.test(address))
|
||||
createCard(address).then(addCard);
|
||||
}
|
||||
else {
|
||||
if (!this.component.$attendees.hasAttendee(card))
|
||||
this.component.$attendees.add(card, options);
|
||||
this.showAttendeesEditor |= initOrganizer;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue