1 (function(angular
, $, _
) {
4 angular
.module('search').controller('SaveSmartGroup', function ($scope
, crmApi4
, dialogService
) {
5 var ts
= $scope
.ts
= CRM
.ts(),
7 $scope
.groupEntityRefParams
= {
10 params
: {is_hidden
: 0, is_active
: 1, 'saved_search_id.api_entity': model
.entity
},
11 extra
: ['saved_search_id', 'description', 'visibility', 'group_type']
15 minimumInputLength
: 0,
16 placeholder
: ts('Select existing group')
19 if (!CRM
.checkPerm('administer reserved groups')) {
20 $scope
.groupEntityRefParams
.api
.params
.is_reserved
= 0;
23 administerReservedGroups
: CRM
.checkPerm('administer reserved groups')
25 $scope
.groupFields
= _
.indexBy(_
.find(CRM
.vars
.search
.schema
, {name
: 'Group'}).fields
, 'name');
26 $scope
.$watch('model.id', function (id
) {
28 _
.assign(model
, $('#api-save-search-select-group').select2('data').extra
);
31 $scope
.cancel = function () {
32 dialogService
.cancel('saveSearchDialog');
34 $scope
.save = function () {
35 $('.ui-dialog:visible').block();
36 var group
= model
.id
? {id
: model
.id
} : {title
: model
.title
};
37 group
.description
= model
.description
;
38 group
.visibility
= model
.visibility
;
39 group
.group_type
= model
.group_type
;
40 group
.saved_search_id
= '$id';
42 api_entity
: model
.entity
,
43 api_params
: model
.params
46 savedSearch
.id
= model
.saved_search_id
;
48 crmApi4('SavedSearch', 'save', {records
: [savedSearch
], chain
: {group
: ['Group', 'save', {'records': [group
]}]}})
49 .then(function (result
) {
50 dialogService
.close('saveSearchDialog', result
[0]);
54 })(angular
, CRM
.$, CRM
._
);