rpt_tpl_band.js 11 KB

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