123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- 'use strict'
- let bandTreeOprObj = {
- treeObj : null,
- currentNode: null,
- innerCounter: 1,
- 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);
- },
- copyBandList: function (isAllParent) {
- let me = this, rst = null;
- if (me.treeObj) {
- rst = [];
- let nodes = me.treeObj.getNodes();
- let private_copy_nodes = function (parentNode, item) {
- item[JV.PROP_ID] = parentNode[JV.PROP_ID];
- item[JV.BAND_PROP_NAME] = parentNode[JV.BAND_PROP_NAME];
- item[JV.BAND_PROP_STYLE] = parentNode[JV.BAND_PROP_STYLE];
- item[JV.BAND_PROP_CONTROL] = parentNode[JV.BAND_PROP_CONTROL];
- if (parentNode[JV.BAND_PROP_HEIGHT]) item[JV.BAND_PROP_HEIGHT] = parentNode[JV.BAND_PROP_HEIGHT];
- if (parentNode[JV.BAND_PROP_WIDTH]) item[JV.BAND_PROP_WIDTH] = parentNode[JV.BAND_PROP_WIDTH];
- item[JV.BAND_PROP_DISPLAY_TYPE] = parentNode[JV.BAND_PROP_DISPLAY_TYPE];
- item[JV.BAND_PROP_ALIGNMENT] = parentNode[JV.BAND_PROP_ALIGNMENT];
- item[JV.BAND_PROP_MERGE_BORDER] = parentNode[JV.BAND_PROP_MERGE_BORDER];
- if (isAllParent) item.isParent = true;
- if (parentNode[JV.BAND_PROP_SUB_BANDS]) {
- item.items = [];
- for (let subNode of parentNode[JV.BAND_PROP_SUB_BANDS]) {
- let subItem = {};
- private_copy_nodes(subNode, subItem);
- item.items.push(subItem);
- }
- }
- }
- for (let node of nodes) {
- let item = {};
- if (isAllParent) item.isParent = true;
- private_copy_nodes(node, item);
- rst.push(item);
- }
- } else {
- console.log("the band tree is not ready!");
- }
- return rst;
- },
- 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;
- },
- 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 = rpt_tpl_cfg_helper.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;
- },
- onBeforeRemove: function(treeId, treeNode){
- let rst = true;
- if (treeNode.band_s && treeNode.band_s.length > 0) {
- rst = false;
- } else {
- rst = confirm("在删除前请确认报表模板内部没有引用,否则会造成混淆。");
- }
- return rst;
- },
- 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] = rpt_tpl_cfg_helper.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;
- }
- }
- };
|