From f9290b8e4297869bcf9064b8b185573f9792e453 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 19 Mar 2015 12:39:13 -0700 Subject: [PATCH] [Representation] Pass ID through dndService Pass ID as well as full domain object through dndService, to support drag-drop behavior like WTD-988. --- .../representation/src/gestures/DragGesture.js | 14 +++++++++++--- .../src/gestures/GestureConstants.js | 6 ++++++ .../test/gestures/DragGestureSpec.js | 8 ++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/platform/representation/src/gestures/DragGesture.js b/platform/representation/src/gestures/DragGesture.js index 1b70a76dd4..c5d9c94494 100644 --- a/platform/representation/src/gestures/DragGesture.js +++ b/platform/representation/src/gestures/DragGesture.js @@ -45,12 +45,19 @@ define( domainObject.getId() ); - // Finally, also pass the object instance via the dndService, - // so more than the ID can be retrieved (if desired) + // Finally, also pass the id object instance via the + // dndService, allowing inspection during drag as well + // as retrieval of the original domain object. dndService.setData( - GestureConstants.MCT_DRAG_TYPE, + GestureConstants.MCT_EXTENDED_DRAG_TYPE, domainObject ); + dndService.setData( + GestureConstants.MCT_DRAG_TYPE, + domainObject.getId() + ); + + } catch (err) { // Exceptions at this point indicate that the browser // do not fully support drag-and-drop (e.g. if @@ -66,6 +73,7 @@ define( function endDrag() { // Clear the drag data after the drag is complete dndService.removeData(GestureConstants.MCT_DRAG_TYPE); + dndService.removeData(GestureConstants.MCT_EXTENDED_DRAG_TYPE); } // Mark the element as draggable, and handle the dragstart event diff --git a/platform/representation/src/gestures/GestureConstants.js b/platform/representation/src/gestures/GestureConstants.js index 126a7b3981..b9a8162ae9 100644 --- a/platform/representation/src/gestures/GestureConstants.js +++ b/platform/representation/src/gestures/GestureConstants.js @@ -10,6 +10,12 @@ define({ * calls.) */ MCT_DRAG_TYPE: 'mct-domain-object-id', + /** + * The string identifier for the data type used for drag-and-drop + * composition of domain objects, by object instance (passed through + * the dndService) + */ + MCT_EXTENDED_DRAG_TYPE: 'mct-domain-object', /** * An estimate for the dimensions of a context menu, used for * positioning. diff --git a/platform/representation/test/gestures/DragGestureSpec.js b/platform/representation/test/gestures/DragGestureSpec.js index cb7435061f..f1c6358db7 100644 --- a/platform/representation/test/gestures/DragGestureSpec.js +++ b/platform/representation/test/gestures/DragGestureSpec.js @@ -65,6 +65,10 @@ define( handlers.dragstart({ dataTransfer: mockDataTransfer }); expect(mockDndService.setData).toHaveBeenCalledWith( GestureConstants.MCT_DRAG_TYPE, + TEST_ID + ); + expect(mockDndService.setData).toHaveBeenCalledWith( + GestureConstants.MCT_EXTENDED_DRAG_TYPE, mockDomainObject ); }); @@ -78,8 +82,12 @@ define( // End the drag handlers.dragend({ dataTransfer: mockDataTransfer }); + + // Should have removed the data that was attached expect(mockDndService.removeData) .toHaveBeenCalledWith(GestureConstants.MCT_DRAG_TYPE); + expect(mockDndService.removeData) + .toHaveBeenCalledWith(GestureConstants.MCT_EXTENDED_DRAG_TYPE); }); it("logs a warning if dataTransfer cannot be set", function () {