made syncTree method on handler return a promise so we can do somethnig with it after (it still raises an event). Updates all editors to assign a currentNode to their scope when syncTree is complete, now that gets assigned to the umboptions which is now decoupled from nav.ui.
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
angular.module("umbraco.directives")
|
||||
.directive('umbOptionsMenu', function ($injector, treeService, navigationService, umbModelMapper) {
|
||||
.directive('umbOptionsMenu', function ($injector, treeService, navigationService, umbModelMapper, appState) {
|
||||
return {
|
||||
scope: {
|
||||
content: "=",
|
||||
currentSection: "@",
|
||||
treeAlias: "@"
|
||||
currentNode: "="
|
||||
},
|
||||
restrict: 'E',
|
||||
replace: true,
|
||||
@@ -15,9 +14,6 @@ angular.module("umbraco.directives")
|
||||
//depending on what the menu item is supposed to do.
|
||||
scope.executeMenuItem = function (action) {
|
||||
|
||||
//map our content object to a basic entity to pass in to the handlers
|
||||
var currentEntity = umbModelMapper.convertToEntityBasic(scope.content);
|
||||
|
||||
if (action.metaData && action.metaData["jsAction"] && angular.isString(action.metaData["jsAction"])) {
|
||||
|
||||
//we'll try to get the jsAction from the injector
|
||||
@@ -43,10 +39,10 @@ angular.module("umbraco.directives")
|
||||
}
|
||||
|
||||
method.apply(this, [{
|
||||
entity: currentEntity,
|
||||
entity: umbModelMapper.convertToEntityBasic(scope.currentNode),
|
||||
action: action,
|
||||
section: scope.currentSection,
|
||||
treeAlias: scope.treeAlias
|
||||
treeAlias: treeService.getTreeAlias(scope.currentNode)
|
||||
}]);
|
||||
}
|
||||
}
|
||||
@@ -57,18 +53,19 @@ angular.module("umbraco.directives")
|
||||
// the problem with all these dialogs is were passing other object's scopes around which isn't nice at all.
|
||||
// Each of these passed scopes expects a .nav property assigned to it which is a reference to the navigationService,
|
||||
// which should not be happenning... should simply be using the navigation service, no ?!
|
||||
scope.$parent.openDialog(currentEntity, action, scope.currentSection);
|
||||
scope.$parent.openDialog(scope.currentNode, action, scope.currentSection);
|
||||
}
|
||||
};
|
||||
|
||||
//callback method to go and get the options async
|
||||
scope.getOptions = function () {
|
||||
if (!scope.content.id) {
|
||||
|
||||
if (!scope.currentNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!scope.actions) {
|
||||
treeService.getMenu({ treeNode: navigationService.ui.currentNode })
|
||||
treeService.getMenu({ treeNode: scope.currentNode })
|
||||
.then(function (data) {
|
||||
scope.actions = data.menuItems;
|
||||
});
|
||||
|
||||
@@ -114,6 +114,14 @@ function umbTreeDirective($compile, $log, $q, $rootScope, treeService, notificat
|
||||
throw "args.path cannot be null";
|
||||
}
|
||||
|
||||
var deferred = $q.defer();
|
||||
|
||||
//this is super complex but seems to be working in other places, here we're listening for our
|
||||
// own events, once the tree is sycned we'll resolve our promise.
|
||||
scope.eventhandler.one("treeSynced", function (e, syncArgs) {
|
||||
deferred.resolve(syncArgs);
|
||||
});
|
||||
|
||||
//this should normally be set unless it is being called from legacy
|
||||
// code, so set the active tree type before proceeding.
|
||||
if (args.tree) {
|
||||
@@ -130,6 +138,8 @@ function umbTreeDirective($compile, $log, $q, $rootScope, treeService, notificat
|
||||
//filter the path for root node ids
|
||||
args.path = _.filter(args.path, function (item) { return (item !== "init" && item !== "-1"); });
|
||||
loadPath(args.path, args.forceReload);
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,7 @@ function angularHelper($log, $q) {
|
||||
*
|
||||
* @description
|
||||
* In some situations we need to return a promise as a rejection, normally based on invalid data. This
|
||||
* is a wrapper to do that so we can save one writing a bit of code.
|
||||
* is a wrapper to do that so we can save on writing a bit of code.
|
||||
*
|
||||
* @param {object} objReject The object to send back with the promise rejection
|
||||
*/
|
||||
|
||||
@@ -27,11 +27,11 @@ function umbracoMenuActions($q, treeService, $location, navigationService, appSt
|
||||
*/
|
||||
"RefreshNode": function (args) {
|
||||
|
||||
//just in case clear any tree cache for this node/section
|
||||
treeService.clearCache({
|
||||
cacheKey: "__" + args.section, //each item in the tree cache is cached by the section name
|
||||
childrenOf: args.entity.parentId //clear the children of the parent
|
||||
});
|
||||
////just in case clear any tree cache for this node/section
|
||||
//treeService.clearCache({
|
||||
// cacheKey: "__" + args.section, //each item in the tree cache is cached by the section name
|
||||
// childrenOf: args.entity.parentId //clear the children of the parent
|
||||
//});
|
||||
|
||||
//since we're dealing with an entity, we need to attempt to find it's tree node, in the main tree
|
||||
// this action is purely a UI thing so if for whatever reason there is no loaded tree node in the UI
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* Section navigation and search, and maintain their state for the entire application lifetime
|
||||
*
|
||||
*/
|
||||
function navigationService($rootScope, $routeParams, $log, $location, $q, $timeout, dialogService, treeService, notificationsService, historyService, appState) {
|
||||
function navigationService($rootScope, $routeParams, $log, $location, $q, $timeout, dialogService, treeService, notificationsService, historyService, appState, angularHelper) {
|
||||
|
||||
var minScreenSize = 1100;
|
||||
//used to track the current dialog object
|
||||
@@ -297,7 +297,7 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
|
||||
* @methodOf umbraco.services.navigationService
|
||||
*
|
||||
* @description
|
||||
* Syncs a tree with a given path
|
||||
* Syncs a tree with a given path, returns a promise
|
||||
* The path format is: ["itemId","itemId"], and so on
|
||||
* so to sync to a specific document type node do:
|
||||
* <pre>
|
||||
@@ -320,8 +320,12 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo
|
||||
}
|
||||
|
||||
if (mainTreeEventHandler) {
|
||||
mainTreeEventHandler.syncTree(args);
|
||||
//returns a promise
|
||||
return mainTreeEventHandler.syncTree(args);
|
||||
}
|
||||
|
||||
//couldn't sync
|
||||
return angularHelper.rejectedPromise();
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,6 +13,7 @@ function ContentEditController($scope, $routeParams, $q, $timeout, $window, appS
|
||||
$scope.subButtons = [];
|
||||
$scope.nav = navigationService;
|
||||
$scope.currentSection = appState.getSectionState("currentSection");
|
||||
$scope.currentNode = null; //the editors affiliated node
|
||||
|
||||
//This sets up the action buttons based on what permissions the user has.
|
||||
//The allowedActions parameter contains a list of chars, each represents a button by permission so
|
||||
@@ -125,7 +126,9 @@ function ContentEditController($scope, $routeParams, $q, $timeout, $window, appS
|
||||
|
||||
configureButtons(data);
|
||||
|
||||
navigationService.syncTree({ tree: "content", path: data.path.split(","), forceReload: true });
|
||||
navigationService.syncTree({ tree: "content", path: data.path.split(","), forceReload: true }).then(function (syncArgs) {
|
||||
$scope.currentNode = syncArgs.node;
|
||||
});
|
||||
|
||||
deferred.resolve(data);
|
||||
|
||||
@@ -171,7 +174,9 @@ function ContentEditController($scope, $routeParams, $q, $timeout, $window, appS
|
||||
// if there are any and then clear them so the collection no longer persists them.
|
||||
serverValidationManager.executeAndClearAllSubscriptions();
|
||||
|
||||
navigationService.syncTree({ tree: "content", path: data.path.split(",") });
|
||||
navigationService.syncTree({ tree: "content", path: data.path.split(",") }).then(function(syncArgs) {
|
||||
$scope.currentNode = syncArgs.node;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -193,7 +198,9 @@ function ContentEditController($scope, $routeParams, $q, $timeout, $window, appS
|
||||
|
||||
configureButtons(data);
|
||||
|
||||
navigationService.syncTree({ tree: "content", path: data.path.split(","), forceReload: true });
|
||||
navigationService.syncTree({ tree: "content", path: data.path.split(","), forceReload: true }).then(function (syncArgs) {
|
||||
$scope.currentNode = syncArgs.node;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,10 @@
|
||||
<p class="btn btn-link umb-status-label">{{formStatus}}</p>
|
||||
</div>
|
||||
|
||||
<umb-options-menu content="content" current-section="{{currentSection}}"></umb-options-menu>
|
||||
<umb-options-menu ng-show="currentNode"
|
||||
current-node="currentNode"
|
||||
current-section="{{currentSection}}">
|
||||
</umb-options-menu>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -11,6 +11,7 @@ function DataTypeEditController($scope, $routeParams, $location, appState, navig
|
||||
//setup scope vars
|
||||
$scope.nav = navigationService;
|
||||
$scope.currentSection = appState.getSectionState("currentSection");
|
||||
$scope.currentNode = null; //the editors affiliated node
|
||||
|
||||
//method used to configure the pre-values when we retreive them from the server
|
||||
function createPreValueProps(preVals) {
|
||||
@@ -68,7 +69,9 @@ function DataTypeEditController($scope, $routeParams, $location, appState, navig
|
||||
// if there are any and then clear them so the collection no longer persists them.
|
||||
serverValidationManager.executeAndClearAllSubscriptions();
|
||||
|
||||
navigationService.syncTree({ tree: "datatype", path: [String(data.id)] });
|
||||
navigationService.syncTree({ tree: "datatype", path: [String(data.id)] }).then(function (syncArgs) {
|
||||
$scope.currentNode = syncArgs.node;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -104,7 +107,9 @@ function DataTypeEditController($scope, $routeParams, $location, appState, navig
|
||||
}
|
||||
});
|
||||
|
||||
navigationService.syncTree({ tree: "datatype", path: [String(data.id)], forceReload: true });
|
||||
navigationService.syncTree({ tree: "datatype", path: [String(data.id)], forceReload: true }).then(function (syncArgs) {
|
||||
$scope.currentNode = syncArgs.node;
|
||||
});
|
||||
|
||||
}, function(err) {
|
||||
|
||||
|
||||
@@ -18,7 +18,10 @@
|
||||
<div class="span8">
|
||||
<div class="btn-toolbar pull-right umb-btn-toolbar">
|
||||
|
||||
<umb-options-menu content="content" current-section="{{currentSection}}"></umb-options-menu>
|
||||
<umb-options-menu ng-show="currentNode"
|
||||
current-node="currentNode"
|
||||
current-section="{{currentSection}}">
|
||||
</umb-options-menu>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -20,7 +20,10 @@
|
||||
<p class="btn btn-link umb-status-label">{{formStatus}}</p>
|
||||
</div>
|
||||
|
||||
<umb-options-menu content="content" current-section="{{currentSection}}"></umb-options-menu>
|
||||
<umb-options-menu ng-show="currentNode"
|
||||
current-node="currentNode"
|
||||
current-section="{{currentSection}}">
|
||||
</umb-options-menu>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -11,6 +11,7 @@ function mediaEditController($scope, $routeParams, appState, mediaResource, navi
|
||||
//setup scope vars
|
||||
$scope.nav = navigationService;
|
||||
$scope.currentSection = appState.getSectionState("currentSection");
|
||||
$scope.currentNode = null; //the editors affiliated node
|
||||
|
||||
if ($routeParams.create) {
|
||||
|
||||
@@ -33,7 +34,9 @@ function mediaEditController($scope, $routeParams, appState, mediaResource, navi
|
||||
// if there are any and then clear them so the collection no longer persists them.
|
||||
serverValidationManager.executeAndClearAllSubscriptions();
|
||||
|
||||
navigationService.syncTree({ tree: "media", path: data.path });
|
||||
navigationService.syncTree({ tree: "media", path: data.path }).then(function (syncArgs) {
|
||||
$scope.currentNode = syncArgs.node;
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
@@ -53,7 +56,9 @@ function mediaEditController($scope, $routeParams, appState, mediaResource, navi
|
||||
rebindCallback: contentEditingHelper.reBindChangedProperties($scope.content, data)
|
||||
});
|
||||
|
||||
navigationService.syncTree({ tree: "media", path: data.path, forceReload: true });
|
||||
navigationService.syncTree({ tree: "media", path: data.path, forceReload: true }).then(function (syncArgs) {
|
||||
$scope.currentNode = syncArgs.node;
|
||||
});
|
||||
|
||||
}, function(err) {
|
||||
|
||||
|
||||
@@ -20,7 +20,10 @@
|
||||
<p class="btn btn-link umb-status-label">{{formStatus}}</p>
|
||||
</div>
|
||||
|
||||
<umb-options-menu content="content" current-section="{{currentSection}}"></umb-options-menu>
|
||||
<umb-options-menu ng-show="currentNode"
|
||||
current-node="currentNode"
|
||||
current-section="{{currentSection}}">
|
||||
</umb-options-menu>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -11,6 +11,7 @@ function MemberEditController($scope, $routeParams, $location, $q, $window, appS
|
||||
//setup scope vars
|
||||
$scope.nav = navigationService;
|
||||
$scope.currentSection = appState.getSectionState("currentSection");
|
||||
$scope.currentNode = null; //the editors affiliated node
|
||||
|
||||
if ($routeParams.create) {
|
||||
//we are creating so get an empty member item
|
||||
@@ -43,7 +44,9 @@ function MemberEditController($scope, $routeParams, $location, $q, $window, appS
|
||||
var path = data.name[0]+"," + data.key;
|
||||
path = path.replace(/-/g,'');
|
||||
|
||||
navigationService.syncTree({ tree: "member", path: path.split(",") });
|
||||
navigationService.syncTree({ tree: "member", path: path.split(",") }).then(function (syncArgs) {
|
||||
$scope.currentNode = syncArgs.node;
|
||||
});
|
||||
|
||||
//in one particular special case, after we've created a new item we redirect back to the edit
|
||||
// route but there might be server validation errors in the collection which we need to display
|
||||
@@ -71,6 +74,10 @@ function MemberEditController($scope, $routeParams, $location, $q, $window, appS
|
||||
redirectId: data.key,
|
||||
rebindCallback: contentEditingHelper.reBindChangedProperties($scope.content, data)
|
||||
});
|
||||
|
||||
navigationService.syncTree({ tree: "member", path: path.split(",") }).then(function (syncArgs) {
|
||||
$scope.currentNode = syncArgs.node;
|
||||
});
|
||||
|
||||
}, function (err) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user