mirror of
https://github.com/nasa/openmct.git
synced 2025-06-16 06:08:11 +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:
@ -36,7 +36,6 @@ define([
|
|||||||
"./src/policies/EditActionPolicy",
|
"./src/policies/EditActionPolicy",
|
||||||
"./src/policies/EditableLinkPolicy",
|
"./src/policies/EditableLinkPolicy",
|
||||||
"./src/policies/EditableMovePolicy",
|
"./src/policies/EditableMovePolicy",
|
||||||
"./src/policies/EditNavigationPolicy",
|
|
||||||
"./src/policies/EditContextualActionPolicy",
|
"./src/policies/EditContextualActionPolicy",
|
||||||
"./src/representers/EditRepresenter",
|
"./src/representers/EditRepresenter",
|
||||||
"./src/representers/EditToolbarRepresenter",
|
"./src/representers/EditToolbarRepresenter",
|
||||||
@ -75,7 +74,6 @@ define([
|
|||||||
EditActionPolicy,
|
EditActionPolicy,
|
||||||
EditableLinkPolicy,
|
EditableLinkPolicy,
|
||||||
EditableMovePolicy,
|
EditableMovePolicy,
|
||||||
EditNavigationPolicy,
|
|
||||||
EditContextualActionPolicy,
|
EditContextualActionPolicy,
|
||||||
EditRepresenter,
|
EditRepresenter,
|
||||||
EditToolbarRepresenter,
|
EditToolbarRepresenter,
|
||||||
@ -130,7 +128,7 @@ define([
|
|||||||
"depends": [
|
"depends": [
|
||||||
"$scope",
|
"$scope",
|
||||||
"$location",
|
"$location",
|
||||||
"policyService"
|
"navigationService"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -262,11 +260,6 @@ define([
|
|||||||
"category": "action",
|
"category": "action",
|
||||||
"implementation": EditableLinkPolicy
|
"implementation": EditableLinkPolicy
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"category": "navigation",
|
|
||||||
"message": "Continuing will cause the loss of any unsaved changes.",
|
|
||||||
"implementation": EditNavigationPolicy
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"implementation": CreationPolicy,
|
"implementation": CreationPolicy,
|
||||||
"category": "creation"
|
"category": "creation"
|
||||||
|
@ -28,17 +28,48 @@ define(
|
|||||||
[],
|
[],
|
||||||
function () {
|
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
|
* Controller which is responsible for populating the scope for
|
||||||
* Edit mode
|
* Edit mode
|
||||||
* @memberof platform/commonUI/edit
|
* @memberof platform/commonUI/edit
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function EditObjectController($scope, $location, policyService) {
|
function EditObjectController($scope, $location, navigationService) {
|
||||||
this.scope = $scope;
|
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) {
|
function setViewForDomainObject(domainObject) {
|
||||||
|
|
||||||
var locationViewKey = $location.search().view;
|
var locationViewKey = $location.search().view;
|
||||||
@ -54,10 +85,9 @@ define(
|
|||||||
((domainObject && domainObject.useCapability('view')) || [])
|
((domainObject && domainObject.useCapability('view')) || [])
|
||||||
.forEach(selectViewIfMatching);
|
.forEach(selectViewIfMatching);
|
||||||
}
|
}
|
||||||
navigatedObject = domainObject;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.$watch('domainObject', setViewForDomainObject);
|
setViewForDomainObject($scope.domainObject);
|
||||||
|
|
||||||
$scope.doAction = function (action) {
|
$scope.doAction = function (action) {
|
||||||
return $scope[action] && $scope[action]();
|
return $scope[action] && $scope[action]();
|
||||||
|
@ -1,64 +0,0 @@
|
|||||||
/*****************************************************************************
|
|
||||||
* Open MCT, Copyright (c) 2014-2016, United States Government
|
|
||||||
* as represented by the Administrator of the National Aeronautics and Space
|
|
||||||
* Administration. All rights reserved.
|
|
||||||
*
|
|
||||||
* Open MCT is licensed under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
* Open MCT includes source code licensed under additional open source
|
|
||||||
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
|
||||||
* this source code distribution or the Licensing information page available
|
|
||||||
* at runtime from the About dialog for additional information.
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
define(
|
|
||||||
[],
|
|
||||||
function () {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Policy controlling whether navigation events should proceed
|
|
||||||
* when object is being edited.
|
|
||||||
* @memberof platform/commonUI/edit
|
|
||||||
* @constructor
|
|
||||||
* @implements {Policy.<Action, ActionContext>}
|
|
||||||
*/
|
|
||||||
function EditNavigationPolicy(policyService) {
|
|
||||||
this.policyService = policyService;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
EditNavigationPolicy.prototype.isDirty = function (domainObject) {
|
|
||||||
var navigatedObject = domainObject,
|
|
||||||
editorCapability = navigatedObject &&
|
|
||||||
navigatedObject.getCapability("editor");
|
|
||||||
|
|
||||||
return editorCapability &&
|
|
||||||
editorCapability.isEditContextRoot() &&
|
|
||||||
editorCapability.dirty();
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allow navigation if an object is not dirty, or if the user elects
|
|
||||||
* to proceed anyway.
|
|
||||||
* @param currentNavigation
|
|
||||||
* @returns {boolean|*} true if the object model is clean; or if
|
|
||||||
* it's dirty and the user wishes to proceed anyway.
|
|
||||||
*/
|
|
||||||
EditNavigationPolicy.prototype.allow = function (currentNavigation) {
|
|
||||||
return !this.isDirty(currentNavigation);
|
|
||||||
};
|
|
||||||
|
|
||||||
return EditNavigationPolicy;
|
|
||||||
}
|
|
||||||
);
|
|
Reference in New Issue
Block a user