From 10a44c026c126d2dad688f85d6df9780f99d5945 Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 19 Nov 2015 18:45:18 -0800 Subject: [PATCH] [Edit Mode] Visual indication of object being edited #278 --- .../edit/src/capabilities/EditorCapability.js | 7 ++++++- .../commonUI/edit/src/objects/EditableDomainObject.js | 1 - .../edit/src/objects/EditableDomainObjectCache.js | 11 ++++++++++- .../commonUI/general/res/templates/tree-node.html | 2 +- .../general/src/controllers/TreeNodeController.js | 9 +++++++++ 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/platform/commonUI/edit/src/capabilities/EditorCapability.js b/platform/commonUI/edit/src/capabilities/EditorCapability.js index 7094d1142c..62ae9fadc1 100644 --- a/platform/commonUI/edit/src/capabilities/EditorCapability.js +++ b/platform/commonUI/edit/src/capabilities/EditorCapability.js @@ -80,6 +80,7 @@ define( EditorCapability.prototype.save = function (nonrecursive) { var domainObject = this.domainObject, editableObject = this.editableObject, + self = this, cache = this.cache; // Update the underlying, "real" domain object's model @@ -95,8 +96,10 @@ define( return domainObject.getCapability('persistence').persist(); } + editableObject.getCapability("status").set("editing", false); + return nonrecursive ? - resolvePromise(doMutate()).then(doPersist) : + resolvePromise(doMutate()).then(doPersist).then(function(){self.cancel()}) : resolvePromise(cache.saveAll()); }; @@ -109,6 +112,8 @@ define( * @memberof platform/commonUI/edit.EditorCapability# */ EditorCapability.prototype.cancel = function () { + this.editableObject.getCapability("status").set("editing", false); + //TODO: Reset the cache as well here. return resolvePromise(undefined); }; diff --git a/platform/commonUI/edit/src/objects/EditableDomainObject.js b/platform/commonUI/edit/src/objects/EditableDomainObject.js index 2c03ff4eec..8c15b2efed 100644 --- a/platform/commonUI/edit/src/objects/EditableDomainObject.js +++ b/platform/commonUI/edit/src/objects/EditableDomainObject.js @@ -116,7 +116,6 @@ define( } cache = new EditableDomainObjectCache(EditableDomainObjectImpl, $q); - return cache.getEditableObject(domainObject); } diff --git a/platform/commonUI/edit/src/objects/EditableDomainObjectCache.js b/platform/commonUI/edit/src/objects/EditableDomainObjectCache.js index c724c601d8..2a9d2d2643 100644 --- a/platform/commonUI/edit/src/objects/EditableDomainObjectCache.js +++ b/platform/commonUI/edit/src/objects/EditableDomainObjectCache.js @@ -70,7 +70,8 @@ define( EditableDomainObjectCache.prototype.getEditableObject = function (domainObject) { var type = domainObject.getCapability('type'), EditableDomainObject = this.EditableDomainObject, - editableObject; + editableObject, + statusListener; // Track the top-level domain object; this will have // some special behavior for its context capability. @@ -92,6 +93,14 @@ define( this.cache.getCachedModel(domainObject) ); editableObject.getCapability("status").set('editing', true); + if (!this.isRoot(domainObject)){ + statusListener = this.root.getCapability("status").listen(function(statuses){ + if (statuses.indexOf("editing") < 0 ){ + editableObject.getCapability("status").set("editing", false); + statusListener(); + } + }); + } return editableObject; }; diff --git a/platform/commonUI/general/res/templates/tree-node.html b/platform/commonUI/general/res/templates/tree-node.html index 885646d606..2538ab31ae 100644 --- a/platform/commonUI/general/res/templates/tree-node.html +++ b/platform/commonUI/general/res/templates/tree-node.html @@ -23,7 +23,7 @@ =0; + + //TODO: Temporary hack until css classes are defined for status + // change + $scope.domainObject.getCapability('status').listen(function(status){ + $scope.editing = status.indexOf('editing') >=0; + }); + // Listen for changes which will effect display parameters $scope.$watch("ngModel.selectedObject", setSelection); $scope.$watch("domainObject", checkSelection);