Search ext: decouple actions, add searchKit base module, rename searchAdmin module...
[civicrm-core.git] / ext / search / ang / crmSearchActions / saveSmartGroup.directive.js
1 (function(angular, $, _) {
2 "use strict";
3
4 angular.module('crmSearchActions').directive('saveSmartGroup', function() {
5 return {
6 bindToController: {
7 load: '<',
8 entity: '<',
9 params: '<'
10 },
11 restrict: 'A',
12 controller: function ($scope, $element, dialogService) {
13 var ts = $scope.ts = CRM.ts(),
14 ctrl = this;
15
16 $scope.saveGroup = function () {
17 var model = {
18 title: '',
19 description: '',
20 visibility: 'User and User Admin Only',
21 group_type: [],
22 id: ctrl.load ? ctrl.load.id : null,
23 api_entity: ctrl.entity,
24 api_params: _.cloneDeep(angular.extend({}, ctrl.params, {version: 4}))
25 };
26 delete model.api_params.orderBy;
27 if (ctrl.load && ctrl.load.api_params && ctrl.load.api_params.select && ctrl.load.api_params.select[0]) {
28 model.api_params.select.unshift(ctrl.load.api_params.select[0]);
29 }
30 var options = CRM.utils.adjustDialogDefaults({
31 autoOpen: false,
32 title: ts('Save smart group')
33 });
34 dialogService.open('saveSearchDialog', '~/crmSearchActions/saveSmartGroup.html', model, options);
35 };
36 }
37 };
38 });
39
40 })(angular, CRM.$, CRM._);