DnDHelper.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use strict';
  2. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2016, 2019
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. *
  8. * Drag-and-Drop Manager
  9. */
  10. define([], function () {
  11. var DnDHelper = {
  12. _id: null,
  13. /** Handles drag'n'drop for when the user drags a widget on to something that isn't the actual target, but rather
  14. * is another page. Examples where it is used include when dragging a widget on to a frame in the filmstrip (for a story) or
  15. * a tab in a tabbed dashboard.
  16. * @param canvas - the canvasAPI
  17. * @param parentId - The id (string) that the widget is dropped on to.
  18. * @param dragObject - the widget being dragged.
  19. */
  20. handleWidgetDrop: function handleWidgetDrop(canvas, parentId, dragObject) {
  21. if (canvas) {
  22. if (dragObject.data.operation === 'new') {
  23. var widgetContent = this._prepareWidgetContent(parentId, dragObject);
  24. canvas.addContent(widgetContent);
  25. } else if (dragObject.data.operation === 'move') {
  26. var contentIdList = this._getContentIdList(dragObject);
  27. canvas.moveContent(parentId, contentIdList);
  28. }
  29. }
  30. },
  31. /** Prepares a drag'n'drop widget for 'blind' drops, such as when we drag a widget on to
  32. * a frame in the film strip that isn't the currently selected one.
  33. */
  34. _prepareWidgetContent: function _prepareWidgetContent(parentId, dragObject) {
  35. var layoutProperties = dragObject.data.layoutProperties.style || {};
  36. var widgetContent = {
  37. containerId: parentId,
  38. layout: _extends({}, layoutProperties),
  39. spec: _extends({
  40. style: layoutProperties
  41. }, dragObject.widgetSpec.model)
  42. };
  43. return widgetContent;
  44. },
  45. _getContentIdList: function _getContentIdList(dragObject) {
  46. var nodesInfoList = dragObject.data && dragObject.data.nodeInfoList;
  47. var contentIdList = nodesInfoList.map(function (nodesInfo) {
  48. if (nodesInfo && nodesInfo.node && nodesInfo.node._layout) {
  49. return nodesInfo.node._layout.model && nodesInfo.node._layout.model.id;
  50. }
  51. });
  52. return contentIdList;
  53. }
  54. };
  55. return DnDHelper;
  56. });
  57. //# sourceMappingURL=DnDHelper.js.map