[Edit Mode] #627 remove edit concerns from browse controller

This commit is contained in:
Henry
2016-01-26 21:47:19 -08:00
parent 494212a448
commit 549dfab5aa
16 changed files with 402 additions and 100 deletions

View File

@ -72,13 +72,26 @@ define(
* Enter edit mode.
*/
EditAction.prototype.perform = function () {
var editableObject;
var self = this;
if (!this.domainObject.hasCapability("editor")) {
editableObject = new EditableDomainObject(this.domainObject, this.$q);
editableObject.getCapability('status').set('editing', true);
this.navigationService.setNavigation(editableObject);
//TODO: This is only necessary because the drop gesture is
// wrapping the object itself, need to refactor this later.
// All responsibility for switching into edit mode should be
// in the edit action, and not duplicated in the gesture
this.domainObject = new EditableDomainObject(this.domainObject, this.$q);
}
//this.$location.path("/edit");
this.navigationService.setNavigation(this.domainObject);
this.domainObject.getCapability('status').set('editing', true);
//Register a listener to automatically cancel this edit action
//if the user navigates away from this object.
function cancelEditing(navigatedTo){
if (!navigatedTo || navigatedTo.getId() !== self.domainObject.getId()) {
self.domainObject.getCapability('editor').cancel();
self.navigationService.removeListener(cancelEditing);
}
}
this.navigationService.addListener(cancelEditing);
};
/**

View File

@ -0,0 +1,65 @@
/*****************************************************************************
* 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,Promise*/
/**
* This bundle implements Edit mode.
* @namespace platform/commonUI/edit
*/
define(
[],
function () {
"use strict";
/**
* Controller which is responsible for populating the scope for
* Edit mode
* @memberof platform/commonUI/edit
* @constructor
*/
function EditObjectController($scope) {
this.scope = $scope;
}
/**
* Get the warning to show if the user attempts to navigate
* away from Edit mode while unsaved changes are present.
* @returns {string} the warning to show, or undefined if
* there are no unsaved changes
*/
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();
return hasChanges ?
"Unsaved changes will be lost if you leave this page." :
undefined;
};
return EditObjectController;
}
);

View File

@ -35,7 +35,7 @@ define(
* @constructor
* @param $window the window
*/
function MCTBeforeUnload($window) {
function MCTBeforeUnload($window, navigationService) {
var unloads = [],
oldBeforeUnload = $window.onbeforeunload;
@ -57,6 +57,7 @@ define(
// Stop using this unload expression
function removeUnload() {
navigationService.removeListener(checkNavigationEvent, "before");
unloads = unloads.filter(function (callback) {
return callback !== unload;
});
@ -65,17 +66,28 @@ define(
}
}
// Show a dialog before allowing a location change
function checkLocationChange(event) {
function shouldAllowNavigation(){
// Get an unload message (if any)
var warning = unload();
// Prompt the user if there's an unload message
if (warning && !$window.confirm(warning)) {
// ...and prevent the route change if it was confirmed
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
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) {
@ -90,6 +102,8 @@ define(
// Also handle route changes
scope.$on("$locationChangeStart", checkLocationChange);
navigationService.addListener(checkNavigationEvent, "before");
}
return {

View File

@ -49,6 +49,7 @@ define(
var self = this;
this.scope = scope;
this.listenHandle = undefined;
// Mutate and persist a new version of a domain object's model.
function doPersist(model) {
@ -100,10 +101,13 @@ define(
// Place the "commit" method in the scope
scope.commit = commit;
scope.setEditable = setEditable;
}
// Handle a specific representation of a specific domain object
EditRepresenter.prototype.represent = function represent(representation, representedObject) {
var scope = this.scope,
self = this;
// Track the key, to know which view configuration to save to.
this.key = (representation || {}).key;
// Track the represented object
@ -113,11 +117,26 @@ define(
// Ensure existing watches are released
this.destroy();
/**
* Listen for changes in object state. If the object becomes
* editable then change the view and inspector regions
* object representation accordingly
*/
this.listenHandle = this.domainObject.getCapability('status').listen(function(statuses){
if (statuses.indexOf('editing')!=-1){
scope.viewRegionTemplate = 'edit-object';
scope.inspectorRegionTemplate = 'inspector-edit'
} else {
delete scope.viewRegionTemplate;
}
});
};
// Respond to the destruction of the current representation.
EditRepresenter.prototype.destroy = function destroy() {
// Nothing to clean up
this.listenHandle && this.listenHandle();
};
return EditRepresenter;