// Load data for lists
afforms: function(crmApi4) {
return crmApi4('Afform', 'get', {
- select: ['name', 'title', 'type', 'server_route', 'has_local', 'has_base', 'is_dashlet', 'contact_summary:label'],
- orderBy: {title: 'ASC'}
+ select: ['name', 'title', 'type', 'server_route', 'has_local', 'has_base', 'is_dashlet', 'contact_summary:label']
});
}
}
angular.module('afAdmin').controller('afAdminList', function($scope, afforms, crmApi4, crmStatus) {
var ts = $scope.ts = CRM.ts('org.civicrm.afform_admin'),
ctrl = $scope.$ctrl = this;
+ this.sortField = 'title';
+ this.sortDir = false;
$scope.crmUrl = CRM.url;
afforms[afform.type].push(afform);
}, {});
+ // Change sort field/direction when clicking a column header
+ this.sortBy = function(col) {
+ ctrl.sortDir = ctrl.sortField === col ? !ctrl.sortDir : false;
+ ctrl.sortField = col;
+ };
+
$scope.$bindToRoute({
expr: '$ctrl.tab',
param: 'tab',
<table>
<thead>
<tr>
- <th>{{:: ts('Title') }}</th>
- <th>{{:: ts('Name') }}</th>
- <th>{{:: ts('Page') }}</th>
- <th>{{:: ts('Placement') }}</th>
+ <th ng-click="$ctrl.sortBy('title')">
+ <i class="crm-i fa-sort disabled" ng-if="$ctrl.sortField !== 'title'"></i>
+ <i class="crm-i fa-sort-{{ $ctrl.sortDir ? 'asc' : 'desc' }}" ng-if="$ctrl.sortField === 'title'"></i>
+ {{:: ts('Title') }}
+ </th>
+ <th ng-click="$ctrl.sortBy('name')">
+ <i class="crm-i fa-sort disabled" ng-if="$ctrl.sortField !== 'name'"></i>
+ <i class="crm-i fa-sort-{{ $ctrl.sortDir ? 'asc' : 'desc' }}" ng-if="$ctrl.sortField === 'name'"></i>
+ {{:: ts('Name') }}
+ </th>
+ <th ng-click="$ctrl.sortBy('server_route')">
+ <i class="crm-i fa-sort disabled" ng-if="$ctrl.sortField !== 'server_route'"></i>
+ <i class="crm-i fa-sort-{{ $ctrl.sortDir ? 'asc' : 'desc' }}" ng-if="$ctrl.sortField === 'server_route'"></i>
+ {{:: ts('Page') }}
+ </th>
+ <th ng-click="$ctrl.sortBy('placement.length')">
+ <i class="crm-i fa-sort disabled" ng-if="$ctrl.sortField !== 'placement.length'"></i>
+ <i class="crm-i fa-sort-{{ $ctrl.sortDir ? 'asc' : 'desc' }}" ng-if="$ctrl.sortField === 'placement.length'"></i>
+ {{:: ts('Placement') }}
+ </th>
<th></th>
</tr>
</thead>
<tbody>
- <tr ng-repeat="afform in $ctrl.afforms[$ctrl.tab] | filter:$ctrl.searchAfformList">
+ <tr ng-repeat="afform in $ctrl.afforms[$ctrl.tab] | filter:$ctrl.searchAfformList | orderBy:$ctrl.sortField:$ctrl.sortDir">
<td>{{ afform.title }}</td>
<td>
<code>{{ afform.name }}</code>