[Representation] Pass ID through dndService

Pass ID as well as full domain object through dndService,
to support drag-drop behavior like WTD-988.
This commit is contained in:
Victor Woeltjen 2015-03-19 12:39:13 -07:00
parent 818510da14
commit f9290b8e42
3 changed files with 25 additions and 3 deletions

View File

@ -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

View File

@ -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.

View File

@ -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 () {