Edit mode and cancel buttons work
This commit is contained in:
@@ -74,15 +74,17 @@ define(
|
||||
// Callback for updating the in-scope reference to the object
|
||||
// that is currently navigated-to.
|
||||
function setNavigation(domainObject) {
|
||||
var navigatedDomainObject = domainObject;
|
||||
|
||||
$scope.navigatedObject = navigatedDomainObject;
|
||||
|
||||
var wrappedObject = domainObject;
|
||||
|
||||
$scope.navigatedObject = wrappedObject;
|
||||
$scope.treeModel.selectedObject = domainObject;
|
||||
navigationService.setNavigation(domainObject);
|
||||
updateRoute(domainObject);
|
||||
}
|
||||
|
||||
function navigateTo(domainObject) {
|
||||
|
||||
// Check if an object has been navigated-to already...
|
||||
// If not, or if an ID path has been explicitly set in the URL,
|
||||
// navigate to the URL-specified object.
|
||||
@@ -148,6 +150,16 @@ define(
|
||||
selectedObject: navigationService.getNavigation()
|
||||
};
|
||||
|
||||
$scope.beforeUnloadWarning = function() {
|
||||
var editorCapability = $scope.navigatedObject &&
|
||||
$scope.navigatedObject.getCapability("editor"),
|
||||
hasChanges = editorCapability && editorCapability.dirty();
|
||||
|
||||
return hasChanges ?
|
||||
"Unsaved changes will be lost if you leave this page." :
|
||||
undefined;
|
||||
}
|
||||
|
||||
// Listen for changes in navigation state.
|
||||
navigationService.addListener(setNavigation);
|
||||
|
||||
@@ -159,8 +171,6 @@ define(
|
||||
navigationService.removeListener(setNavigation);
|
||||
});
|
||||
|
||||
$scope.editMode = false;
|
||||
|
||||
}
|
||||
|
||||
return BrowseController;
|
||||
|
||||
@@ -33,7 +33,8 @@ define(
|
||||
* @memberof platform/commonUI/browse
|
||||
* @constructor
|
||||
*/
|
||||
function BrowseObjectController($scope, $location, $route, $q) {
|
||||
function BrowseObjectController($scope, $location, $route, $q, navigationService) {
|
||||
var navigatedObject;
|
||||
function setViewForDomainObject(domainObject) {
|
||||
|
||||
var locationViewKey = $location.search().view;
|
||||
@@ -49,6 +50,8 @@ define(
|
||||
((domainObject && domainObject.useCapability('view')) || [])
|
||||
.forEach(selectViewIfMatching);
|
||||
}
|
||||
$scope.editMode = domainObject.getDomainObject ? true : false;
|
||||
navigatedObject = domainObject;
|
||||
}
|
||||
|
||||
function updateQueryParam(viewKey) {
|
||||
@@ -66,23 +69,17 @@ define(
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function toggleEditMode(editMode){
|
||||
var domainObject = $scope.domainObject;
|
||||
if (editMode){
|
||||
$scope.domainObject = domainObject && new EditableDomainObject(domainObject, $q);
|
||||
} else {
|
||||
$scope.domainObject = (domainObject.getDomainObject && domainObject.getDomainObject()) || domainObject;
|
||||
}
|
||||
}
|
||||
|
||||
$scope.$watch('editMode', toggleEditMode);
|
||||
|
||||
$scope.$watch('domainObject', setViewForDomainObject);
|
||||
$scope.$watch('representation.selected.key', updateQueryParam);
|
||||
|
||||
$scope.$on(GestureConstants.MCT_DROP_EVENT, function() {
|
||||
$scope.editMode = true;
|
||||
});
|
||||
$scope.cancelEditing = function() {
|
||||
navigationService.setNavigation($scope.domainObject.getDomainObject());
|
||||
}
|
||||
|
||||
$scope.doAction = function (action){
|
||||
$scope[action] && $scope[action]();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user