123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- '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("<option value='" + style.ID + "'>" + style.CfgDispName + "</option>");
- }
- }
- let pf = $("#pageFrequency");
- pf.append("<option value='" + JV.PAGE_STATUS[0] + "'>每页</option>");
- pf.append("<option value='" + JV.PAGE_STATUS[1] + "'>首页</option>");
- pf.append("<option value='" + JV.PAGE_STATUS[2] + "'>尾页</option>");
- pf.append("<option value='" + JV.PAGE_STATUS[3] + "'>章首页</option>");
- pf.append("<option value='" + JV.PAGE_STATUS[4] + "'>章尾页</option>");
- pf.append("<option value='" + JV.PAGE_STATUS[5] + "'>分组</option>");
- pf.append("<option value='" + JV.PAGE_STATUS[6] + "'>交叉行尾页</option>");
- pf.append("<option value='" + JV.PAGE_STATUS[7] + "'>交叉列尾页</option>");
- let ba = $("#bandAlignment");
- ba.append("<option value='" + JV.LAYOUT[0] + "'>上</option>");
- ba.append("<option value='" + JV.LAYOUT[1] + "'>下</option>");
- ba.append("<option value='" + JV.LAYOUT[2] + "'>左</option>");
- ba.append("<option value='" + JV.LAYOUT[3] + "'>右</option>");
- ba.append("<option value='" + JV.LAYOUT[4] + "'>填充</option>");
- },
- 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;
- }
- }
- };
|