'use strict' let bandTreeOprObj = { treeObj : null, currentNode: null, innerCounter: 1, reportCfg: null, canTrickEvent: false, iniTree: function(rptTpl) { var me = this; let bandList = rptTpl[JV.NODE_BAND_COLLECTION]; me.buildTreeData(bandList); me.treeObj = $.fn.zTree.init($("#band_tree_reversed"), bandSetting, bandList); me.treeObj.expandAll(true); }, buildTreeData: function(bandList){ let rst = [], startIdx = 1; //zTreeHelper.createTree(result, setting, "rptTplTree", me); let private_setBandId = function (parentBand) { if (parentBand[JV.BAND_PROP_SUB_BANDS]) { for (let band of parentBand[JV.BAND_PROP_SUB_BANDS]) { band.ID = startIdx; band.ParentID = parentBand.ID; startIdx++; private_setBandId(band); } } } for (let band of bandList) { band.ID = startIdx; band.ParentID = -1; startIdx++; private_setBandId(band); } return rst; }, getReportTplCfg: function() { let me = this, params = {}; params.userId = userID; CommonAjax.postEx("report_tpl_api/getUserRptCfg", params, 20000, true, function(result){ me.reportCfg = result; me.refreshRptCfgs(); }, null, null ); }, refreshRptCfgs: function () { let me = this; if (me.reportCfg) { me.reportCfg.borderArr = []; for (let style of me.reportCfg.styles) { me.reportCfg.borderArr.push(style.ID); $("#borderStyles").append(""); } } let pf = $("#pageFrequency"); pf.append(""); pf.append(""); pf.append(""); pf.append(""); pf.append(""); pf.append(""); pf.append(""); pf.append(""); let ba = $("#bandAlignment"); ba.append(""); ba.append(""); ba.append(""); ba.append(""); ba.append(""); }, createBandFromNode: function(node) { let me = this, rst = {}; rst[JV.BAND_PROP_ALIGNMENT] = node[JV.BAND_PROP_ALIGNMENT]; rst[JV.BAND_PROP_DISPLAY_TYPE] = node[JV.BAND_PROP_DISPLAY_TYPE]; let posIdx = JV.LAYOUT.indexOf(node[JV.BAND_PROP_ALIGNMENT]) switch(posIdx) { case 0: case 1: rst[JV.BAND_PROP_HEIGHT] = node[JV.BAND_PROP_HEIGHT]; break; case 2: case 3: rst[JV.BAND_PROP_WIDTH] = node[JV.BAND_PROP_WIDTH]; break; } rst[JV.PROP_NAME] = node[JV.PROP_NAME]; rst[JV.PROP_CONTROL] = node[JV.PROP_CONTROL]; rst[JV.PROP_STYLE] = node[JV.PROP_STYLE]; if (node[JV.BAND_PROP_MERGE_BORDER] != undefined) { rst[JV.BAND_PROP_MERGE_BORDER] = node[JV.BAND_PROP_MERGE_BORDER]; } else { rst[JV.BAND_PROP_MERGE_BORDER] = 'F'; } if (node[JV.BAND_PROP_SUB_BANDS]) { rst[JV.BAND_PROP_SUB_BANDS] = []; for (let subNode of node[JV.BAND_PROP_SUB_BANDS]) { rst[JV.BAND_PROP_SUB_BANDS].push(me.createBandFromNode(subNode)); } } return rst; }, createDftBand: function () { let me = this, rst = {}; rst[JV.BAND_PROP_ALIGNMENT] = 'Top'; rst[JV.BAND_PROP_DISPLAY_TYPE] = 'EveryPage'; rst[JV.BAND_PROP_HEIGHT] = '3'; rst[JV.PROP_NAME] = 'newBand_' + me.innerCounter; me.innerCounter++; rst[JV.PROP_CONTROL] = 'Default'; rst[JV.PROP_STYLE] = 'Default_None'; rst[JV.BAND_PROP_MERGE_BORDER] = 'F'; return rst; }, addRootBand: function (rptTpl) { let me = this; if (rptTpl) { let newBand = me.createDftBand(); let newNodes = [], isSilent = false; newNodes.push(newBand); if (me.treeObj) { me.treeObj.addNodes(null, -1, newNodes, isSilent); } else { me.treeObj = $.fn.zTree.init($("#band_tree_reversed"), bandSetting, newNodes); } } }, addSubBand: function (rptTpl) { let me = this; if (rptTpl && me.currentNode != null) { let newBand = me.createDftBand(); let newNodes = [], isSilent = false; newNodes.push(newBand); me.treeObj.addNodes(me.currentNode, -1, newNodes, isSilent); } }, moveDownBand: function (rptTpl) { let me = bandTreeOprObj; if (rptTpl && me.currentNode && me.currentNode.getNextNode()) { let nextNode = me.currentNode.getNextNode(); me.treeObj.moveNode(nextNode, me.currentNode, "next", true); } }, moveUpBand: function (rptTpl) { let me = bandTreeOprObj; if (rptTpl && me.currentNode && me.currentNode.getPreNode()) { let preNode = me.currentNode.getPreNode(); me.treeObj.moveNode(preNode, me.currentNode, "prev", true); } }, onClick: function(event,treeId,treeNode) { let me = bandTreeOprObj; me.currentNode = treeNode; me.canTrickEvent = false; //then refresh the band tab properties //边框样式borderStyles $("#borderStyles ").get(0).selectedIndex = me.reportCfg.borderArr.indexOf(treeNode[JV.PROP_STYLE]); //边框合并 $("#mergeBandBorder").get(0).checked = stringUtil.convertStrToBoolean(treeNode[JV.BAND_PROP_MERGE_BORDER]); //位置 let posIdx = JV.LAYOUT.indexOf(treeNode[JV.BAND_PROP_ALIGNMENT]) $("#bandAlignment").get(0).selectedIndex = posIdx; //高与宽 me.setupWidthHeightByPosition(posIdx); //频率 $("#pageFrequency").get(0).selectedIndex = JV.PAGE_STATUS.indexOf(treeNode[JV.BAND_PROP_DISPLAY_TYPE]) // me.canTrickEvent = true; }, setupWidthHeightByPosition: function (posIdx) { let me = this, treeNode = me.currentNode; switch(posIdx) { case 0: case 1: $("#bandHeight").get(0).disabled = false; $("#bandHeight").get(0).value = treeNode[JV.BAND_PROP_HEIGHT]; $("#bandWidth").get(0).disabled = true; $("#bandWidth").get(0).value = ""; break; case 2: case 3: $("#bandHeight").get(0).disabled = true; $("#bandHeight").get(0).value = ""; $("#bandWidth").get(0).disabled = false; $("#bandWidth").get(0).value = treeNode[JV.BAND_PROP_WIDTH]; break; default: $("#bandHeight").get(0).disabled = true; $("#bandHeight").get(0).value = ""; $("#bandWidth").get(0).disabled = true; $("#bandWidth").get(0).value = ""; break; } }, bandStyleChange: function (dom) { let me = this; if (me.currentNode) { me.currentNode[JV.PROP_STYLE] = me.reportCfg.borderArr[dom.selectedIndex]; } }, bandAlignmentChange: function (dom) { let me = this; if (me.currentNode) { let posIdx = dom.selectedIndex; me.currentNode[JV.BAND_PROP_ALIGNMENT] = JV.LAYOUT[posIdx]; me.setupWidthHeightByPosition(posIdx); } }, bandHeightWidthChange: function (dom) { let me = this, treeNode = me.currentNode; if (me.currentNode) { let posIdx = $("#bandAlignment").get(0).selectedIndex; switch(posIdx) { case 0: case 1: treeNode[JV.BAND_PROP_HEIGHT] = dom.value; break; case 2: case 3: treeNode[JV.BAND_PROP_WIDTH] = dom.value; break; } } }, bandShowFrequencyChange: function (dom) { let me = this; if (me.currentNode) { me.currentNode[JV.BAND_PROP_DISPLAY_TYPE] = JV.PAGE_STATUS[dom.selectedIndex]; } }, bandBorderMergeChange: function (dom) { let me = this; if (me.currentNode) { me.currentNode[JV.BAND_PROP_MERGE_BORDER] = dom.checked?'T':'F'; } }, extractBands: function (rptTpl) { let me = this; if (rptTpl) { let newBandList = []; for (let node of me.treeObj.getNodes()) { newBandList.push(me.createBandFromNode(node)); } rptTpl[JV.NODE_BAND_COLLECTION] = newBandList; } } };