diff --git a/platform/commonUI/edit/src/actions/CancelAction.js b/platform/commonUI/edit/src/actions/CancelAction.js index 1fc5ff3ac1..6b9cbf9c08 100644 --- a/platform/commonUI/edit/src/actions/CancelAction.js +++ b/platform/commonUI/edit/src/actions/CancelAction.js @@ -63,14 +63,10 @@ define( return editor.cancel(); } - // Discard the current root view (which will be the editing - // UI, which will have been pushed atop the Browise UI.) + //Discard current 'editable' object, and retrieve original + // un-edited object. function returnToBrowse() { - self.objectService.getObjects([self.domainObject.getId()]).then(function(objects){ - return self.navigationService.setNavigation(objects[self.domainObject.getId()]); - }) - //return - // self.navigationService.setNavigation(self.domainObject.getDomainObject()); + return self.navigationService.setNavigation(self.domainObject.getOriginalObject()); } return doCancel(getEditorCapability()) diff --git a/platform/commonUI/edit/src/actions/SaveAction.js b/platform/commonUI/edit/src/actions/SaveAction.js index f9f545ed79..9dec2f39aa 100644 --- a/platform/commonUI/edit/src/actions/SaveAction.js +++ b/platform/commonUI/edit/src/actions/SaveAction.js @@ -99,8 +99,9 @@ define( return domainObject.useCapability('composition') .then(function(composees){ return self.$q.all(composees.map(function(composee){ - return object.getCapability('composition').add(composee); - })); + object.getCapability('composition').add(composee); + return object; + })).then(function(){return object}); }); }); } @@ -120,7 +121,9 @@ define( //This is a new 'virtual panel' that has not been persisted // yet. if (domainObject.getModel().type === 'telemetry.panel' && !domainObject.getModel().persisted){ - return self.getObjectService().getObjects([domainObject.getModel().location]).then(function(objs){ doWizardSave(domainObject, objs[domainObject.getModel().location])}); + return self.getObjectService() + .getObjects([domainObject.getModel().location]) + .then(function(objs){ return doWizardSave(domainObject, objs[domainObject.getModel().location])}); } else { return domainObject.getCapability("editor").save(); } @@ -128,8 +131,8 @@ define( // Discard the current root view (which will be the editing // UI, which will have been pushed atop the Browse UI.) - function returnToBrowse() { - return self.navigationService.setNavigation(self.domainObject.getDomainObject()); + function returnToBrowse(object) { + self.navigationService.setNavigation(object) } return doSave().then(returnToBrowse); diff --git a/platform/commonUI/edit/src/objects/EditableDomainObject.js b/platform/commonUI/edit/src/objects/EditableDomainObject.js index ce1faf015e..2c03ff4eec 100644 --- a/platform/commonUI/edit/src/objects/EditableDomainObject.js +++ b/platform/commonUI/edit/src/objects/EditableDomainObject.js @@ -78,7 +78,8 @@ define( // different versions of the same editable domain object // are not shown in different sections of the same Edit // UI, which might thereby fall out of sync. - var cache; + var cache, + originalObject = domainObject; // Constructor for EditableDomainObject, which adheres // to the same shared cache. @@ -101,10 +102,15 @@ define( new Factory(capability, editableObject, domainObject, cache) : capability; }; - - editableObject.getDomainObject = function() { - return domainObject; - } + + + editableObject.setOriginalObject = function(object) { + originalObject = object; + }; + + editableObject.getOriginalObject = function() { + return originalObject; + }; return editableObject; } diff --git a/platform/representation/bundle.json b/platform/representation/bundle.json index cfbf66c393..4017033ad6 100644 --- a/platform/representation/bundle.json +++ b/platform/representation/bundle.json @@ -22,7 +22,7 @@ "key": "drop", "implementation": "gestures/DropGesture.js", "depends": [ "dndService", "$q", "navigationService", - "objectService", "instantiate" ] + "objectService", "instantiate", "typeService" ] }, { "key": "menu", diff --git a/platform/representation/src/gestures/DropGesture.js b/platform/representation/src/gestures/DropGesture.js index cb9ed09970..25505499aa 100644 --- a/platform/representation/src/gestures/DropGesture.js +++ b/platform/representation/src/gestures/DropGesture.js @@ -42,7 +42,7 @@ define( * @param {DomainObject} domainObject the domain object whose * composition should be modified as a result of the drop. */ - function DropGesture(dndService, $q, navigationService, objectService, instantiate, element, domainObject) { + function DropGesture(dndService, $q, navigationService, objectService, instantiate, typeService, element, domainObject) { var actionCapability = domainObject.getCapability('action'), editableDomainObject, action; // Action for the drop, when it occurs @@ -108,16 +108,28 @@ define( } function createVirtualPanel(base, overlayId){ - var model = { - name: 'New telemetry panel', - type: 'telemetry.panel', - composition: [base.getId(), overlayId], - location: base.getModel().location - }, - id = uuid(); + + var typeKey = 'telemetry.panel', + type = typeService.getType(typeKey), + model = type.getInitialModel(), + id = uuid(), + newPanel = undefined; + + model.type = typeKey; + model.name = 'New telemetry panel'; + newPanel = instantiate(model, id); + + [base.getId(), overlayId].forEach(function(id){ + newPanel.getCapability('composition').add(id) + }); + + newPanel.getCapability('location').setPrimaryLocation(base.getCapability('location').getContextualLocation()); + //ObjectService is wrapped by a decorator which is obscuring // the newObject method. - return instantiate(model, id); + var virtualPanel = new EditableDomainObject(newPanel, $q); + virtualPanel.setOriginalObject(base); + return virtualPanel; } @@ -137,8 +149,7 @@ define( // the change. if (id) { if (shouldCreateVirtualPanel(domainObject)){ - virtualObj = new EditableDomainObject(createVirtualPanel(domainObject, id)); - navigationService.setNavigation(virtualObj); + navigationService.setNavigation(createVirtualPanel(domainObject, id)); broadcastDrop(id, event); } else { $q.when(action && action.perform()).then(function (result) {