rpt_tpl_band.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. 'use strict'
  2. let bandTreeOprObj = {
  3. treeObj : null,
  4. currentNode: null,
  5. innerCounter: 1,
  6. canTrickEvent: false,
  7. iniTree: function(rptTpl) {
  8. let me = bandTreeOprObj;
  9. let bandList = rptTpl[JV.NODE_BAND_COLLECTION];
  10. me.buildTreeData(bandList);
  11. let rootNode = {Name: "布局框(勾选表示:此布局框是报表外框,受报表边框属性影响)", isParent: true};
  12. rootNode[JV.BAND_PROP_SUB_BANDS] = bandList;
  13. // me.treeObj = $.fn.zTree.init($("#band_tree_reversed"), bandSetting, bandList);
  14. me.treeObj = $.fn.zTree.init($("#band_tree_reversed"), bandSetting, rootNode);
  15. me.treeObj.expandAll(true);
  16. me.setupMergeBorderChk();
  17. },
  18. setupMergeBorderChk: function() {
  19. let me = bandTreeOprObj;
  20. let nodes = me.treeObj.getNodes();
  21. me.treeObj.setChkDisabled(nodes[0], true);
  22. function checkIsMergeBorder(bandNode) {
  23. if (bandNode[JV.BAND_PROP_MERGE_BORDER] != null && bandNode[JV.BAND_PROP_MERGE_BORDER] != undefined) {
  24. if (stringUtil.convertStrToBoolean(bandNode[JV.BAND_PROP_MERGE_BORDER])) {
  25. me.treeObj.checkNode(bandNode, true);
  26. return false;
  27. }
  28. }
  29. if (bandNode[JV.BAND_PROP_SUB_BANDS] && bandNode[JV.BAND_PROP_SUB_BANDS].length > 0) {
  30. for (let subBandNode of bandNode[JV.BAND_PROP_SUB_BANDS]) {
  31. if (!checkIsMergeBorder(subBandNode)) {
  32. return false;
  33. }
  34. }
  35. }
  36. return true;
  37. }
  38. for (let bNode of nodes) {
  39. checkIsMergeBorder(bNode);
  40. }
  41. },
  42. copyBandList: function (isAllParent) {
  43. let me = this, rst = null;
  44. if (me.treeObj) {
  45. rst = [];
  46. let nodes = me.treeObj.getNodes()[0][JV.BAND_PROP_SUB_BANDS];
  47. let private_copy_nodes = function (parentNode, item) {
  48. item[JV.PROP_ID] = parentNode[JV.PROP_ID];
  49. item[JV.BAND_PROP_NAME] = parentNode[JV.BAND_PROP_NAME];
  50. item[JV.BAND_PROP_STYLE] = parentNode[JV.BAND_PROP_STYLE];
  51. item[JV.BAND_PROP_CONTROL] = parentNode[JV.BAND_PROP_CONTROL];
  52. if (parentNode[JV.BAND_PROP_HEIGHT]) item[JV.BAND_PROP_HEIGHT] = parentNode[JV.BAND_PROP_HEIGHT];
  53. if (parentNode[JV.BAND_PROP_WIDTH]) item[JV.BAND_PROP_WIDTH] = parentNode[JV.BAND_PROP_WIDTH];
  54. item[JV.BAND_PROP_DISPLAY_TYPE] = parentNode[JV.BAND_PROP_DISPLAY_TYPE];
  55. item[JV.BAND_PROP_ALIGNMENT] = parentNode[JV.BAND_PROP_ALIGNMENT];
  56. item[JV.BAND_PROP_MERGE_BORDER] = parentNode[JV.BAND_PROP_MERGE_BORDER];
  57. if (isAllParent) item.isParent = true;
  58. if (parentNode[JV.BAND_PROP_SUB_BANDS]) {
  59. item.items = [];
  60. for (let subNode of parentNode[JV.BAND_PROP_SUB_BANDS]) {
  61. let subItem = {};
  62. private_copy_nodes(subNode, subItem);
  63. item.items.push(subItem);
  64. }
  65. }
  66. }
  67. for (let node of nodes) {
  68. let item = {};
  69. if (isAllParent) item.isParent = true;
  70. private_copy_nodes(node, item);
  71. rst.push(item);
  72. }
  73. } else {
  74. console.log("the band tree is not ready!");
  75. }
  76. return rst;
  77. },
  78. buildTreeData: function(bandList){
  79. let rst = [], startIdx = 1;
  80. //zTreeHelper.createTree(result, setting, "rptTplTree", me);
  81. let private_setBandId = function (parentBand) {
  82. if (parentBand[JV.BAND_PROP_SUB_BANDS]) {
  83. for (let band of parentBand[JV.BAND_PROP_SUB_BANDS]) {
  84. band.ID = startIdx;
  85. band.ParentID = parentBand.ID;
  86. startIdx++;
  87. private_setBandId(band);
  88. }
  89. }
  90. }
  91. for (let band of bandList) {
  92. band.ID = startIdx;
  93. band.ParentID = -1;
  94. startIdx++;
  95. private_setBandId(band);
  96. }
  97. return rst;
  98. },
  99. createBandFromNode: function(node) {
  100. let me = this, rst = {};
  101. rst[JV.BAND_PROP_ALIGNMENT] = node[JV.BAND_PROP_ALIGNMENT];
  102. rst[JV.BAND_PROP_DISPLAY_TYPE] = node[JV.BAND_PROP_DISPLAY_TYPE];
  103. let posIdx = JV.LAYOUT.indexOf(node[JV.BAND_PROP_ALIGNMENT])
  104. switch(posIdx) {
  105. case 0:
  106. case 1:
  107. rst[JV.BAND_PROP_HEIGHT] = node[JV.BAND_PROP_HEIGHT];
  108. break;
  109. case 2:
  110. case 3:
  111. rst[JV.BAND_PROP_WIDTH] = node[JV.BAND_PROP_WIDTH];
  112. break;
  113. }
  114. rst[JV.PROP_NAME] = node[JV.PROP_NAME];
  115. rst[JV.PROP_CONTROL] = node[JV.PROP_CONTROL];
  116. rst[JV.PROP_STYLE] = node[JV.PROP_STYLE];
  117. if (node[JV.BAND_PROP_MERGE_BORDER] !== undefined) {
  118. rst[JV.BAND_PROP_MERGE_BORDER] = node[JV.BAND_PROP_MERGE_BORDER];
  119. } else {
  120. rst[JV.BAND_PROP_MERGE_BORDER] = 'F';
  121. }
  122. if (node[JV.BAND_PROP_SUB_BANDS]) {
  123. rst[JV.BAND_PROP_SUB_BANDS] = [];
  124. for (let subNode of node[JV.BAND_PROP_SUB_BANDS]) {
  125. rst[JV.BAND_PROP_SUB_BANDS].push(me.createBandFromNode(subNode));
  126. }
  127. }
  128. return rst;
  129. },
  130. createDftBand: function () {
  131. let me = this, rst = {};
  132. rst[JV.BAND_PROP_ALIGNMENT] = 'Top';
  133. rst[JV.BAND_PROP_DISPLAY_TYPE] = 'EveryPage';
  134. rst[JV.BAND_PROP_HEIGHT] = '3';
  135. rst[JV.PROP_NAME] = 'newBand_' + me.innerCounter;
  136. me.innerCounter++;
  137. rst[JV.PROP_CONTROL] = 'Default';
  138. rst[JV.PROP_STYLE] = 'Default_None';
  139. rst[JV.BAND_PROP_MERGE_BORDER] = 'F';
  140. return rst;
  141. },
  142. addHoverDom: function(treeId, treeNode) {
  143. let me = bandTreeOprObj, sObj = $("#" + treeNode.tId + "_span");
  144. if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length > 0 || treeNode.nodeType === RT.NodeType.TEMPLATE) return;
  145. let addStr = "<span class='button add' id='addBtn_" + treeNode.tId + "' title='新增布局框' onfocus='this.blur();'></span>";
  146. sObj.after(addStr);
  147. let btn = $("#addBtn_"+treeNode.tId);
  148. if (btn) btn.bind("click", function(){
  149. let newBand = me.createDftBand();
  150. let newNodes = [], isSilent = false;
  151. newNodes.push(newBand);
  152. me.treeObj.addNodes(treeNode, -1, newNodes, isSilent);
  153. });
  154. },
  155. removeHoverDom: function(treeId, treeNode) {
  156. $("#addBtn_"+treeNode.tId).unbind().remove();
  157. },
  158. onBeforeDrag: function (treeId, treeNodes) {
  159. let rst = true;
  160. for (let node of treeNodes) {
  161. if (node.level === 0) {
  162. rst = false;
  163. break;
  164. }
  165. }
  166. return rst;
  167. },
  168. onBeforeDrop: function (treeId, treeNodes, targetNode, moveType, isCopy) {
  169. let me = bandTreeOprObj, rst = true;
  170. if (targetNode.level === 0) {
  171. if (moveType !== 'inner') {
  172. rst = false;
  173. }
  174. }
  175. return rst;
  176. },
  177. onClick: function(event,treeId,treeNode) {
  178. let me = bandTreeOprObj;
  179. me.currentNode = treeNode;
  180. me.canTrickEvent = false;
  181. //then refresh the band tab properties
  182. //边框样式borderStyles
  183. $("#borderStyles").get(0).selectedIndex = rpt_tpl_cfg_helper.reportCfg.borderArr.indexOf(treeNode[JV.PROP_STYLE]);
  184. //边框合并
  185. // $("#mergeBandBorder").get(0).checked = stringUtil.convertStrToBoolean(treeNode[JV.BAND_PROP_MERGE_BORDER]);
  186. //位置
  187. let posIdx = JV.LAYOUT.indexOf(treeNode[JV.BAND_PROP_ALIGNMENT])
  188. $("#bandAlignment").get(0).selectedIndex = posIdx;
  189. //高与宽
  190. me.setupWidthHeightByPosition(posIdx);
  191. //频率
  192. $("#pageFrequency").get(0).selectedIndex = JV.PAGE_STATUS.indexOf(treeNode[JV.BAND_PROP_DISPLAY_TYPE])
  193. //
  194. me.canTrickEvent = true;
  195. },
  196. onCheck: function (event,treeId,treeNode) {
  197. let me = bandTreeOprObj;
  198. let nodes = me.treeObj.getNodes();
  199. function unCheckMergeBorder(bandNode) {
  200. if (bandNode[JV.BAND_PROP_MERGE_BORDER] != null && bandNode[JV.BAND_PROP_MERGE_BORDER] != undefined) {
  201. bandNode[JV.BAND_PROP_MERGE_BORDER] = 'F';
  202. }
  203. if (bandNode[JV.BAND_PROP_SUB_BANDS] && bandNode[JV.BAND_PROP_SUB_BANDS].length > 0) {
  204. for (let subBandNode of bandNode[JV.BAND_PROP_SUB_BANDS]) {
  205. unCheckMergeBorder(subBandNode)
  206. }
  207. }
  208. }
  209. for (let bNode of nodes) {
  210. unCheckMergeBorder(bNode);
  211. }
  212. if (treeNode.checked) {
  213. treeNode[JV.BAND_PROP_MERGE_BORDER] = 'T';
  214. }
  215. },
  216. onBeforeRemove: function(treeId, treeNode){
  217. let rst = true;
  218. if (treeNode.band_s && treeNode.band_s.length > 0) {
  219. rst = false;
  220. } else {
  221. rst = confirm("在删除前请确认报表模板内部没有引用,否则会造成混淆。");
  222. }
  223. return rst;
  224. },
  225. setupWidthHeightByPosition: function (posIdx) {
  226. let me = this, treeNode = me.currentNode;
  227. switch(posIdx) {
  228. case 0:
  229. case 1:
  230. $("#bandHeight").get(0).disabled = false;
  231. $("#bandHeight").get(0).value = treeNode[JV.BAND_PROP_HEIGHT];
  232. $("#bandWidth").get(0).disabled = true;
  233. $("#bandWidth").get(0).value = "";
  234. break;
  235. case 2:
  236. case 3:
  237. $("#bandHeight").get(0).disabled = true;
  238. $("#bandHeight").get(0).value = "";
  239. $("#bandWidth").get(0).disabled = false;
  240. $("#bandWidth").get(0).value = treeNode[JV.BAND_PROP_WIDTH];
  241. break;
  242. default:
  243. $("#bandHeight").get(0).disabled = true;
  244. $("#bandHeight").get(0).value = "";
  245. $("#bandWidth").get(0).disabled = true;
  246. $("#bandWidth").get(0).value = "";
  247. break;
  248. }
  249. },
  250. bandStyleChange: function (dom) {
  251. let me = this;
  252. if (me.currentNode) {
  253. me.currentNode[JV.PROP_STYLE] = rpt_tpl_cfg_helper.reportCfg.borderArr[dom.selectedIndex];
  254. }
  255. },
  256. bandAlignmentChange: function (dom) {
  257. let me = this;
  258. if (me.currentNode) {
  259. let posIdx = dom.selectedIndex;
  260. me.currentNode[JV.BAND_PROP_ALIGNMENT] = JV.LAYOUT[posIdx];
  261. me.setupWidthHeightByPosition(posIdx);
  262. }
  263. },
  264. bandHeightWidthChange: function (dom) {
  265. let me = this, treeNode = me.currentNode;
  266. if (me.currentNode) {
  267. let posIdx = $("#bandAlignment").get(0).selectedIndex;
  268. switch(posIdx) {
  269. case 0:
  270. case 1:
  271. treeNode[JV.BAND_PROP_HEIGHT] = dom.value;
  272. break;
  273. case 2:
  274. case 3:
  275. treeNode[JV.BAND_PROP_WIDTH] = dom.value;
  276. break;
  277. }
  278. }
  279. },
  280. changeBandHeight: function (bandName, newHeight) {
  281. let me = this;
  282. let private_setup_band_height = function (bNode) {
  283. let rst = false;
  284. if (bNode[JV.PROP_NAME] === bandName) {
  285. bNode[JV.BAND_PROP_HEIGHT] = newHeight;
  286. rst = true;
  287. }
  288. if (bNode[JV.BAND_PROP_SUB_BANDS] && bNode[JV.BAND_PROP_SUB_BANDS].length > 0) {
  289. for (let sbNode of bNode[JV.BAND_PROP_SUB_BANDS]) {
  290. if (private_setup_band_height(sbNode)) {
  291. rst = true;
  292. break;
  293. }
  294. }
  295. }
  296. return rst;
  297. };
  298. if (me.currentNode && me.currentNode[JV.PROP_NAME] === bandName) {
  299. me.currentNode[JV.BAND_PROP_HEIGHT] = newHeight;
  300. } else {
  301. let nodes = me.treeObj.getNodes();
  302. for (let node of nodes) {
  303. if (private_setup_band_height(node)) {
  304. break;
  305. }
  306. }
  307. }
  308. },
  309. bandShowFrequencyChange: function (dom) {
  310. let me = this;
  311. if (me.currentNode) {
  312. me.currentNode[JV.BAND_PROP_DISPLAY_TYPE] = JV.PAGE_STATUS[dom.selectedIndex];
  313. }
  314. },
  315. extractBands: function (rptTpl) {
  316. let me = this;
  317. if (rptTpl) {
  318. let newBandList = [];
  319. let nodes = me.treeObj.getNodes()[0][JV.BAND_PROP_SUB_BANDS];
  320. for (let node of nodes) {
  321. newBandList.push(me.createBandFromNode(node));
  322. }
  323. rptTpl[JV.NODE_BAND_COLLECTION] = newBandList;
  324. }
  325. }
  326. };