From 6e783648d6fca7d0cc76f659d2c67c074778c5ea Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 17 Mar 2015 18:11:46 -0700 Subject: [PATCH] [Edit] Hide root object Act as if the object being edited is the root object when in Edit mode, except in the Library pane (which has its own means of getting the real root object.) WTD-922. --- .../capabilities/EditableContextCapability.js | 17 ++++++++++++++++- .../edit/src/controllers/EditPanesController.js | 2 +- .../src/objects/EditableDomainObjectCache.js | 16 +++++++++++++++- .../core/src/capabilities/ContextCapability.js | 6 +++++- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/platform/commonUI/edit/src/capabilities/EditableContextCapability.js b/platform/commonUI/edit/src/capabilities/EditableContextCapability.js index a21dc9ba31..4880c0072e 100644 --- a/platform/commonUI/edit/src/capabilities/EditableContextCapability.js +++ b/platform/commonUI/edit/src/capabilities/EditableContextCapability.js @@ -23,13 +23,28 @@ define( ) { // This is a "lookup" style capability (it looks up other // domain objects), and it should be idempotent - return new EditableLookupCapability( + var capability = new EditableLookupCapability( contextCapability, editableObject, domainObject, cache, true // Idempotent ); + + // Provide access to the real root, for the Elements pane. + capability.getTrueRoot = capability.getRoot; + + // Hide ancestry after the root of this subgraph + if (cache.isRoot(domainObject)) { + capability.getRoot = function () { + return editableObject; + }; + capability.getPath = function () { + return [editableObject]; + }; + } + + return capability; }; } ); \ No newline at end of file diff --git a/platform/commonUI/edit/src/controllers/EditPanesController.js b/platform/commonUI/edit/src/controllers/EditPanesController.js index eece0471be..6962004b7f 100644 --- a/platform/commonUI/edit/src/controllers/EditPanesController.js +++ b/platform/commonUI/edit/src/controllers/EditPanesController.js @@ -16,7 +16,7 @@ define( function updateRoot(domainObject) { var context = domainObject && domainObject.getCapability('context'), - newRoot = context && context.getRoot(), + newRoot = context && context.getRealRoot(), oldId = root && root.getId(), newId = newRoot && newRoot.getId(); diff --git a/platform/commonUI/edit/src/objects/EditableDomainObjectCache.js b/platform/commonUI/edit/src/objects/EditableDomainObjectCache.js index 6673e31998..3509b9675a 100644 --- a/platform/commonUI/edit/src/objects/EditableDomainObjectCache.js +++ b/platform/commonUI/edit/src/objects/EditableDomainObjectCache.js @@ -34,7 +34,8 @@ define( */ function EditableDomainObjectCache(EditableDomainObject) { var cache = new EditableModelCache(), - dirty = {}; + dirty = {}, + root; return { /** @@ -45,11 +46,24 @@ define( * @returns {DomainObject} the domain object in an editable form */ getEditableObject: function (domainObject) { + // Track the top-level domain object; this will have + // some special behavior for its context capability. + root = root || domainObject; + + // Provide an editable form of the object return new EditableDomainObject( domainObject, cache.getCachedModel(domainObject) ); }, + /** + * Check if a domain object is (effectively) the top-level + * object in this editable subgraph. + * @returns {boolean} true if it is the root + */ + isRoot: function (domainObject) { + return domainObject === root; + }, /** * Mark an editable domain object (presumably already cached) * as having received modifications during editing; it should be diff --git a/platform/core/src/capabilities/ContextCapability.js b/platform/core/src/capabilities/ContextCapability.js index b46708bef4..c1e6b9c5a7 100644 --- a/platform/core/src/capabilities/ContextCapability.js +++ b/platform/core/src/capabilities/ContextCapability.js @@ -76,7 +76,11 @@ define( * object which exposed this capability. */ getRoot: function () { - return this.getPath()[0]; + var parentContext = parentObject && + parentObject.getCapability('context'); + + return parentContext ? + parentContext.getRoot() : domainObject; } }; }