jpc_helper_band.js 5.1 KB

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