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 |
44402a2e CW |
9 | $routeProvider.when('/display/:savedSearchName/:displayName', { |
10 | controller: 'crmSearchPageDisplay', | |
e7515b5b | 11 | // Dynamic template generates the directive for each display type |
ecb9d1eb CW |
12 | template: '<h1 crm-page-title>{{:: $ctrl.display.label }}</h1>\n' + |
13 | '<div ng-include="\'~/crmSearchPage/displayType/\' + $ctrl.display.type + \'.html\'" id="bootstrap-theme"></div>', | |
44402a2e CW |
14 | resolve: { |
15 | // Load saved search display | |
16 | display: function($route, crmApi4) { | |
17 | var params = $route.current.params; | |
18 | return crmApi4('SearchDisplay', 'get', { | |
f99cfe44 CW |
19 | where: [['name', '=', params.displayName], ['saved_search_id.name', '=', params.savedSearchName]], |
20 | select: ['*', 'saved_search_id.api_entity', 'saved_search_id.name'] | |
44402a2e CW |
21 | }, 0); |
22 | } | |
23 | } | |
24 | }); | |
25 | }) | |
26 | ||
27 | // Controller for displaying a search | |
a4321c5d CW |
28 | .controller('crmSearchPageDisplay', function($scope, $location, display) { |
29 | var ctrl = $scope.$ctrl = this; | |
44402a2e | 30 | this.display = display; |
f99cfe44 CW |
31 | this.searchName = display['saved_search_id.name']; |
32 | this.apiEntity = display['saved_search_id.api_entity']; | |
a4321c5d CW |
33 | |
34 | $scope.$watch(function() {return $location.search();}, function(params) { | |
35 | ctrl.filters = params; | |
36 | }); | |
44402a2e CW |
37 | }); |
38 | ||
39 | })(angular, CRM.$, CRM._); |