(feat) sorting capabilities in the addressbook module
parent
e7a73413d5
commit
7c2cb259a2
|
@ -288,6 +288,58 @@
|
|||
<md-option value="organization"><var:string label:value="Organization"/></md-option>
|
||||
</md-select>
|
||||
</div>
|
||||
<div class="sg-toolbar-group-last">
|
||||
<md-menu>
|
||||
<md-button class="sg-icon-button" label:aria-label="Sort"
|
||||
ng-click="$mdOpenMenu()">
|
||||
<md-icon>sort</md-icon>
|
||||
</md-button>
|
||||
<md-menu-content>
|
||||
<md-menu-item>
|
||||
<md-button ng-click="addressbook.sort('c_cn')">
|
||||
<md-icon ng-class="{ 'icon-check': addressbook.sortedBy('c_cn') }">
|
||||
<!-- selected --></md-icon> <var:string label:value="Name"/>
|
||||
</md-button>
|
||||
</md-menu-item>
|
||||
<md-menu-item>
|
||||
<md-button ng-click="addressbook.sort('c_mail')">
|
||||
<md-icon ng-class="{ 'icon-check': addressbook.sortedBy('c_mail') }">
|
||||
<!-- selected --></md-icon> <var:string label:value="Email"/>
|
||||
</md-button>
|
||||
</md-menu-item>
|
||||
<md-menu-item>
|
||||
<md-button ng-click="addressbook.sort('c_screenname')">
|
||||
<md-icon ng-class="{ 'icon-check': addressbook.sortedBy('c_screenname') }">
|
||||
<!-- selected --></md-icon> <var:string
|
||||
label:value="Screen Name"/>
|
||||
</md-button>
|
||||
</md-menu-item>
|
||||
<md-menu-item>
|
||||
<md-button ng-click="addressbook.sort('c_o')">
|
||||
<md-icon ng-class="{ 'icon-check': addressbook.sortedBy('c_o') }">
|
||||
<!-- selected --></md-icon> <var:string
|
||||
label:value="Organization"/>
|
||||
</md-button>
|
||||
</md-menu-item>
|
||||
<md-menu-item>
|
||||
<md-button ng-click="addressbook.sort('c_telephonenumber')">
|
||||
<md-icon ng-class="{ 'icon-check': addressbook.sortedBy('c_telephonenumber') }">
|
||||
<!-- selected --></md-icon> <var:string
|
||||
label:value="Preferred Phone"/>
|
||||
</md-button>
|
||||
</md-menu-item>
|
||||
<md-menu-divider> <!-- divider --></md-menu-divider>
|
||||
<md-menu-item >
|
||||
<md-button ng-click="addressbook.sort()">
|
||||
<md-checkbox
|
||||
ng-model="addressbook.selectedFolder.$query.asc"
|
||||
ng-true-value="0"
|
||||
ng-false-value="1"><var:string label:value="Descending Order"/></md-checkbox>
|
||||
</md-button>
|
||||
</md-menu-item>
|
||||
</md-menu-content>
|
||||
</md-menu>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div layout="row" layout-align="start center" ng-show="addressbook.selectedFolder.$selectedCount() > 0">
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue