mirror of
https://github.com/nasa/openmct.git
synced 2025-06-16 22:28:13 +00:00
Addressing issues from code review
This commit is contained in:
@ -124,7 +124,6 @@ define(
|
||||
*/
|
||||
EditorCapability.prototype.cancel = function () {
|
||||
this.editableObject.getCapability("status").set("editing", false);
|
||||
//TODO: Reset the cache as well here.
|
||||
this.cache.markClean();
|
||||
return resolvePromise(undefined);
|
||||
};
|
||||
|
@ -36,8 +36,9 @@ define(
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
*/
|
||||
function EditObjectController($scope, $location) {
|
||||
function EditObjectController($scope, $location, policyService) {
|
||||
this.scope = $scope;
|
||||
this.policyService = policyService;
|
||||
|
||||
var navigatedObject;
|
||||
function setViewForDomainObject(domainObject) {
|
||||
@ -73,16 +74,14 @@ define(
|
||||
*/
|
||||
EditObjectController.prototype.getUnloadWarning = function () {
|
||||
var navigatedObject = this.scope.domainObject,
|
||||
editorCapability = navigatedObject &&
|
||||
navigatedObject.getCapability("editor"),
|
||||
statusCapability = navigatedObject &&
|
||||
navigatedObject.getCapability("status"),
|
||||
hasChanges = statusCapability && statusCapability.get('editing')
|
||||
&& editorCapability && editorCapability.dirty();
|
||||
policyMessage;
|
||||
|
||||
this.policyService.allow("navigation", navigatedObject, undefined, function(message) {
|
||||
policyMessage = message;
|
||||
});
|
||||
|
||||
return policyMessage;
|
||||
|
||||
return hasChanges ?
|
||||
"Unsaved changes will be lost if you leave this page." :
|
||||
undefined;
|
||||
};
|
||||
|
||||
return EditObjectController;
|
||||
|
@ -35,7 +35,7 @@ define(
|
||||
* @constructor
|
||||
* @param $window the window
|
||||
*/
|
||||
function MCTBeforeUnload($window, navigationService) {
|
||||
function MCTBeforeUnload($window) {
|
||||
var unloads = [],
|
||||
oldBeforeUnload = $window.onbeforeunload;
|
||||
|
||||
@ -57,7 +57,6 @@ define(
|
||||
|
||||
// Stop using this unload expression
|
||||
function removeUnload() {
|
||||
navigationService.removeListener(checkNavigationEvent, "before");
|
||||
unloads = unloads.filter(function (callback) {
|
||||
return callback !== unload;
|
||||
});
|
||||
@ -66,28 +65,17 @@ define(
|
||||
}
|
||||
}
|
||||
|
||||
function shouldAllowNavigation(){
|
||||
// Show a dialog before allowing a location change
|
||||
function checkLocationChange(event) {
|
||||
// Get an unload message (if any)
|
||||
var warning = unload();
|
||||
// Prompt the user if there's an unload message
|
||||
return !warning || $window.confirm(warning);
|
||||
}
|
||||
|
||||
// Show a dialog before allowing a location change
|
||||
function checkLocationChange(event) {
|
||||
if (!shouldAllowNavigation()) {
|
||||
// Prevent the route change if it was confirmed
|
||||
if (warning && !$window.confirm(warning)) {
|
||||
// ...and prevent the route change if it was confirmed
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
// Show a dialog before allowing a location change
|
||||
function checkNavigationEvent(event) {
|
||||
// Return a false value to the navigationService to
|
||||
// indicate that the navigation event should be prevented
|
||||
return shouldAllowNavigation();
|
||||
}
|
||||
|
||||
// If this is the first active instance of this directive,
|
||||
// register as the window's beforeunload handler
|
||||
if (unloads.length === 0) {
|
||||
@ -102,8 +90,6 @@ define(
|
||||
|
||||
// Also handle route changes
|
||||
scope.$on("$locationChangeStart", checkLocationChange);
|
||||
|
||||
navigationService.addListener(checkNavigationEvent, "before");
|
||||
}
|
||||
|
||||
return {
|
||||
|
68
platform/commonUI/edit/src/policies/EditNavigationPolicy.js
Normal file
68
platform/commonUI/edit/src/policies/EditNavigationPolicy.js
Normal file
@ -0,0 +1,68 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* as represented by the Administrator of the National Aeronautics and Space
|
||||
* Administration. All rights reserved.
|
||||
*
|
||||
* Open MCT Web 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 Web 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.
|
||||
*****************************************************************************/
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Policy controlling whether navigation events should proceed
|
||||
* when object is being edited.
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
* @implements {Policy.<Action, ActionContext>}
|
||||
*/
|
||||
function EditNavigationPolicy($window, policyService) {
|
||||
this.window = $window;
|
||||
this.policyService = policyService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
EditNavigationPolicy.prototype.isDirty = function(domainObject) {
|
||||
var navigatedObject = domainObject,
|
||||
editorCapability = navigatedObject &&
|
||||
navigatedObject.getCapability("editor"),
|
||||
statusCapability = navigatedObject &&
|
||||
navigatedObject.getCapability("status");
|
||||
|
||||
return statusCapability && statusCapability.get('editing')
|
||||
&& editorCapability && 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;
|
||||
}
|
||||
);
|
@ -147,7 +147,6 @@ define(
|
||||
|
||||
// Respond to the destruction of the current representation.
|
||||
EditRepresenter.prototype.destroy = function destroy() {
|
||||
// Nothing to clean up
|
||||
return this.listenHandle && this.listenHandle();
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user