rpt_tpl_band.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. 'use strict'
  2. let bandTreeOprObj = {
  3. treeObj : null,
  4. currentNode: null,
  5. innerCounter: 1,
  6. canTrickEvent: false,
  7. iniTree: function(rptTpl) {
  8. var me = this;
  9. let bandList = rptTpl[JV.NODE_BAND_COLLECTION];
  10. me.buildTreeData(bandList);
  11. me.treeObj = $.fn.zTree.init($("#band_tree_reversed"), bandSetting, bandList);
  12. me.treeObj.expandAll(true);
  13. },
  14. copyBandList: function (isAllParent) {
  15. let me = this, rst = null;
  16. if (me.treeObj) {
  17. rst = [];
  18. let nodes = me.treeObj.getNodes();
  19. let private_copy_nodes = function (parentNode, item) {
  20. item[JV.PROP_ID] = parentNode[JV.PROP_ID];
  21. item[JV.BAND_PROP_NAME] = parentNode[JV.BAND_PROP_NAME];
  22. item[JV.BAND_PROP_STYLE] = parentNode[JV.BAND_PROP_STYLE];
  23. item[JV.BAND_PROP_CONTROL] = parentNode[JV.BAND_PROP_CONTROL];
  24. if (parentNode[JV.BAND_PROP_HEIGHT]) item[JV.BAND_PROP_HEIGHT] = parentNode[JV.BAND_PROP_HEIGHT];
  25. if (parentNode[JV.BAND_PROP_WIDTH]) item[JV.BAND_PROP_WIDTH] = parentNode[JV.BAND_PROP_WIDTH];
  26. item[JV.BAND_PROP_DISPLAY_TYPE] = parentNode[JV.BAND_PROP_DISPLAY_TYPE];
  27. item[JV.BAND_PROP_ALIGNMENT] = parentNode[JV.BAND_PROP_ALIGNMENT];
  28. item[JV.BAND_PROP_MERGE_BORDER] = parentNode[JV.BAND_PROP_MERGE_BORDER];
  29. if (isAllParent) item.isParent = true;
  30. if (parentNode[JV.BAND_PROP_SUB_BANDS]) {
  31. item.items = [];
  32. for (let subNode of parentNode[JV.BAND_PROP_SUB_BANDS]) {
  33. let subItem = {};
  34. private_copy_nodes(subNode, subItem);
  35. item.items.push(subItem);
  36. }
  37. }
  38. }
  39. for (let node of nodes) {
  40. let item = {};
  41. if (isAllParent) item.isParent = true;
  42. private_copy_nodes(node, item);
  43. rst.push(item);
  44. }
  45. } else {
  46. console.log("the band tree is not ready!");
  47. }
  48. return rst;
  49. },
  50. buildTreeData: function(bandList){
  51. let rst = [], startIdx = 1;
  52. //zTreeHelper.createTree(result, setting, "rptTplTree", me);
  53. let private_setBandId = function (parentBand) {
  54. if (parentBand[JV.BAND_PROP_SUB_BANDS]) {
  55. for (let band of parentBand[JV.BAND_PROP_SUB_BANDS]) {
  56. band.ID = startIdx;
  57. band.ParentID = parentBand.ID;
  58. startIdx++;
  59. private_setBandId(band);
  60. }
  61. }
  62. }
  63. for (let band of bandList) {
  64. band.ID = startIdx;
  65. band.ParentID = -1;
  66. startIdx++;
  67. private_setBandId(band);
  68. }
  69. return rst;
  70. },
  71. createBandFromNode: function(node) {
  72. let me = this, rst = {};
  73. rst[JV.BAND_PROP_ALIGNMENT] = node[JV.BAND_PROP_ALIGNMENT];
  74. rst[JV.BAND_PROP_DISPLAY_TYPE] = node[JV.BAND_PROP_DISPLAY_TYPE];
  75. let posIdx = JV.LAYOUT.indexOf(node[JV.BAND_PROP_ALIGNMENT])
  76. switch(posIdx) {
  77. case 0:
  78. case 1:
  79. rst[JV.BAND_PROP_HEIGHT] = node[JV.BAND_PROP_HEIGHT];
  80. break;
  81. case 2:
  82. case 3:
  83. rst[JV.BAND_PROP_WIDTH] = node[JV.BAND_PROP_WIDTH];
  84. break;
  85. }
  86. rst[JV.PROP_NAME] = node[JV.PROP_NAME];
  87. rst[JV.PROP_CONTROL] = node[JV.PROP_CONTROL];
  88. rst[JV.PROP_STYLE] = node[JV.PROP_STYLE];
  89. if (node[JV.BAND_PROP_MERGE_BORDER] !== undefined) {
  90. rst[JV.BAND_PROP_MERGE_BORDER] = node[JV.BAND_PROP_MERGE_BORDER];
  91. } else {
  92. rst[JV.BAND_PROP_MERGE_BORDER] = 'F';
  93. }
  94. if (node[JV.BAND_PROP_SUB_BANDS]) {
  95. rst[JV.BAND_PROP_SUB_BANDS] = [];
  96. for (let subNode of node[JV.BAND_PROP_SUB_BANDS]) {
  97. rst[JV.BAND_PROP_SUB_BANDS].push(me.createBandFromNode(subNode));
  98. }
  99. }
  100. return rst;
  101. },
  102. createDftBand: function () {
  103. let me = this, rst = {};
  104. rst[JV.BAND_PROP_ALIGNMENT] = 'Top';
  105. rst[JV.BAND_PROP_DISPLAY_TYPE] = 'EveryPage';
  106. rst[JV.BAND_PROP_HEIGHT] = '3';
  107. rst[JV.PROP_NAME] = 'newBand_' + me.innerCounter;
  108. me.innerCounter++;
  109. rst[JV.PROP_CONTROL] = 'Default';
  110. rst[JV.PROP_STYLE] = 'Default_None';
  111. rst[JV.BAND_PROP_MERGE_BORDER] = 'F';
  112. return rst;
  113. },
  114. addRootBand: function (rptTpl) {
  115. let me = this;
  116. if (rptTpl) {
  117. let newBand = me.createDftBand();
  118. let newNodes = [], isSilent = false;
  119. newNodes.push(newBand);
  120. if (me.treeObj) {
  121. me.treeObj.addNodes(null, -1, newNodes, isSilent);
  122. } else {
  123. me.treeObj = $.fn.zTree.init($("#band_tree_reversed"), bandSetting, newNodes);
  124. }
  125. }
  126. },
  127. addSubBand: function (rptTpl) {
  128. let me = this;
  129. if (rptTpl && me.currentNode != null) {
  130. let newBand = me.createDftBand();
  131. let newNodes = [], isSilent = false;
  132. newNodes.push(newBand);
  133. me.treeObj.addNodes(me.currentNode, -1, newNodes, isSilent);
  134. }
  135. },
  136. moveDownBand: function (rptTpl) {
  137. let me = bandTreeOprObj;
  138. if (rptTpl && me.currentNode && me.currentNode.getNextNode()) {
  139. let nextNode = me.currentNode.getNextNode();
  140. me.treeObj.moveNode(nextNode, me.currentNode, "next", true);
  141. }
  142. },
  143. moveUpBand: function (rptTpl) {
  144. let me = bandTreeOprObj;
  145. if (rptTpl && me.currentNode && me.currentNode.getPreNode()) {
  146. let preNode = me.currentNode.getPreNode();
  147. me.treeObj.moveNode(preNode, me.currentNode, "prev", true);
  148. }
  149. },
  150. onClick: function(event,treeId,treeNode) {
  151. let me = bandTreeOprObj;
  152. me.currentNode = treeNode;
  153. me.canTrickEvent = false;
  154. //then refresh the band tab properties
  155. //边框样式borderStyles
  156. $("#borderStyles").get(0).selectedIndex = rpt_tpl_cfg_helper.reportCfg.borderArr.indexOf(treeNode[JV.PROP_STYLE]);
  157. //边框合并
  158. $("#mergeBandBorder").get(0).checked = stringUtil.convertStrToBoolean(treeNode[JV.BAND_PROP_MERGE_BORDER]);
  159. //位置
  160. let posIdx = JV.LAYOUT.indexOf(treeNode[JV.BAND_PROP_ALIGNMENT])
  161. $("#bandAlignment").get(0).selectedIndex = posIdx;
  162. //高与宽
  163. me.setupWidthHeightByPosition(posIdx);
  164. //频率
  165. $("#pageFrequency").get(0).selectedIndex = JV.PAGE_STATUS.indexOf(treeNode[JV.BAND_PROP_DISPLAY_TYPE])
  166. //
  167. me.canTrickEvent = true;
  168. },
  169. setupWidthHeightByPosition: function (posIdx) {
  170. let me = this, treeNode = me.currentNode;
  171. switch(posIdx) {
  172. case 0:
  173. case 1:
  174. $("#bandHeight").get(0).disabled = false;
  175. $("#bandHeight").get(0).value = treeNode[JV.BAND_PROP_HEIGHT];
  176. $("#bandWidth").get(0).disabled = true;
  177. $("#bandWidth").get(0).value = "";
  178. break;
  179. case 2:
  180. case 3:
  181. $("#bandHeight").get(0).disabled = true;
  182. $("#bandHeight").get(0).value = "";
  183. $("#bandWidth").get(0).disabled = false;
  184. $("#bandWidth").get(0).value = treeNode[JV.BAND_PROP_WIDTH];
  185. break;
  186. default:
  187. $("#bandHeight").get(0).disabled = true;
  188. $("#bandHeight").get(0).value = "";
  189. $("#bandWidth").get(0).disabled = true;
  190. $("#bandWidth").get(0).value = "";
  191. break;
  192. }
  193. },
  194. bandStyleChange: function (dom) {
  195. let me = this;
  196. if (me.currentNode) {
  197. me.currentNode[JV.PROP_STYLE] = rpt_tpl_cfg_helper.reportCfg.borderArr[dom.selectedIndex];
  198. }
  199. },
  200. bandAlignmentChange: function (dom) {
  201. let me = this;
  202. if (me.currentNode) {
  203. let posIdx = dom.selectedIndex;
  204. me.currentNode[JV.BAND_PROP_ALIGNMENT] = JV.LAYOUT[posIdx];
  205. me.setupWidthHeightByPosition(posIdx);
  206. }
  207. },
  208. bandHeightWidthChange: function (dom) {
  209. let me = this, treeNode = me.currentNode;
  210. if (me.currentNode) {
  211. let posIdx = $("#bandAlignment").get(0).selectedIndex;
  212. switch(posIdx) {
  213. case 0:
  214. case 1:
  215. treeNode[JV.BAND_PROP_HEIGHT] = dom.value;
  216. break;
  217. case 2:
  218. case 3:
  219. treeNode[JV.BAND_PROP_WIDTH] = dom.value;
  220. break;
  221. }
  222. }
  223. },
  224. bandShowFrequencyChange: function (dom) {
  225. let me = this;
  226. if (me.currentNode) {
  227. me.currentNode[JV.BAND_PROP_DISPLAY_TYPE] = JV.PAGE_STATUS[dom.selectedIndex];
  228. }
  229. },
  230. bandBorderMergeChange: function (dom) {
  231. let me = this;
  232. if (me.currentNode) {
  233. me.currentNode[JV.BAND_PROP_MERGE_BORDER] = dom.checked?'T':'F';
  234. }
  235. },
  236. extractBands: function (rptTpl) {
  237. let me = this;
  238. if (rptTpl) {
  239. let newBandList = [];
  240. for (let node of me.treeObj.getNodes()) {
  241. newBandList.push(me.createBandFromNode(node));
  242. }
  243. rptTpl[JV.NODE_BAND_COLLECTION] = newBandList;
  244. }
  245. }
  246. };