mirror of
https://github.com/nasa/openmct.git
synced 2025-06-15 13:48:12 +00:00
[Edit] manage editing in EditObjectController
EditObjectController now exits edit mode when it is destroyed. It also injects a check function in the navigation service to replace the old functionality implemented in EditNavigationPolicy. https://github.com/nasa/openmct/issues/1360
This commit is contained in:
@ -28,17 +28,48 @@ define(
|
||||
[],
|
||||
function () {
|
||||
|
||||
function isDirty(domainObject) {
|
||||
var navigatedObject = domainObject,
|
||||
editorCapability = navigatedObject &&
|
||||
navigatedObject.getCapability("editor");
|
||||
|
||||
return editorCapability &&
|
||||
editorCapability.isEditContextRoot() &&
|
||||
editorCapability.dirty();
|
||||
}
|
||||
|
||||
function cancelEditing(domainObject) {
|
||||
var navigatedObject = domainObject,
|
||||
editorCapability = navigatedObject &&
|
||||
navigatedObject.getCapability("editor");
|
||||
|
||||
return editorCapability &&
|
||||
editorCapability.finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Controller which is responsible for populating the scope for
|
||||
* Edit mode
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
*/
|
||||
function EditObjectController($scope, $location, policyService) {
|
||||
function EditObjectController($scope, $location, navigationService) {
|
||||
this.scope = $scope;
|
||||
this.policyService = policyService;
|
||||
var domainObject = $scope.domainObject;
|
||||
|
||||
var removeCheck = navigationService
|
||||
.checkBeforeNavigation(function () {
|
||||
if (isDirty(domainObject)) {
|
||||
return "Continuing will cause the loss of any unsaved changes.";
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
$scope.$on('$destroy', function () {
|
||||
removeCheck();
|
||||
cancelEditing(domainObject);
|
||||
});
|
||||
|
||||
var navigatedObject;
|
||||
function setViewForDomainObject(domainObject) {
|
||||
|
||||
var locationViewKey = $location.search().view;
|
||||
@ -54,10 +85,9 @@ define(
|
||||
((domainObject && domainObject.useCapability('view')) || [])
|
||||
.forEach(selectViewIfMatching);
|
||||
}
|
||||
navigatedObject = domainObject;
|
||||
}
|
||||
|
||||
$scope.$watch('domainObject', setViewForDomainObject);
|
||||
setViewForDomainObject($scope.domainObject);
|
||||
|
||||
$scope.doAction = function (action) {
|
||||
return $scope[action] && $scope[action]();
|
||||
|
Reference in New Issue
Block a user