jpc_helper_band.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. 'use strict';
  2. const JV = require('../jpc_value_define');
  3. const JpcCommonHelper = require('./jpc_helper_common');
  4. const JpcBandHelper = {
  5. getBandTypeValByString: function(bandType) {
  6. let rst = JV.PAGE_STATUS.indexOf(bandType);
  7. if (rst < 0) rst = JV.STATUS_NORMAL;
  8. return rst;
  9. },
  10. setBandArea: function(bands, rptTpl, pageStatus, isOnlyNormalStatus, isOnlyExStatus) {
  11. const me = this;
  12. if (rptTpl[JV.NODE_BAND_COLLECTION]) {
  13. isOnlyNormalStatus = isOnlyNormalStatus || false;
  14. isOnlyExStatus = isOnlyExStatus || false;
  15. const unitFactor = JpcCommonHelper.getUnitFactor(rptTpl);
  16. const orgArea = JpcCommonHelper.getReportArea(rptTpl, unitFactor);
  17. for (let i = 0; i < rptTpl[JV.NODE_BAND_COLLECTION].length; i++) {
  18. me.setBandPos(bands, rptTpl[JV.NODE_BAND_COLLECTION][i], orgArea, unitFactor, pageStatus, isOnlyNormalStatus, isOnlyExStatus);
  19. }
  20. }
  21. },
  22. setBandPos: function(bands, bandNode, orgArea, unitFactor, pageStatus, isOnlyNormalStatus, isOnlyExStatus) {
  23. const me = this;
  24. const band = bands[bandNode[JV.BAND_PROP_NAME]];
  25. // 0. for multi flow purpose
  26. if (isOnlyNormalStatus) {
  27. if (bandNode.hasOwnProperty(JV.PROP_BAND_EX_ONLY) && JpcCommonHelper.getBoolean(bandNode[JV.PROP_BAND_EX_ONLY])) {
  28. return;
  29. }
  30. }
  31. if (isOnlyExStatus) {
  32. if (bandNode.hasOwnProperty(JV.PROP_BAND_NORMAL_ONLY) && !(JpcCommonHelper.getBoolean(bandNode[JV.PROP_BAND_NORMAL_ONLY]))) {
  33. return;
  34. }
  35. }
  36. // 1. initialize
  37. band[JV.PROP_LEFT] = orgArea[JV.IDX_LEFT];
  38. band[JV.PROP_TOP] = orgArea[JV.IDX_TOP];
  39. band[JV.PROP_RIGHT] = orgArea[JV.IDX_RIGHT];
  40. band[JV.PROP_BOTTOM] = orgArea[JV.IDX_BOTTOM];
  41. // 2. set this band
  42. if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]]) {
  43. switch (band[JV.BAND_PROP_ALIGNMENT]) {
  44. case JV.LAYOUT_TOP:
  45. if (band[JV.PROP_CALCULATION] === JV.CAL_TYPE_ABSTRACT) {
  46. band.Bottom = band.Top + unitFactor * band[JV.BAND_PROP_HEIGHT];
  47. } else {
  48. band.Bottom = band.Top + (band.Bottom - band.Top) * band[JV.BAND_PROP_HEIGHT] / 100;
  49. }
  50. orgArea[JV.IDX_TOP] = band.Bottom;
  51. break;
  52. case JV.LAYOUT_BOTTOM:
  53. if (band[JV.PROP_CALCULATION] === JV.CAL_TYPE_ABSTRACT) {
  54. band.Top = band.Bottom - unitFactor * band[JV.BAND_PROP_HEIGHT];
  55. } else {
  56. band.Top = band.Bottom - (band.Bottom - band.Top) * band[JV.BAND_PROP_HEIGHT] / 100;
  57. }
  58. orgArea[JV.IDX_BOTTOM] = band.Top;
  59. break;
  60. case JV.LAYOUT_LEFT:
  61. if (band[JV.PROP_CALCULATION] === JV.CAL_TYPE_ABSTRACT) {
  62. band.Right = band.Left + unitFactor * band[JV.BAND_PROP_WIDTH];
  63. } else {
  64. band.Right = band.Left + (band.Right - band.Left) * band[JV.BAND_PROP_WIDTH] / 100;
  65. }
  66. orgArea[JV.IDX_LEFT] = band.Right;
  67. break;
  68. case JV.LAYOUT_RIGHT:
  69. if (band[JV.PROP_CALCULATION] === JV.CAL_TYPE_ABSTRACT) {
  70. band.Left = band.Right - unitFactor * band[JV.BAND_PROP_WIDTH];
  71. } else {
  72. band.Left = band.Right - (band.Right - band.Left) * band[JV.BAND_PROP_WIDTH] / 100;
  73. }
  74. orgArea[JV.IDX_RIGHT] = band.Left;
  75. break;
  76. default:
  77. break;
  78. }
  79. // 3. set sub-bands
  80. if (bandNode[JV.BAND_PROP_SUB_BANDS]) {
  81. const bandArea = [band.Left, band.Top, band.Right, band.Bottom];
  82. for (let i = 0; i < bandNode[JV.BAND_PROP_SUB_BANDS].length; i++) {
  83. me.setBandPos(bands, bandNode[JV.BAND_PROP_SUB_BANDS][i], bandArea, unitFactor, pageStatus, isOnlyNormalStatus, isOnlyExStatus);
  84. }
  85. }
  86. }
  87. },
  88. resetBandPos: function(bandCollection, bands, contentBand, offsetX, offsetY) {
  89. const orgX = contentBand.Right;
  90. const orgY = contentBand.Bottom;
  91. function chkAndResetPos(targetBand) {
  92. const band = bands[targetBand.Name];
  93. if (band) {
  94. if (band === contentBand) {
  95. band.Bottom += offsetY;
  96. band.Right += offsetX;
  97. } else {
  98. if (band.Top >= orgY) {
  99. band.Top += offsetY;
  100. band.Bottom += offsetY;
  101. } else if (band.Bottom >= orgY && band.Top < orgY) {
  102. band.Bottom += offsetY;
  103. }
  104. if (band.Left >= orgX) {
  105. band.Left += offsetX;
  106. band.Right += offsetX;
  107. } else if (band.Right >= orgX && band.Le < orgX) {
  108. band.Right += offsetX;
  109. }
  110. }
  111. if (targetBand[JV.BAND_PROP_SUB_BANDS]) {
  112. for (let i = 0; i < targetBand[JV.BAND_PROP_SUB_BANDS].length; i++) {
  113. chkAndResetPos(targetBand[JV.BAND_PROP_SUB_BANDS][i]);
  114. }
  115. }
  116. }
  117. }
  118. for (let i = 0; i < bandCollection.length; i++) {
  119. chkAndResetPos(bandCollection[i]);
  120. }
  121. },
  122. };
  123. module.exports = JpcBandHelper;