Commit | Line | Data |
---|---|---|
475029f6 CW |
1 | (function(angular, $, _) { |
2 | "use strict"; | |
3 | ||
493f83d4 | 4 | angular.module('crmSearchAdmin').controller('searchList', function($scope, savedSearches, crmApi4) { |
475029f6 CW |
5 | var ts = $scope.ts = CRM.ts(), |
6 | ctrl = $scope.$ctrl = this; | |
7 | this.savedSearches = savedSearches; | |
4f0729ed | 8 | this.entityTitles = _.transform(CRM.crmSearchAdmin.schema, function(titles, entity) { |
493f83d4 | 9 | titles[entity.name] = entity.title_plural; |
475029f6 | 10 | }, {}); |
44402a2e | 11 | |
7620b30a CW |
12 | this.searchPath = window.location.href.split('#')[0].replace('civicrm/admin/search', 'civicrm/search'); |
13 | ||
b40e49df CW |
14 | this.encode = function(params) { |
15 | return encodeURI(angular.toJson(params)); | |
16 | }; | |
17 | ||
44402a2e CW |
18 | this.deleteSearch = function(search) { |
19 | var index = _.findIndex(savedSearches, {id: search.id}); | |
20 | if (index > -1) { | |
21 | crmApi4([ | |
22 | ['Group', 'delete', {where: [['saved_search_id', '=', search.id]]}], | |
23 | ['SavedSearch', 'delete', {where: [['id', '=', search.id]]}] | |
24 | ]); | |
25 | savedSearches.splice(index, 1); | |
26 | } | |
27 | }; | |
475029f6 CW |
28 | }); |
29 | ||
30 | })(angular, CRM.$, CRM._); |