1 (function(angular
, $, _
) {
4 // Trait shared by any search display controllers which allow sorting
5 angular
.module('crmSearchDisplay').factory('searchDisplaySortableTrait', function() {
6 var ts
= CRM
.ts('org.civicrm.search_kit');
8 // Trait properties get mixed into display controller using angular.extend()
13 getSort: function(col
) {
14 var dir
= _
.reduce(this.sort
, function(dir
, item
) {
15 return item
[0] === col
.key
? item
[1] : dir
;
18 return 'fa-sort-' + dir
.toLowerCase();
20 return 'fa-sort disabled';
23 setSort: function(col
, $event
) {
24 if (col
.type
!== 'field') {
27 var dir
= this.getSort(col
) === 'fa-sort-asc' ? 'DESC' : 'ASC';
28 if (!$event
.shiftKey
|| !this.sort
) {
31 var index
= _
.findIndex(this.sort
, [col
.key
]);
33 this.sort
[index
][1] = dir
;
35 this.sort
.push([col
.key
, dir
]);
43 })(angular
, CRM
.$, CRM
._
);