Commit | Line | Data |
---|---|---|
44402a2e CW |
1 | (function(angular, $, _) { |
2 | "use strict"; | |
3 | ||
4 | // Declare module | |
5 | angular.module('crmSearchPage', CRM.angRequires('crmSearchPage')) | |
6 | ||
44402a2e | 7 | .config(function($routeProvider) { |
e7515b5b | 8 | // Load & render a SearchDisplay |
5c952e51 | 9 | $routeProvider.when('/display/:savedSearchName/:displayName?', { |
44402a2e | 10 | controller: 'crmSearchPageDisplay', |
e7515b5b | 11 | // Dynamic template generates the directive for each display type |
ecb9d1eb | 12 | template: '<h1 crm-page-title>{{:: $ctrl.display.label }}</h1>\n' + |
11cc6da1 | 13 | '<form ng-include="\'~/crmSearchPage/displayType/\' + $ctrl.display.type + \'.html\'" id="bootstrap-theme"></form>', |
44402a2e CW |
14 | resolve: { |
15 | // Load saved search display | |
5c952e51 | 16 | info: function($route, crmApi4) { |
44402a2e | 17 | var params = $route.current.params; |
5c952e51 CW |
18 | var apiCalls = { |
19 | search: ['SavedSearch', 'get', { | |
20 | select: ['name', 'api_entity'], | |
21 | where: [['name', '=', params.savedSearchName]] | |
22 | }, 0] | |
23 | }; | |
24 | if (params.displayName) { | |
25 | apiCalls.display = ['SearchDisplay', 'get', { | |
26 | where: [['name', '=', params.displayName], ['saved_search_id.name', '=', params.savedSearchName]], | |
27 | }, 0]; | |
28 | } else { | |
29 | apiCalls.display = ['SearchDisplay', 'getDefault', { | |
30 | savedSearch: params.savedSearchName, | |
31 | }, 0]; | |
32 | } | |
33 | return crmApi4(apiCalls); | |
44402a2e CW |
34 | } |
35 | } | |
36 | }); | |
37 | }) | |
38 | ||
39 | // Controller for displaying a search | |
5c952e51 | 40 | .controller('crmSearchPageDisplay', function($scope, $location, info) { |
a4321c5d | 41 | var ctrl = $scope.$ctrl = this; |
5c952e51 CW |
42 | this.display = info.display; |
43 | this.searchName = info.search.name; | |
44 | this.apiEntity = info.search.api_entity; | |
a4321c5d CW |
45 | |
46 | $scope.$watch(function() {return $location.search();}, function(params) { | |
47 | ctrl.filters = params; | |
48 | }); | |
44402a2e CW |
49 | }); |
50 | ||
51 | })(angular, CRM.$, CRM._); |