rpt_tpl_band.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. onBeforeRemove: function(treeId, treeNode){
  170. let rst = true;
  171. if (treeNode.band_s && treeNode.band_s.length > 0) {
  172. rst = false;
  173. } else {
  174. rst = confirm("在删除前请确认报表模板内部没有引用,否则会造成混淆。");
  175. }
  176. return rst;
  177. },
  178. setupWidthHeightByPosition: function (posIdx) {
  179. let me = this, treeNode = me.currentNode;
  180. switch(posIdx) {
  181. case 0:
  182. case 1:
  183. $("#bandHeight").get(0).disabled = false;
  184. $("#bandHeight").get(0).value = treeNode[JV.BAND_PROP_HEIGHT];
  185. $("#bandWidth").get(0).disabled = true;
  186. $("#bandWidth").get(0).value = "";
  187. break;
  188. case 2:
  189. case 3:
  190. $("#bandHeight").get(0).disabled = true;
  191. $("#bandHeight").get(0).value = "";
  192. $("#bandWidth").get(0).disabled = false;
  193. $("#bandWidth").get(0).value = treeNode[JV.BAND_PROP_WIDTH];
  194. break;
  195. default:
  196. $("#bandHeight").get(0).disabled = true;
  197. $("#bandHeight").get(0).value = "";
  198. $("#bandWidth").get(0).disabled = true;
  199. $("#bandWidth").get(0).value = "";
  200. break;
  201. }
  202. },
  203. bandStyleChange: function (dom) {
  204. let me = this;
  205. if (me.currentNode) {
  206. me.currentNode[JV.PROP_STYLE] = rpt_tpl_cfg_helper.reportCfg.borderArr[dom.selectedIndex];
  207. }
  208. },
  209. bandAlignmentChange: function (dom) {
  210. let me = this;
  211. if (me.currentNode) {
  212. let posIdx = dom.selectedIndex;
  213. me.currentNode[JV.BAND_PROP_ALIGNMENT] = JV.LAYOUT[posIdx];
  214. me.setupWidthHeightByPosition(posIdx);
  215. }
  216. },
  217. bandHeightWidthChange: function (dom) {
  218. let me = this, treeNode = me.currentNode;
  219. if (me.currentNode) {
  220. let posIdx = $("#bandAlignment").get(0).selectedIndex;
  221. switch(posIdx) {
  222. case 0:
  223. case 1:
  224. treeNode[JV.BAND_PROP_HEIGHT] = dom.value;
  225. break;
  226. case 2:
  227. case 3:
  228. treeNode[JV.BAND_PROP_WIDTH] = dom.value;
  229. break;
  230. }
  231. }
  232. },
  233. bandShowFrequencyChange: function (dom) {
  234. let me = this;
  235. if (me.currentNode) {
  236. me.currentNode[JV.BAND_PROP_DISPLAY_TYPE] = JV.PAGE_STATUS[dom.selectedIndex];
  237. }
  238. },
  239. bandBorderMergeChange: function (dom) {
  240. let me = this;
  241. if (me.currentNode) {
  242. me.currentNode[JV.BAND_PROP_MERGE_BORDER] = dom.checked?'T':'F';
  243. }
  244. },
  245. extractBands: function (rptTpl) {
  246. let me = this;
  247. if (rptTpl) {
  248. let newBandList = [];
  249. for (let node of me.treeObj.getNodes()) {
  250. newBandList.push(me.createBandFromNode(node));
  251. }
  252. rptTpl[JV.NODE_BAND_COLLECTION] = newBandList;
  253. }
  254. }
  255. };