From 7c2cb259a2fea6e2d18610fb6b7568c96acde9eb Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Mon, 20 Jul 2015 14:24:36 -0400 Subject: [PATCH] (feat) sorting capabilities in the addressbook module --- .../ContactsUI/UIxContactFoldersView.wox | 52 +++++++++++++++++++ .../js/Contacts/AddressBook.service.js | 19 +++---- .../js/Contacts/AddressBookController.js | 11 ++++ 3 files changed, 70 insertions(+), 12 deletions(-) diff --git a/UI/Templates/ContactsUI/UIxContactFoldersView.wox b/UI/Templates/ContactsUI/UIxContactFoldersView.wox index d5e3aa355..a2296cedd 100644 --- a/UI/Templates/ContactsUI/UIxContactFoldersView.wox +++ b/UI/Templates/ContactsUI/UIxContactFoldersView.wox @@ -288,6 +288,58 @@ +
+ + + sort + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/UI/WebServerResources/js/Contacts/AddressBook.service.js b/UI/WebServerResources/js/Contacts/AddressBook.service.js index 112833b44..3348dc88d 100644 --- a/UI/WebServerResources/js/Contacts/AddressBook.service.js +++ b/UI/WebServerResources/js/Contacts/AddressBook.service.js @@ -163,7 +163,7 @@ // Add 'isOwned' and 'isSubscription' attributes based on active user (TODO: add it server-side?) this.isOwned = AddressBook.activeUser.isSuperUser || this.owner == AddressBook.activeUser.login; this.isSubscription = !this.isRemote && this.owner != AddressBook.activeUser.login; - this.$query = undefined; + this.$query = {search: 'name_or_address', value: '', sort: 'c_cn', asc: 'true'}; }; /** @@ -249,16 +249,10 @@ * @returns a collection of Cards instances */ AddressBook.prototype.$filter = function(search, options, excludedCards) { - var _this = this, - params = { - search: 'name_or_address', - value: search, - sort: 'c_cn', - asc: 'true' - }; + var _this = this; if (options) { - angular.extend(params, options); + angular.extend(this.$query, options); if (options.dry) { if (!search) { @@ -266,16 +260,17 @@ this.$cards = []; return AddressBook.$q.when(this.$cards); } - else if (this.$query == search) { + else if (this.$query.value == search) { // Query hasn't changed return AddressBook.$q.when(this.$cards); } } } - this.$query = search; + + this.$query.value = search; return this.$id().then(function(addressbookId) { - return AddressBook.$$resource.fetch(addressbookId, 'view', params); + return AddressBook.$$resource.fetch(addressbookId, 'view', _this.$query); }).then(function(response) { var results, cards, card, index; if (options && options.dry) { diff --git a/UI/WebServerResources/js/Contacts/AddressBookController.js b/UI/WebServerResources/js/Contacts/AddressBookController.js index c1bb09bf0..359b2a158 100644 --- a/UI/WebServerResources/js/Contacts/AddressBookController.js +++ b/UI/WebServerResources/js/Contacts/AddressBookController.js @@ -18,6 +18,9 @@ vm.notSelectedComponent = notSelectedComponent; vm.unselectCards = unselectCards; vm.confirmDeleteSelectedCards = confirmDeleteSelectedCards; + vm.sort = sort; + vm.sortedBy = sortedBy; + function selectCard(card) { $state.go('app.addressbook.card.view', {addressbookId: stateAddressbook.id, cardId: card.id}); @@ -80,6 +83,14 @@ // Delete failed }); } + + function sort(field) { + vm.selectedFolder.$filter('', { sort: field }); + } + + function sortedBy(field) { + return vm.selectedFolder.$query.sort == field; + } } angular