Merge pull request #22138 from eileenmcnaughton/cust_edit
[civicrm-core.git] / ext / search_kit / ang / crmSearchAdmin / displays / searchAdminDisplayTable.component.js
1 (function(angular, $, _) {
2 "use strict";
3
4 angular.module('crmSearchAdmin').component('searchAdminDisplayTable', {
5 bindings: {
6 display: '<',
7 apiEntity: '<',
8 apiParams: '<'
9 },
10 require: {
11 parent: '^crmSearchAdminDisplay'
12 },
13 templateUrl: '~/crmSearchAdmin/displays/searchAdminDisplayTable.html',
14 controller: function($scope, searchMeta) {
15 var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'),
16 ctrl = this;
17
18 this.tableClasses = [
19 {name: 'table', label: ts('Row Borders')},
20 {name: 'table-bordered', label: ts('Column Borders')},
21 {name: 'table-striped', label: ts('Even/Odd Stripes')}
22 ];
23
24 // Check if array contains item
25 this.includes = _.includes;
26
27 // Add or remove an item from an array
28 this.toggle = function(collection, item) {
29 if (_.includes(collection, item)) {
30 _.pull(collection, item);
31 } else {
32 collection.push(item);
33 }
34 };
35
36 this.$onInit = function () {
37 if (!ctrl.display.settings) {
38 ctrl.display.settings = _.extend({}, _.cloneDeep(CRM.crmSearchAdmin.defaultDisplay.settings), {columns: null});
39 if (searchMeta.getEntity(ctrl.apiEntity).order_by) {
40 ctrl.display.settings.sort.push([searchMeta.getEntity(ctrl.apiEntity).order_by, 'ASC']);
41 }
42 }
43 // Displays created prior to 5.43 may not have this property
44 ctrl.display.settings.classes = ctrl.display.settings.classes || [];
45 ctrl.parent.initColumns({label: true, sortable: true});
46 };
47
48 }
49 });
50
51 })(angular, CRM.$, CRM._);