rpt_tpl_band.js 9.4 KB

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