zTree在addHoverDom中获取级别判断…

function addHoverDom(treeId, treeNode) {
     
      var sObj = $("#" + treeNode.tId + "_span");
      var addStr = "";
      var templateStr = "";
      var clsStr  = "";
      if (treeNode.level < maxLevel - 2) {      // 非模板节点和第二级模板组目录节点
            if (treeNode.editNameFlag || $("#addBtn_"+treeNode.id).length>0) return;
           
            if(treeNode.getParentNode()==null){
                  if(treeNode.text=="System"){
                        if(map.sys_gp_add==true){
                              addStr = returnAddButton(addStr,treeNode);
                             
                        }
                  }
                  if(treeNode.text=="User"){
                        if(map.user_gp_add==true){
                              addStr = returnAddButton(addStr,treeNode);
                        }
                  }
                 
            }else{
                  if(treeNode.getParentNode().text=="System"){
                        if(treeNode.level==1&&map.sys_gp_add==true){
                              addStr = returnAddButton(addStr,treeNode);
                        }
                  }
                  if(treeNode.getParentNode().text=="User"){
                        if(treeNode.level==1&&map.user_gp_add==true){
                              addStr = returnAddButton(addStr,treeNode);
                        }
                       
                  }
            }
           
            sObj.after(addStr);
            var btn = $("#addBtn_"+treeNode.id);
            if (btn){
                  btn.bind("click", function(){
                        if (!treeNode.open) {
                              $('#' + treeId).inspurTree('expandNode', treeNode);
                              if (treeNode.children && treeNode.children.length > 0) {
                                    var inter = setInterval(function(){
                                          if (treeNode.open) {
                                                window.clearInterval(inter);
                                                addGroupNode(treeId, treeNode) ;
                                          }
                                    }, 100);
                              } else {
                                    addGroupNode(treeId, treeNode) ;
                              }
                        } else {
                              addGroupNode(treeId, treeNode) ;
                        }
                        return false;
                  });
            }
      }
     
      if (treeNode.iconSkin == 'icon01') {      // template node
            //添加之前 先删除组件
            //removeHoverDom(treeId, treeNode);
            if (treeNode.editNameFlag || $("#playBtn_"+treeNode.id).length>0) return;
            //if(window.treeTool){
                 
                  clsStr = 'button home' ;
                  if (treeNode.isMain) {
                        clsStr = 'button home_xz' ;
                  }
                  if(treeNode.getParentNode()!=null){
                        var node = treeNode.getParentNode();
                        var nodeValue = node.getParentNode();
                       
                        if(nodeValue.text=="System"&&treeNode.level==2){
                              removeHoverDom(treeId, treeNode);
                              templateStr ="";
                              templateStr = returnSys(treeNode,templateStr,clsStr);
                        }
                        if(nodeValue.getParentNode()!=null){
                              if(nodeValue.getParentNode().text=="System"&&treeNode.level==3){
                                    removeHoverDom(treeId, treeNode);
                                    templateStr="";
                                    templateStr = returnSys(treeNode,templateStr,clsStr);
                              }
                        }
                       
                       
                        if(nodeValue.text=="User"&&treeNode.level==2){
                              templateStr = "";
                              templateStr = returnUser(treeNode,templateStr,clsStr);
                        }
                        if(nodeValue.getParentNode()!=null){
                              if(nodeValue.getParentNode().text=="User"&&treeNode.level==3){
                                    templateStr="";
                                    templateStr = returnUser(treeNode,templateStr,clsStr);
                              }
                        }
                       
                       
                  }
                  //window.treeTool=$(templateStr);
            //}
           
            //sObj.after(window.treeTool) ;
            sObj.after(templateStr) ;
            var btnPlay = $('#playBtn_' + treeNode.id) ;
            var btnHome = $('#homeBtn_' + treeNode.id) ;
            var btnSaveAs = $('#saveAsBtn_' + treeNode.id) ;
            var btnExport = $('#exportBtn_' + treeNode.id) ;
            // play trigger
            if (btnPlay) {
                  btnPlay.bind('click', function(e){
                        // 首先检查该DashboardTemplate下是否有监控组件数据
                        $.post(basePath + '/dashboard/checkElesExist_cptPre.do', {'templateId': treeNode.id}, function(datas){
                              if (datas == "1") {
                                    var jsp_url = basePath + '/pages/dashboard/showMonitor.jsp?tpId=' + treeNode.id + '&name=' + treeNode.text ;
                                    var targetWin = window.open(jsp_url, 'elementsPlay',
                                          'fullscreen=yes,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no') ;
                              } else {
                                    $.inspurMessageBox.alert({
                                              content: 'The template do not have any element.'
                                      });
                              }
                        },'text') ;
                        //e.stopPropagation();
                        //阻止事件冒泡
                        return false;
                  }) ;           
            }
            if (btnHome) {
                  btnHome.click(function(e){
                        var confirmTip = 'Are you sure to set this template as main ?' ;
                        var opt_url = basePath + '/dashboard/templateAsMain_dsbTree.do' ;
                        var tempCls = $('#homeBtn_' + treeNode.id).attr('class') ;
                        if (tempCls == 'button home_xz') {
                              confirmTip = 'Are you sure cancel to set this template
as main ?' ;
                              opt_url = basePath + '/dashboard/templateCancelMain_dsbTree.do' ;
                        }
                        $.inspurMessageBox.confirm({
                              content: confirmTip,
                              width: 350,
                              onClose:function(value){
                                    if(value) {
                                          $.ajax({
                                                type: 'POST',
                                                url: opt_url,
                                                data: {
                                                      id: treeNode.id,
                                                      name: treeNode.text
                                                },
                                                dataType: 'json',
                                                success: function(msg) {
                                                      flag = msg.success;
                                                      if(flag) {
                                                            if (oldMain) {
                                                                  oldMain.isMain = false ;
                                                            }
                                                            if (tempCls == 'button home') {
                                                                  $('#homeBtn_' + treeNode.id).attr('class', 'button home_xz') ;
                                                                  treeNode.isMain = true ;
                                                                  oldMain = treeNode ;
                                                            } else {
                                                                  $('#homeBtn_' + treeNode.id).attr('class', 'button home') ;
                                                            }
                                                      } else {
                                                            $.inspurMessageBox.alert({
                                                                  type:'error',
                                                                  content: msg.msg
                                                            });
                                                      }
                                                },
                                                error: function(XMLHttpRequest, textStatus, errorThrown) {
                                                      $.inspurMessageBox.alert({
                                                            type:'error',
                                                            content: 'Setting failure!'
                                                      });
                                                }
                                          });
                                    }
                              }
                        });
                        //e.stopPropagation();
                        //阻止事件冒泡
                        return false;
                  }) ;
            }
           
            // save as
            if (btnSaveAs) {
                  btnSaveAs.click(function(e){
                        $('#pop_saveAs').inspurWindow("open") ;
                        //取当前值
                        var orgName = treeNode.text;
                        templateId = treeNode.id;
                        $('#dashboard_name').attr('orgName', orgName);
                        $('#dashboard_name').val('Copy Of '+ orgName) ;
                        $('#dashboard_desc').val('') ;
                        $("#dash_group_tree").inspurTree({
                              dataSource: basePath + "/dashboard/getDatas4Tree_dsbTree.do",
                              edit: false,
                              root: dash_root,
                              selectedMulti: false,
                              autoParam:['id', 'level'],
                              otherParam:{'justGroups': '1'},
                              onClick: dashGroupOnClick2,
                              onCreate: function(e, treeId, node) {
                                    if(node.level == 0) {      // 默认展开根节点
                                          $('#' + treeId).inspurTree('expandNode', node);
                                    }
                              }
                        });
                        $('#dashboard_name').focus() ;
                        //阻止事件冒泡
                        return false;
                        //e.stopPropagation();
                  }) ;           
            }
           
            //Export
            if(btnExport){
                  btnExport.click(function(e){
                        var selectNode = $('#'+treeId).inspurTree('getSelected')[0];
                        var selectNodeId = '';
                        if(selectNode != undefined){
                              selectNodeId = selectNode.id;
                        }
                        var eleMap = {}; // 存储每个elementId对应的展示状态 table还是graph
                        if(selectNodeId == treeNode.id){
                              var divs =  RelativeLayout.portal.dom.find('.widgetBodyContainer');//当前展示的div数组
                              $(divs).each(function(i,item){
                                    var elementId = item.id;
                                    var config = RelativeLayout.get($('#'+elementId)).config;
                                    var displayType = config.displayType;
                                    eleMap[elementId] = displayType;
                              });
                        }
                       
                        var taskID = generateTaskID();
                        $(btnExport).inspurProgressBar({
                              taskID: taskID,
                              message:"Data Loading, please wait…",
                              isMonitorable : false,
                              isFake: true,
                              isMask:true
                        });
                       
                        $.ajax({
                              type: "post",
                              url: basePath + '/dashboard/exportExcelForTemplate_cptPre.do',
                              //async: false,
                              data: {
                                    templateId:treeNode.id,
                                    templateName:treeNode.text,
                                    eleMap:JSON.stringify(eleMap)
                              },
                              dataType: 'text',
                              success: function(filePath) {
                                    if(filePath == "" || filePath == "null" || filePath == null || filePath == undefined){
                                          setTimeout(function(){$.inspurMessageBox.alert({
                                                content:"No data to export."
                                          });},20);
                                    } else {
                                          window.location.href = basePath + '/dashboard/downloadFile_cptPre.do?filePath='+filePath;
                                    }
                                    $(btnExport).inspurProgressBar('close');
                              },
                              error:function(){
                                    $(btnExport).inspurProgressBar('close');
                              }
                        });
                        //阻止事件冒泡
                        return false;
                        //e.stopPropagation();
                  });
            }
           
           
      }
}


function returnUser(treeNode,templateStr,clsStr){
    if(map.user_tp_play==true){
        templateStr = "" ;
    }
    if(map.user_tp_sethome==true){
        // add set home
        
        templateStr += "" ;
    }
    if(map.user_tp_copy==true){
        //添加另存为图标按钮
        templateStr += "" ;
    }
    if(map.user_tp_export==true){
        //添加导出按钮 add by xuchi
        templateStr += "" ;
    }
    return templateStr;
}

function returnAddButton(addStr,treeNode){
    addStr = "";
    return addStr;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值