Group.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2013, 2019
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['./Absolute', '../../../../lib/@waca/dashboard-common/dist/ui/interaction/Utils', 'jquery'], function (BaseLayout, utils, $) {
  8. var PageLayout = null;
  9. PageLayout = BaseLayout.extend({
  10. init: function init() {
  11. PageLayout.inherited('init', this, arguments);
  12. this.specializeConsumeView(['onResize', 'onResizeStep', 'onSelect', 'onDeselect', 'getWidgetPositionUpdate', 'getMinimumTop', 'getMinimumLeft', 'getMaximumHeight', 'getMaximumWidth']);
  13. },
  14. createDropZone: function createDropZone() {
  15. // We do nothing here. We need to disable the absolute layout default dropzone
  16. },
  17. /*
  18. * Return the first ancestor that is not a group
  19. */
  20. getFirstNonGroupAncestorView: function getFirstNonGroupAncestorView() {
  21. var node = null;
  22. var $nestedGroups = $(this.domNode).parents('.pagegroup');
  23. if ($nestedGroups.length > 0) {
  24. node = $nestedGroups[$nestedGroups.length - 1];
  25. } else {
  26. node = this.domNode;
  27. }
  28. return node._layout.parentLayout;
  29. },
  30. onSelect: function onSelect() {
  31. var children = this.model.items;
  32. var child;
  33. for (var i = 0; i < children.length; i++) {
  34. child = this.layoutController.getLayoutView(children[i].id);
  35. if (child && child.onSelect) {
  36. child.onSelect(true); //true [isGroupSelect];
  37. }
  38. }
  39. },
  40. onDeselect: function onDeselect() {
  41. var children = this.model.items;
  42. var child;
  43. for (var i = 0; i < children.length; i++) {
  44. child = this.layoutController.getLayoutView(children[i].id);
  45. if (child && child.onDeselect) {
  46. child.onDeselect();
  47. }
  48. }
  49. },
  50. /**
  51. * Get the position of the group node relative to the first ancestor that is not a group
  52. */
  53. getPositionRelativeToPage: function getPositionRelativeToPage() {
  54. var $node = $(this.domNode);
  55. var positionRelativeToPage = {
  56. x: parseInt($node.css('left'), 10),
  57. y: parseInt($node.css('top'), 10)
  58. };
  59. var $nestedGroups = $node.parents('.pagegroup');
  60. for (var i = 0; i < $nestedGroups.length; i++) {
  61. positionRelativeToPage.x += parseInt($($nestedGroups[i]).css('left'), 10);
  62. positionRelativeToPage.y += parseInt($($nestedGroups[i]).css('top'), 10);
  63. }
  64. return positionRelativeToPage;
  65. },
  66. /**
  67. * Get the minimum left position that a child can have before reaching the left most boundary of the page
  68. */
  69. getMinimumLeft: function getMinimumLeft() {
  70. var positionRelativeToPage = this.getPositionRelativeToPage();
  71. var pageView = this.getFirstNonGroupAncestorView();
  72. return pageView.getMinimumLeft() - positionRelativeToPage.x;
  73. },
  74. /**
  75. * Get the minimum top position that a child can have before reaching the top most boundary of the page
  76. */
  77. getMinimumTop: function getMinimumTop() {
  78. var positionRelativeToPage = this.getPositionRelativeToPage();
  79. var pageView = this.getFirstNonGroupAncestorView();
  80. return pageView.getMinimumTop() - positionRelativeToPage.y;
  81. },
  82. getMaximumWidth: function getMaximumWidth() {
  83. var pageView = this.getFirstNonGroupAncestorView();
  84. var pageMaxWidth = pageView.getMaximumWidth();
  85. if (pageMaxWidth) {
  86. var positionRelativeToPage = this.getPositionRelativeToPage();
  87. pageMaxWidth = pageMaxWidth - positionRelativeToPage.x;
  88. }
  89. return pageMaxWidth;
  90. },
  91. getMaximumHeight: function getMaximumHeight() {
  92. var pageView = this.getFirstNonGroupAncestorView();
  93. var pageMaxHeight = pageView.getMaximumHeight();
  94. if (pageMaxHeight) {
  95. var positionRelativeToPage = this.getPositionRelativeToPage();
  96. pageMaxHeight = pageMaxHeight - positionRelativeToPage.y;
  97. }
  98. return pageMaxHeight;
  99. }
  100. });
  101. return PageLayout;
  102. });
  103. //# sourceMappingURL=Group.js.map