rpt_tpl_band.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. if (!treeNode.hasOwnProperty("band_s")) {
  153. treeNode["band_s"] = [];
  154. treeNode.isParent = true;
  155. }
  156. me.treeObj.addNodes(treeNode, -1, newNodes, isSilent);
  157. });
  158. },
  159. removeHoverDom: function(treeId, treeNode) {
  160. $("#addBtn_"+treeNode.tId).unbind().remove();
  161. },
  162. onBeforeDrag: function (treeId, treeNodes) {
  163. let rst = true;
  164. for (let node of treeNodes) {
  165. if (node.level === 0) {
  166. rst = false;
  167. break;
  168. }
  169. }
  170. return rst;
  171. },
  172. onBeforeDrop: function (treeId, treeNodes, targetNode, moveType, isCopy) {
  173. let me = bandTreeOprObj, rst = true;
  174. if (targetNode.level === 0) {
  175. if (moveType !== 'inner') {
  176. rst = false;
  177. }
  178. }
  179. return rst;
  180. },
  181. onClick: function(event,treeId,treeNode) {
  182. let me = bandTreeOprObj;
  183. me.currentNode = treeNode;
  184. me.canTrickEvent = false;
  185. //then refresh the band tab properties
  186. //边框样式borderStyles
  187. $("#borderStyles").get(0).selectedIndex = rpt_tpl_cfg_helper.reportCfg.borderArr.indexOf(treeNode[JV.PROP_STYLE]);
  188. //边框合并
  189. // $("#mergeBandBorder").get(0).checked = stringUtil.convertStrToBoolean(treeNode[JV.BAND_PROP_MERGE_BORDER]);
  190. //位置
  191. let posIdx = JV.LAYOUT.indexOf(treeNode[JV.BAND_PROP_ALIGNMENT])
  192. $("#bandAlignment").get(0).selectedIndex = posIdx;
  193. //高与宽
  194. me.setupWidthHeightByPosition(posIdx);
  195. //频率
  196. $("#pageFrequency").get(0).selectedIndex = JV.PAGE_STATUS.indexOf(treeNode[JV.BAND_PROP_DISPLAY_TYPE])
  197. //
  198. me.canTrickEvent = true;
  199. },
  200. onCheck: function (event,treeId,treeNode) {
  201. let me = bandTreeOprObj;
  202. let nodes = me.treeObj.getNodes();
  203. function unCheckMergeBorder(bandNode) {
  204. if (bandNode[JV.BAND_PROP_MERGE_BORDER] != null && bandNode[JV.BAND_PROP_MERGE_BORDER] != undefined) {
  205. bandNode[JV.BAND_PROP_MERGE_BORDER] = 'F';
  206. }
  207. if (bandNode[JV.BAND_PROP_SUB_BANDS] && bandNode[JV.BAND_PROP_SUB_BANDS].length > 0) {
  208. for (let subBandNode of bandNode[JV.BAND_PROP_SUB_BANDS]) {
  209. unCheckMergeBorder(subBandNode)
  210. }
  211. }
  212. }
  213. for (let bNode of nodes) {
  214. unCheckMergeBorder(bNode);
  215. }
  216. if (treeNode.checked) {
  217. treeNode[JV.BAND_PROP_MERGE_BORDER] = 'T';
  218. }
  219. },
  220. onBeforeRemove: function(treeId, treeNode){
  221. let rst = true;
  222. if (treeNode.band_s && treeNode.band_s.length > 0) {
  223. rst = false;
  224. } else {
  225. rst = confirm("在删除前请确认报表模板内部没有引用,否则会造成混淆。");
  226. }
  227. return rst;
  228. },
  229. setupWidthHeightByPosition: function (posIdx) {
  230. let me = this, treeNode = me.currentNode;
  231. switch(posIdx) {
  232. case 0:
  233. case 1:
  234. $("#bandHeight").get(0).disabled = false;
  235. $("#bandHeight").get(0).value = treeNode[JV.BAND_PROP_HEIGHT];
  236. $("#bandWidth").get(0).disabled = true;
  237. $("#bandWidth").get(0).value = "";
  238. break;
  239. case 2:
  240. case 3:
  241. $("#bandHeight").get(0).disabled = true;
  242. $("#bandHeight").get(0).value = "";
  243. $("#bandWidth").get(0).disabled = false;
  244. $("#bandWidth").get(0).value = treeNode[JV.BAND_PROP_WIDTH];
  245. break;
  246. default:
  247. $("#bandHeight").get(0).disabled = true;
  248. $("#bandHeight").get(0).value = "";
  249. $("#bandWidth").get(0).disabled = true;
  250. $("#bandWidth").get(0).value = "";
  251. break;
  252. }
  253. },
  254. bandStyleChange: function (dom) {
  255. let me = this;
  256. if (me.currentNode) {
  257. me.currentNode[JV.PROP_STYLE] = rpt_tpl_cfg_helper.reportCfg.borderArr[dom.selectedIndex];
  258. }
  259. },
  260. bandAlignmentChange: function (dom) {
  261. let me = this;
  262. if (me.currentNode) {
  263. let posIdx = dom.selectedIndex;
  264. me.currentNode[JV.BAND_PROP_ALIGNMENT] = JV.LAYOUT[posIdx];
  265. me.setupWidthHeightByPosition(posIdx);
  266. }
  267. },
  268. bandHeightWidthChange: function (dom) {
  269. let me = this, treeNode = me.currentNode;
  270. if (me.currentNode) {
  271. let posIdx = $("#bandAlignment").get(0).selectedIndex;
  272. switch(posIdx) {
  273. case 0:
  274. case 1:
  275. treeNode[JV.BAND_PROP_HEIGHT] = dom.value;
  276. break;
  277. case 2:
  278. case 3:
  279. treeNode[JV.BAND_PROP_WIDTH] = dom.value;
  280. break;
  281. }
  282. }
  283. },
  284. changeBandHeight: function (bandName, newHeight) {
  285. let me = this;
  286. let private_setup_band_height = function (bNode) {
  287. let rst = false;
  288. if (bNode[JV.PROP_NAME] === bandName) {
  289. bNode[JV.BAND_PROP_HEIGHT] = newHeight;
  290. rst = true;
  291. }
  292. if (bNode[JV.BAND_PROP_SUB_BANDS] && bNode[JV.BAND_PROP_SUB_BANDS].length > 0) {
  293. for (let sbNode of bNode[JV.BAND_PROP_SUB_BANDS]) {
  294. if (private_setup_band_height(sbNode)) {
  295. rst = true;
  296. break;
  297. }
  298. }
  299. }
  300. return rst;
  301. };
  302. if (me.currentNode && me.currentNode[JV.PROP_NAME] === bandName) {
  303. me.currentNode[JV.BAND_PROP_HEIGHT] = newHeight;
  304. } else {
  305. let nodes = me.treeObj.getNodes();
  306. for (let node of nodes) {
  307. if (private_setup_band_height(node)) {
  308. break;
  309. }
  310. }
  311. }
  312. },
  313. bandShowFrequencyChange: function (dom) {
  314. let me = this;
  315. if (me.currentNode) {
  316. me.currentNode[JV.BAND_PROP_DISPLAY_TYPE] = JV.PAGE_STATUS[dom.selectedIndex];
  317. }
  318. },
  319. extractBands: function (rptTpl) {
  320. let me = this;
  321. if (rptTpl) {
  322. let newBandList = [];
  323. let nodes = me.treeObj.getNodes()[0][JV.BAND_PROP_SUB_BANDS];
  324. for (let node of nodes) {
  325. newBandList.push(me.createBandFromNode(node));
  326. }
  327. rptTpl[JV.NODE_BAND_COLLECTION] = newBandList;
  328. }
  329. }
  330. };