1 (function(angular
, $, _
) {
4 // Specialized searchDisplay, only used by Admins
5 angular
.module('crmSearchAdmin').component('crmSearchAdminResultsTable', {
10 crmSearchAdmin
: '^crmSearchAdmin'
12 templateUrl
: '~/crmSearchAdmin/resultsTable/crmSearchAdminResultsTable.html',
13 controller: function($scope
, $element
, searchMeta
, searchDisplayBaseTrait
, searchDisplayTasksTrait
, searchDisplaySortableTrait
) {
14 var ts
= $scope
.ts
= CRM
.ts('org.civicrm.search_kit'),
15 // Mix in traits to this controller
16 ctrl
= angular
.extend(this, searchDisplayBaseTrait
, searchDisplayTasksTrait
, searchDisplaySortableTrait
);
18 function buildSettings() {
19 ctrl
.apiEntity
= ctrl
.search
.api_entity
;
20 ctrl
.settings
= _
.cloneDeep(CRM
.crmSearchAdmin
.defaultDisplay
.settings
);
21 ctrl
.settings
.button
= ts('Search');
22 // The default-display settings contain just one column (the last one, with the links menu)
23 ctrl
.settings
.columns
= _
.transform(ctrl
.search
.api_params
.select
, function(columns
, fieldExpr
) {
24 columns
.push(searchMeta
.fieldToColumn(fieldExpr
, {label
: true, sortable
: true}));
25 }).concat(ctrl
.settings
.columns
);
27 apiParams
: JSON
.stringify(ctrl
.search
.api_params
, null, 2)
34 this.$onInit = function() {
36 this.initializeDisplay($scope
, $element
);
37 $scope
.$watch('$ctrl.search.api_params', buildSettings
, true);
40 // Add callbacks for pre & post run
41 this.onPreRun
.push(function(apiParams
) {
42 apiParams
.debug
= true;
45 this.onPostRun
.push(function(result
) {
46 ctrl
.debug
= _
.extend(_
.pick(ctrl
.debug
, 'apiParams'), result
.debug
);
49 $scope
.sortableColumnOptions
= {
51 handle
: '.crm-draggable',
52 update: function(e
, ui
) {
53 // Don't allow items to be moved to position 0 if locked
54 if (!ui
.item
.sortable
.dropindex
&& ctrl
.crmSearchAdmin
.groupExists
) {
55 ui
.item
.sortable
.cancel();
57 // Function selectors use `ng-repeat` with `track by $index` so must be refreshed when rearranging the array
58 ctrl
.crmSearchAdmin
.hideFuncitons();
62 $scope
.fieldsForSelect = function() {
63 return {results
: ctrl
.crmSearchAdmin
.getAllFields(':label', ['Field', 'Custom', 'Extra', 'Pseudo'], function(key
) {
64 return _
.contains(ctrl
.search
.api_params
.select
, key
);
69 $scope
.addColumn = function(col
) {
70 ctrl
.crmSearchAdmin
.addParam('select', col
);
73 $scope
.removeColumn = function(index
) {
74 ctrl
.crmSearchAdmin
.clearParam('select', index
);
80 })(angular
, CRM
.$, CRM
._
);