rpt_tpl_band.js 12 KB

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