diff --git a/platform/commonUI/edit/src/representers/EditRepresenter.js b/platform/commonUI/edit/src/representers/EditRepresenter.js index 452f85e36d..3face1184d 100644 --- a/platform/commonUI/edit/src/representers/EditRepresenter.js +++ b/platform/commonUI/edit/src/representers/EditRepresenter.js @@ -92,8 +92,14 @@ define( } } + function setEditable(editableDomainObject) { + self.domainObject = editableDomainObject; + scope.model = editableDomainObject.getModel(); + } + // Place the "commit" method in the scope scope.commit = commit; + scope.setEditable = setEditable; } // Handle a specific representation of a specific domain object diff --git a/platform/features/layout/bundle.json b/platform/features/layout/bundle.json index b7cac9ad9e..3f710d4371 100644 --- a/platform/features/layout/bundle.json +++ b/platform/features/layout/bundle.json @@ -19,6 +19,7 @@ "type": "telemetry.panel", "templateUrl": "templates/fixed.html", "uses": [ "composition" ], + "gestures": [ "drop" ], "toolbar": { "sections": [ { diff --git a/platform/features/layout/src/FixedController.js b/platform/features/layout/src/FixedController.js index 77c655e2cb..28ca9c3990 100644 --- a/platform/features/layout/src/FixedController.js +++ b/platform/features/layout/src/FixedController.js @@ -273,12 +273,15 @@ define( } // Position a panel after a drop event - function handleDrop(e, id, position) { + function handleDrop(e, id, position, editableDomainObject) { // Don't handle this event if it has already been handled // color is set to "" to let the CSS theme determine the default color if (e.defaultPrevented) { return; } + if (editableDomainObject){ + $scope.setEditable(editableDomainObject); + } e.preventDefault(); // Store the position of this element. addElement({ diff --git a/platform/features/layout/src/LayoutController.js b/platform/features/layout/src/LayoutController.js index 37f434ba88..a4ff03f021 100644 --- a/platform/features/layout/src/LayoutController.js +++ b/platform/features/layout/src/LayoutController.js @@ -62,10 +62,15 @@ define( } // Position a panel after a drop event - function handleDrop(e, id, position) { + //An editableDomainObject is provided, as the drop may have + // triggered a transition to edit mode. + function handleDrop(e, id, position, editableDomainObject) { if (e.defaultPrevented) { return; } + if (editableDomainObject){ + $scope.setEditable(editableDomainObject); + } // Ensure that configuration field is populated $scope.configuration = $scope.configuration || {}; // Make sure there is a "panels" field in the diff --git a/platform/features/plot/bundle.json b/platform/features/plot/bundle.json index d367c028cb..0ea025bb4f 100644 --- a/platform/features/plot/bundle.json +++ b/platform/features/plot/bundle.json @@ -8,6 +8,7 @@ "glyph": "6", "templateUrl": "templates/plot.html", "needs": [ "telemetry" ], + "gestures": [ "drop" ], "priority": "preferred", "delegation": true } diff --git a/platform/representation/src/gestures/DropGesture.js b/platform/representation/src/gestures/DropGesture.js index 7d20578652..5a8e859b3d 100644 --- a/platform/representation/src/gestures/DropGesture.js +++ b/platform/representation/src/gestures/DropGesture.js @@ -45,12 +45,12 @@ define( function DropGesture(dndService, $q, navigationService, objectService, instantiate, typeService, element, domainObject) { var actionCapability = domainObject.getCapability('action'), editableDomainObject, + scope = element && element.scope && element.scope(), action; // Action for the drop, when it occurs function broadcastDrop(id, event) { // Find the relevant scope... - var scope = element && element.scope && element.scope(), - rect; + var rect; if (scope && scope.$broadcast) { // Get the representation's bounds, to convert // drop position @@ -65,7 +65,8 @@ define( { x: event.pageX - rect.left, y: event.pageY - rect.top - } + }, + editableDomainObject ); } } @@ -148,6 +149,9 @@ define( if (shouldCreateVirtualPanel(domainObject)){ editableDomainObject = createVirtualPanel(domainObject, id); navigationService.setNavigation(editableDomainObject); + //Also broadcast the editableDomainObject to + // avoid race condition against non-editable + // version in EditRepresenter broadcastDrop(id, event); } else { $q.when(action && action.perform()).then(function (result) {