Commit | Line | Data |
---|---|---|
03b55607 CW |
1 | (function(angular, $, _) { |
2 | "use strict"; | |
3 | ||
4 | angular.module('crmSearchDisplayList').component('crmSearchDisplayList', { | |
5 | bindings: { | |
406f1014 CW |
6 | apiEntity: '@', |
7 | search: '<', | |
8 | display: '<', | |
03b55607 CW |
9 | apiParams: '<', |
10 | settings: '<', | |
11 | filters: '<' | |
12 | }, | |
a92d81a1 CW |
13 | require: { |
14 | afFieldset: '?^^afFieldset' | |
15 | }, | |
03b55607 | 16 | templateUrl: '~/crmSearchDisplayList/crmSearchDisplayList.html', |
b1603dbd | 17 | controller: function($scope, crmApi4, searchDisplayUtils) { |
67d666c6 | 18 | var ts = $scope.ts = CRM.ts('org.civicrm.search'), |
03b55607 | 19 | ctrl = this; |
406f1014 | 20 | |
03b55607 | 21 | this.page = 1; |
406f1014 | 22 | this.rowCount = null; |
03b55607 CW |
23 | |
24 | this.$onInit = function() { | |
406f1014 | 25 | this.sort = this.settings.sort ? _.cloneDeep(this.settings.sort) : []; |
c7e96654 | 26 | $scope.displayUtils = searchDisplayUtils; |
406f1014 | 27 | |
a92d81a1 | 28 | if (this.afFieldset) { |
b2ee26f0 | 29 | $scope.$watch(this.afFieldset.getFieldData, onChangeFilters, true); |
a92d81a1 | 30 | } |
b2ee26f0 | 31 | $scope.$watch('$ctrl.filters', onChangeFilters, true); |
03b55607 CW |
32 | }; |
33 | ||
a92d81a1 | 34 | this.getResults = _.debounce(function() { |
406f1014 | 35 | searchDisplayUtils.getResults(ctrl); |
a92d81a1 | 36 | }, 100); |
03b55607 | 37 | |
b2ee26f0 CW |
38 | // Refresh current page |
39 | this.refresh = function(row) { | |
40 | searchDisplayUtils.getResults(ctrl); | |
41 | }; | |
42 | ||
43 | function onChangeFilters() { | |
406f1014 CW |
44 | ctrl.page = 1; |
45 | ctrl.rowCount = null; | |
46 | ctrl.getResults(); | |
47 | } | |
48 | ||
daa4e55a CW |
49 | this.formatFieldValue = function(rowData, col) { |
50 | return searchDisplayUtils.formatDisplayValue(rowData, col.key, ctrl.settings.columns); | |
03b55607 CW |
51 | }; |
52 | ||
53 | } | |
54 | }); | |
55 | ||
56 | })(angular, CRM.$, CRM._); |