+ template: '<div id="bootstrap-theme" class="crm-search"><crm-search ng-if="$ctrl.mode === \'create\'" entity="$ctrl.entity" load=":: $ctrl.savedSearch"></crm-search></div>',
+ reloadOnSearch: false,
+ resolve: {
+ // For paths like /load/Group/MySmartGroup, load the group, stash it in the savedSearch variable, and then redirect
+ // For paths like /create/Contact, return the stashed savedSearch if present
+ savedSearch: function($route, $location, $timeout, crmApi4) {
+ var retrievedSearch = savedSearch,
+ params = $route.current.params;
+ savedSearch = undefined;
+ switch (params.mode) {
+ case 'create':
+ return retrievedSearch;
+
+ case 'load':
+ // In theory savedSearches could be attached to something other than groups, but for now that's not supported
+ if (params.entity !== 'Group' || !params.name) {
+ throw 'Failed to load ' + params.entity;
+ }
+ return crmApi4(params.entity, 'get', {
+ select: ['id', 'title', 'saved_search_id', 'saved_search.api_entity', 'saved_search.api_params'],
+ where: [['name', '=', params.name]]
+ }, 0).then(function(retrieved) {
+ savedSearch = {
+ type: params.entity,
+ id: retrieved.id,
+ title: retrieved.title,
+ saved_search_id: retrieved.saved_search_id,
+ api_params: retrieved['saved_search.api_params']
+ };
+ $timeout(function() {
+ $location.url('/create/' + retrieved['saved_search.api_entity']);
+ });
+ });
+ }
+ }
+ }