Merge pull request #19291 from eileenmcnaughton/prof
[civicrm-core.git] / ext / search / ang / crmSearchAdmin / searchList.controller.js
1 (function(angular, $, _) {
2 "use strict";
3
4 angular.module('crmSearchAdmin').controller('searchList', function($scope, savedSearches, crmApi4) {
5 var ts = $scope.ts = CRM.ts(),
6 ctrl = $scope.$ctrl = this;
7 this.savedSearches = savedSearches;
8 this.entityTitles = _.transform(CRM.crmSearchAdmin.schema, function(titles, entity) {
9 titles[entity.name] = entity.title_plural;
10 }, {});
11
12 this.searchPath = window.location.href.split('#')[0].replace('civicrm/admin/search', 'civicrm/search');
13
14 this.encode = function(params) {
15 return encodeURI(angular.toJson(params));
16 };
17
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 };
28 });
29
30 })(angular, CRM.$, CRM._);