Change to navigate by location change

This commit is contained in:
Henry
2015-11-16 17:45:31 -08:00
parent d961b41253
commit cd3bdf4f81
5 changed files with 65 additions and 27 deletions

View File

@@ -20,7 +20,8 @@
at runtime from the About dialog for additional information. at runtime from the About dialog for additional information.
--> -->
<div class="abs holder-all browse-mode" ng-controller="BrowseController"> <div class="abs holder-all browse-mode" ng-controller="BrowseController"
mct-before-unload="beforeUnloadWarning()">
<mct-include key="'topbar-browse'"></mct-include> <mct-include key="'topbar-browse'"></mct-include>
<div class="abs holder holder-main browse-area s-browse-area browse-wrapper" <div class="abs holder holder-main browse-area s-browse-area browse-wrapper"
ng-controller="PaneController as modelPaneTree" ng-controller="PaneController as modelPaneTree"

View File

@@ -34,7 +34,8 @@ define(
"use strict"; "use strict";
var ROOT_ID = "ROOT", var ROOT_ID = "ROOT",
DEFAULT_PATH = "mine"; DEFAULT_PATH = "mine",
CONFIRM_MSG = "Unsaved changes will be lost if you leave this page.";
/** /**
* The BrowseController is used to populate the initial scope in Browse * The BrowseController is used to populate the initial scope in Browse
@@ -54,33 +55,50 @@ define(
function updateRoute(domainObject) { function updateRoute(domainObject) {
var priorRoute = $route.current, var priorRoute = $route.current,
// Act as if params HADN'T changed to avoid page reload // Act as if params HADN'T changed to avoid page reload
unlisten; unlisten,
navigateToObject = domainObject,
mode = "browse";
unlisten = $scope.$on('$locationChangeSuccess', function () { unlisten = $scope.$on('$locationChangeSuccess', function () {
// Checks path to make sure /browse/ is at front // Checks path to make sure /browse/ is at front
// if so, change $route.current // if so, change $route.current
if ($location.path().indexOf("/browse/") === 0) { //if ($location.path().indexOf("/browse/") === 0) {
$route.current = priorRoute; $route.current = priorRoute;
} //}
setNavigation(domainObject);
unlisten(); unlisten();
}); });
// urlService.urlForLocation used to adjust current // urlService.urlForLocation used to adjust current
// path to new, addressed, path based on // path to new, addressed, path based on
// domainObject // domainObject
$location.path(urlService.urlForLocation("browse", domainObject)); if (domainObject && domainObject.hasCapability("editor")){
//Set navigation path to edit mode
mode = "edit";
//Unwrap non-editable object for url calculation (needs
// context capability
navigateToObject = domainObject.getOriginalObject();
}
$location.path(urlService.urlForLocation(mode, navigateToObject));
} }
function setSelectedObject(domainObject) {
/* if (domainObject !== $scope.navigatedObject && isDirty()
&& !confirm(CONFIRM_MSG)) {
$scope.treeModel.selectedObject = $scope.navigatedObject;
} else {
setNavigation(domainObject);
}*/
updateRoute(domainObject);
}
// Callback for updating the in-scope reference to the object // Callback for updating the in-scope reference to the object
// that is currently navigated-to. // that is currently navigated-to.
function setNavigation(domainObject) { function setNavigation(domainObject) {
$scope.navigatedObject = domainObject;
var wrappedObject = domainObject;
$scope.navigatedObject = wrappedObject;
$scope.treeModel.selectedObject = domainObject; $scope.treeModel.selectedObject = domainObject;
navigationService.setNavigation(domainObject); //navigationService.setNavigation(domainObject);
updateRoute(domainObject);
} }
function navigateTo(domainObject) { function navigateTo(domainObject) {
@@ -150,25 +168,40 @@ define(
selectedObject: navigationService.getNavigation() selectedObject: navigationService.getNavigation()
}; };
$scope.beforeUnloadWarning = function() { function isDirty(){
var editorCapability = $scope.navigatedObject && var editorCapability = $scope.navigatedObject &&
$scope.navigatedObject.getCapability("editor"), $scope.navigatedObject.getCapability("editor"),
hasChanges = editorCapability && editorCapability.dirty(); hasChanges = editorCapability && editorCapability.dirty();
return hasChanges;
}
return hasChanges ? function beforeNavigateWarning (){
if (isDirty()) {
return false;
}
else {
return true;
}
}
$scope.beforeUnloadWarning = function() {
return isDirty() ?
"Unsaved changes will be lost if you leave this page." : "Unsaved changes will be lost if you leave this page." :
undefined; undefined;
} }
// Listen for changes in navigation state. // Listen for changes in navigation state.
navigationService.addListener(setNavigation); navigationService.addListener(updateRoute);
// Also listen for changes which come from the tree // If the selected tree node changes, update the route. This
$scope.$watch("treeModel.selectedObject", setNavigation); // ensures navigation is always in sync with browser location,
// and also allows unload event to be used for catching
// navigation as well as browse events.
$scope.$watch("treeModel.selectedObject", updateRoute);
// Clean up when the scope is destroyed // Clean up when the scope is destroyed
$scope.$on("$destroy", function () { $scope.$on("$destroy", function () {
navigationService.removeListener(setNavigation); navigationService.removeListener(updateRoute);
}); });
} }

View File

@@ -78,7 +78,7 @@
"implementation": "actions/CancelAction.js", "implementation": "actions/CancelAction.js",
"name": "Cancel", "name": "Cancel",
"description": "Discard changes made to these objects.", "description": "Discard changes made to these objects.",
"depends": ["$injector", "navigationService"] "depends": ["$location", "urlService"]
} }
], ],
"policies": [ "policies": [

View File

@@ -33,10 +33,10 @@ define(
* @memberof platform/commonUI/edit * @memberof platform/commonUI/edit
* @implements {Action} * @implements {Action}
*/ */
function CancelAction($injector, navigationService, context) { function CancelAction($location, urlService, context) {
this.domainObject = context.domainObject; this.domainObject = context.domainObject;
this.navigationService = navigationService; this.$location = $location;
this.objectService = $injector.get('objectService'); this.urlService = urlService;
} }
/** /**
@@ -47,7 +47,8 @@ define(
*/ */
CancelAction.prototype.perform = function () { CancelAction.prototype.perform = function () {
var domainObject = this.domainObject, var domainObject = this.domainObject,
self = this; $location = this.$location,
urlService = this.urlService;
// Look up the object's "editor.completion" capability; // Look up the object's "editor.completion" capability;
// this is introduced by EditableDomainObject which is // this is introduced by EditableDomainObject which is
@@ -63,10 +64,13 @@ define(
return editor.cancel(); return editor.cancel();
} }
//Discard current 'editable' object, and retrieve original // Discard the current root view (which will be the editing
// un-edited object. // UI, which will have been pushed atop the Browise UI.)
function returnToBrowse() { function returnToBrowse() {
return self.navigationService.setNavigation(self.domainObject.getOriginalObject()); $location.path(urlService.urlForLocation(
"browse",
domainObject.getOriginalObject()
));
} }
return doCancel(getEditorCapability()) return doCancel(getEditorCapability())

View File

@@ -76,7 +76,7 @@
{ {
"key": "TreeNodeController", "key": "TreeNodeController",
"implementation": "controllers/TreeNodeController.js", "implementation": "controllers/TreeNodeController.js",
"depends": [ "$scope", "$timeout" ] "depends": [ "$scope", "$timeout", "navigationService" ]
}, },
{ {
"key": "ActionGroupController", "key": "ActionGroupController",