check if template tree exists, to avoid error if its not present.
This commit is contained in:
@@ -65,6 +65,7 @@ function umbTreeDirective($q, $rootScope, treeService, notificationsService, use
|
||||
vm.reloadNode = reloadNode;
|
||||
vm.syncTree = syncTree;
|
||||
vm.loadChildren = loadChildren;
|
||||
vm.hasTree = hasTree;
|
||||
|
||||
//wire up the exposed api object for hosting controllers
|
||||
if ($scope.api) {
|
||||
@@ -72,6 +73,7 @@ function umbTreeDirective($q, $rootScope, treeService, notificationsService, use
|
||||
$scope.api.load = vm.load;
|
||||
$scope.api.reloadNode = vm.reloadNode;
|
||||
$scope.api.syncTree = vm.syncTree;
|
||||
$scope.api.hasTree = vm.hasTree;
|
||||
}
|
||||
|
||||
//flag to track the last loaded section when the tree 'un-loads'. We use this to determine if we should
|
||||
@@ -203,6 +205,25 @@ function umbTreeDirective($q, $rootScope, treeService, notificationsService, use
|
||||
});
|
||||
}
|
||||
|
||||
//given a tree alias, this will search the current section tree for the specified tree alias and set the current active tree to it's root node
|
||||
function hasTree(treeAlias) {
|
||||
|
||||
if (!$scope.tree) {
|
||||
throw "Err in umbtree.directive.loadActiveTree, $scope.tree is null";
|
||||
}
|
||||
|
||||
if (!treeAlias) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var treeRoots = getTreeRootNodes();
|
||||
var foundTree = _.find(treeRoots, function (node) {
|
||||
return node.metaData.treeAlias.toUpperCase() === treeAlias.toUpperCase();
|
||||
});
|
||||
|
||||
return foundTree !== undefined;
|
||||
}
|
||||
|
||||
//given a tree alias, this will search the current section tree for the specified tree alias and set the current active tree to it's root node
|
||||
function loadActiveTree(treeAlias) {
|
||||
|
||||
|
||||
@@ -338,6 +338,22 @@ function navigationService($routeParams, $location, $q, $injector, eventsService
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc method
|
||||
* @name umbraco.services.navigationService#hasTree
|
||||
* @methodOf umbraco.services.navigationService
|
||||
*
|
||||
* @description
|
||||
* Checks if a tree with the given alias exists.
|
||||
*
|
||||
* @param {String} treeAlias the tree alias to check
|
||||
*/
|
||||
hasTree: function (treeAlias) {
|
||||
return navReadyPromise.promise.then(function () {
|
||||
return mainTreeApi.hasTree(treeAlias);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
Internal method that should ONLY be used by the legacy API wrapper, the legacy API used to
|
||||
have to set an active tree and then sync, the new API does this in one method by using syncTree
|
||||
|
||||
@@ -519,11 +519,16 @@
|
||||
}));
|
||||
|
||||
evts.push(eventsService.on("editors.documentType.saved", function(name, args) {
|
||||
if(args.documentType.allowedTemplates.length > 0){
|
||||
navigationService.syncTree({ tree: "templates", path: [], forceReload: true })
|
||||
.then(function (syncArgs) {
|
||||
navigationService.reloadNode(syncArgs.node)
|
||||
});
|
||||
if(args.documentType.allowedTemplates.length > 0) {
|
||||
navigationService.hasTree("templates").then(function (treeExists) {
|
||||
if (treeExists) {
|
||||
navigationService.syncTree({ tree: "templates", path: [], forceReload: true })
|
||||
.then(function (syncArgs) {
|
||||
navigationService.reloadNode(syncArgs.node)
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user