(fix) Respect order of cards list

pull/91/head
Francis Lachapelle 2015-07-16 16:26:09 -04:00
parent ee0e45cad6
commit 8c8070ff16
1 changed files with 12 additions and 1 deletions

View File

@ -248,7 +248,7 @@
* @param {object} [options] - additional options to the query
* @returns a collection of Cards instances
*/
AddressBook.prototype.$filter = function(search, excludedCards, options) {
AddressBook.prototype.$filter = function(search, options, excludedCards) {
var _this = this,
params = {
search: 'name_or_address',
@ -315,6 +315,17 @@
cards.splice(index, 0, card);
}
});
// Respect the order of the results
_.each(results, function(data, index) {
var oldIndex, removedCards;
if (cards[index].id != data.id) {
oldIndex = _.findIndex(cards, function(card) {
return card.id == data.id;
});
removedCards = cards.splice(oldIndex, 1);
cards.splice(index, 0, removedCards[0]);
}
});
return cards;
});
};