Commit | Line | Data |
---|---|---|
03b55607 CW |
1 | (function(angular, $, _) { |
2 | "use strict"; | |
3 | ||
4 | angular.module('crmSearchDisplayList').component('crmSearchDisplayList', { | |
5 | bindings: { | |
6 | apiEntity: '<', | |
7 | apiParams: '<', | |
8 | settings: '<', | |
9 | filters: '<' | |
10 | }, | |
a92d81a1 CW |
11 | require: { |
12 | afFieldset: '?^^afFieldset' | |
13 | }, | |
03b55607 | 14 | templateUrl: '~/crmSearchDisplayList/crmSearchDisplayList.html', |
b1603dbd | 15 | controller: function($scope, crmApi4, searchDisplayUtils) { |
03b55607 CW |
16 | var ts = $scope.ts = CRM.ts(), |
17 | ctrl = this; | |
18 | this.page = 1; | |
19 | ||
20 | this.$onInit = function() { | |
b1603dbd CW |
21 | this.apiParams = _.cloneDeep(this.apiParams); |
22 | this.apiParams.limit = parseInt(this.settings.limit || 0, 10); | |
23 | this.columns = searchDisplayUtils.prepareColumns(this.settings.columns, this.apiParams); | |
c7e96654 | 24 | $scope.displayUtils = searchDisplayUtils; |
a92d81a1 CW |
25 | if (this.afFieldset) { |
26 | $scope.$watch(this.afFieldset.getFieldData, this.getResults, true); | |
27 | } | |
28 | $scope.$watch('$ctrl.filters', ctrl.getResults, true); | |
03b55607 CW |
29 | }; |
30 | ||
a92d81a1 CW |
31 | this.getResults = _.debounce(function() { |
32 | var params = searchDisplayUtils.prepareParams(ctrl); | |
b1603dbd | 33 | |
03b55607 CW |
34 | crmApi4(ctrl.apiEntity, 'get', params).then(function(results) { |
35 | ctrl.results = results; | |
36 | ctrl.rowCount = results.count; | |
37 | }); | |
a92d81a1 | 38 | }, 100); |
03b55607 CW |
39 | |
40 | $scope.formatResult = function(row, col) { | |
41 | var value = row[col.key], | |
b1603dbd | 42 | formatted = searchDisplayUtils.formatSearchValue(row, col, value), |
03b55607 CW |
43 | output = ''; |
44 | if (formatted.length || (col.label && col.forceLabel)) { | |
45 | if (col.label && (formatted.length || col.forceLabel)) { | |
46 | output += '<label>' + _.escape(col.label) + '</label> '; | |
47 | } | |
48 | if (formatted.length) { | |
49 | output += (col.prefix || '') + formatted + (col.suffix || ''); | |
50 | } | |
51 | } | |
52 | return output; | |
53 | }; | |
54 | ||
55 | } | |
56 | }); | |
57 | ||
58 | })(angular, CRM.$, CRM._); |