Merge pull request #19165 from eileenmcnaughton/pdf
[civicrm-core.git] / ext / search / ang / crmSearchDisplayList / crmSearchDisplayList.component.js
CommitLineData
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 },
11 templateUrl: '~/crmSearchDisplayList/crmSearchDisplayList.html',
b1603dbd 12 controller: function($scope, crmApi4, searchDisplayUtils) {
03b55607
CW
13 var ts = $scope.ts = CRM.ts(),
14 ctrl = this;
15 this.page = 1;
16
17 this.$onInit = function() {
b1603dbd
CW
18 this.apiParams = _.cloneDeep(this.apiParams);
19 this.apiParams.limit = parseInt(this.settings.limit || 0, 10);
20 this.columns = searchDisplayUtils.prepareColumns(this.settings.columns, this.apiParams);
03b55607
CW
21 };
22
23 this.getResults = function() {
b1603dbd
CW
24 var params = searchDisplayUtils.prepareParams(ctrl.apiParams, ctrl.filters, ctrl.settings.pager ? ctrl.page : null);
25
03b55607
CW
26 crmApi4(ctrl.apiEntity, 'get', params).then(function(results) {
27 ctrl.results = results;
28 ctrl.rowCount = results.count;
29 });
30 };
31
32 $scope.$watch('$ctrl.filters', ctrl.getResults, true);
33
34 $scope.formatResult = function(row, col) {
35 var value = row[col.key],
b1603dbd 36 formatted = searchDisplayUtils.formatSearchValue(row, col, value),
03b55607
CW
37 output = '';
38 if (formatted.length || (col.label && col.forceLabel)) {
39 if (col.label && (formatted.length || col.forceLabel)) {
40 output += '<label>' + _.escape(col.label) + '</label> ';
41 }
42 if (formatted.length) {
43 output += (col.prefix || '') + formatted + (col.suffix || '');
44 }
45 }
46 return output;
47 };
48
49 }
50 });
51
52})(angular, CRM.$, CRM._);