Merge pull request #16879 from civicrm/5.24
[civicrm-core.git] / ang / api4Explorer / Explorer.js
index b589bdaaf3e420d137891fb8fa411281d5e3d012..09db7d1d02a2023fee9ea88a87af0f7e462f5bf5 100644 (file)
@@ -32,7 +32,8 @@
     $scope.index = '';
     $scope.selectedTab = {result: 'result', code: 'php'};
     $scope.perm = {
-      accessDebugOutput: CRM.checkPerm('access debug output')
+      accessDebugOutput: CRM.checkPerm('access debug output'),
+      editGroups: CRM.checkPerm('edit groups')
     };
     marked.setOptions({highlight: prettyPrintOne});
     var getMetaParams = {},
     $scope.save = function() {
       var model = {
         title: '',
+        description: '',
+        visibility: 'User and User Admin Only',
+        group_type: [],
         id: null,
         entity: $scope.entity,
         params: JSON.parse(angular.toJson($scope.params))
   angular.module('api4Explorer').controller('SaveSearchCtrl', function($scope, crmApi4, dialogService) {
     var ts = $scope.ts = CRM.ts(),
       model = $scope.model;
+    $scope.groupEntityRefParams = {
+      entity: 'Group',
+      api: {
+        params: {is_hidden: 0, is_active: 1, 'saved_search_id.api_entity': model.entity},
+        extra: ['saved_search_id', 'description', 'visibility', 'group_type']
+      },
+      select: {
+        allowClear: true,
+        minimumInputLength: 0,
+        placeholder: ts('Select existing group')
+      }
+    };
+    if (!CRM.checkPerm('administer reserved groups')) {
+      $scope.groupEntityRefParams.api.params.is_reserved = 0;
+    }
+    $scope.perm = {
+      administerReservedGroups: CRM.checkPerm('administer reserved groups')
+    };
+    $scope.options = CRM.vars.api4.groupOptions;
     $scope.$watch('model.id', function(id) {
       if (id) {
-        model.description = $('#api-save-search-select-group').select2('data').extra.description;
+        _.assign(model, $('#api-save-search-select-group').select2('data').extra);
       }
     });
     $scope.cancel = function() {
       $('.ui-dialog:visible').block();
       var group = model.id ? {id: model.id} : {title: model.title};
       group.description = model.description;
+      group.visibility = model.visibility;
+      group.group_type = model.group_type;
       group.saved_search_id = '$id';
       var savedSearch = {
         api_entity: model.entity,
         api_params: model.params
       };
       if (group.id) {
-        savedSearch.id = $('#api-save-search-select-group').select2('data').extra.saved_search_id;
+        savedSearch.id = model.saved_search_id;
       }
       crmApi4('SavedSearch', 'save', {records: [savedSearch], chain: {group: ['Group', 'save', {'records': [group]}]}})
         .then(function(result) {