⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tree.js

📁 很全面的hrm管理。提供通用的企业人力资源管理。
💻 JS
📖 第 1 页 / 共 2 页
字号:

Tree.prototype.setControl = function(idControlName, nameControlName)
{
    if(idControlName instanceof String)
    {
        this.idObj = document.forms[0].namedItem(idControlName);
        if(!this.idObj )
        {
            this.idObj = eval(idControlName);
            if( !this.idObj )
            {
                this.warn("找不到保存数据的input");
            }
        }
    }
    else if(idControlName)
    {
        this.idObj = idControlName;
    }
    else
    {
        this.warn("找不到保存数据的input");
    }
    
    if(nameControlName instanceof String)
    {
        this.nameObj = document.forms[0].namedItem(nameControlName);
        if(!this.nameObj )
        {
            this.nameObj = eval(nameControlName);
            if( !this.nameObj )
            {
                this.warn("找不到显示数据的span");
            }
        }
    }
    else if(nameControlName)
    {
        this.nameObj = nameControlName;
    }
}

Tree.prototype.setInitValue = function()
{
    var parentSelect = this.getParentSelect();
    var childSelect =  this.getChildSelect();
    
    var orgValue;
    
    if(this.nameObj && this.nameObj.tagName && this.nameObj.tagName == "INPUT")
    {
        var nameValue = this.getObjValue( this.nameObj );
        
        if(nameValue)
        {
            for( obj in this.list )
            {
                if( this.list[obj].indexOf( nameValue ) != -1 )
                {
                    orgValue = obj;
                    break;
                }
            }
        }
    }
    
    if( !orgValue )
    {
        orgValue = this.getObjValue( this.idObj );
    }
    if(orgValue)
    {
        if(this.relation[orgValue])
        {
            parentSelect.value = orgValue;
            this.changeParentSelect();
        }
        else if(this.list[orgValue])
        {
            var child = this.list[orgValue];
            var splitValue = this.splitContent(child);
            parentSelect.value = splitValue[1];
            this.changeParentSelect();
            
            childSelect.value = orgValue;
        }
        else
        {
            parentSelect.value = "NoSelected";
            this.changeParentSelect();
        }
    }
    else
    {
        parentSelect.value = "NoSelected";
        this.changeParentSelect();
    }
}

Tree.prototype.checkValidate = function(idControlName, nameControlName)
{
    var orgValue;
    var eventEle = event.srcElement;
    if( !nameControlName)
    {
        
        var nameControl = eventEle;
        if(nameControl && nameControl.tagName)
        {
        	/*
            if(nameControl .tagName == "SPAN")
            {
                nameControlName = nameControl.id;
            }
            else if(nameControl .tagName == "INPUT");
            {
                nameControlName = nameControl .name;
            }
            */
            if(nameControl.tagName == "SPAN" || nameControl.tagName == "INPUT")
            {
                nameControlName = nameControl;
            }
        }
        
        if(!nameControlName)
        {
            alert("必须指定数据邦定的控件2");
            return;
        }
    }

    if( !idControlName)
    {
        var idControl = _findNextSibling(eventEle);
        //alert(idControl.tagName)
        if(idControl && idControl.tagName)
        {
            //alert(idControl.tagName);
            /*
            if(idControl.tagName == "SPAN")
            {
                idControlName = idControl.id;
            }
            else if(idControl.tagName == "INPUT");
            {
                idControlName = idControl.name;
            }
            */
            if(idControl.tagName == "SPAN" || idControl.tagName == "INPUT")
            {
                idControlName = idControl;
            }
        }
        
        if(!idControlName)
        {
            alert("必须指定数据邦定的控件1");
            return;
        }
    }

    this.setControl(idControlName, nameControlName);

    if(this.nameObj && this.nameObj.tagName && this.nameObj.tagName == "INPUT")
    {
        var nameValue = this.getObjValue( this.nameObj );
        
        if(nameValue && nameValue != "")
        {
            for( obj in this.list )
            {
                if( this.relation[obj] )
                {
                    if( this.list[obj].indexOf(nameValue) != -1)
                    {
                        if(this.parentSelected)
                        {
                            orgValue = obj;
                            break;
                        }
                        else
                        {
                            if( this.relation[obj].length == 0 )
                            {
                                orgValue = obj;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    var childArray =  this.splitContent(this.list[obj]);
                    var childName = childArray[0];
                    if( childName.indexOf( nameValue ) != -1 )
                    {
                        orgValue = obj;
                        break;
                    }
                }
            }
            if( !orgValue )
            {
                orgValue = this.getObjValue( this.idObj );
                if(orgValue)
                {
                    if(this.relation[orgValue])
                    {
                        if( this.parentSelected )
                        {
                            this.setValue(orgValue, this.getValue(orgValue));
                        }
                        else
                        {
                            if(this.relation[orgValue].length == 0)
                            {
                                this.setValue(orgValue, this.getValue(orgValue));
                            }
                            else
                            {
                                this.setValue("",new Array("",""));
                            }
                        }
                    }
                    else if(this.list[orgValue])
                    {
                        var child = this.list[orgValue];
                        var splitValue = this.splitContent(child);
                        this.setValue(orgValue, this.getValue(orgValue));
                    }
                    else
                    {
                        this.setValue("",new Array("",""));
                    }
                }
                else
                {
                    this.setValue("",new Array("",""));
                }
                return ( "[" + nameValue + "]不是一个合法的输入");
            }
            else
            {
                this.setValue(orgValue, this.getValue(orgValue));
            }
        }
        else
        {
            if( nameValue == "" )
            {
                this.setValue("",new Array("",""));
            }
        }
    }
    else
    {
        return "";
    }
}

Tree.prototype.getObjValue = function( obj )
{
    if(obj && obj.tagName)
    {
        if( obj.tagName == "INPUT" )
        {
            return obj.value;
        }
        else if(  obj.tagName == "SPAN" )
        {
            return obj.innerText;
        }
        else
        {
            this.info("不可识别的对象");
        }
    }
    else
    {
        return null;
    }
}

Tree.prototype.setObjValue = function( obj, value )
{
    if(obj  && obj.tagName)
    {
        if( obj.tagName == "INPUT" )
        {
            obj.value = value;
        }
        else if(  obj.tagName == "SPAN" )
        {
            obj.innerText = value;
        }
        else
        {
            this.info("不可识别的对象");
        }
    }
}

/*
* 设置选择的值到邦定的输入框
*/
Tree.prototype.setValue = function(value, arr)
{
    this.setObjValue( this.idObj, value);
    this.setObjValue( this.nameObj, arr[0]);

    if(this.nameObj)
    {
        try
        {
            this.nameObj.title = arr[1];
        }
        catch(e)
        {
        }
    }
}

/*
* 工具函数,找到指定对象的left值
*/
function findLeft(srcObj)
{
    var sum = 0;
    while(srcObj)
    {
        //alert(srcObj.tagName + ":" + srcObj.offsetLeft);
        if(srcObj.offsetLeft && srcObj.tagName != "TR")
        {
            sum += srcObj.offsetLeft;
        }
        srcObj = srcObj.parentNode;
        
        if( srcObj.tagName == "BODY" )
        {
            break;
        }
    }
    
    return sum;
}

/*
* 工具函数,找到指定对象的top值
*/
function findTop(srcObj)
{
    var sum = 0;
    while(srcObj)
    {
        //alert(srcObj.tagName + ":" + srcObj.offsetTop);
        if(srcObj.offsetTop && srcObj.tagName != "TR")
        {
            sum += srcObj.offsetTop;
        }
        srcObj = srcObj.parentNode;
        
        if( srcObj.tagName == "BODY" )
        {
            break;
        }
    }
    
    return sum;
}

/*
* 关闭层的显示
*/
Tree.prototype.close = function()
{
    var divObj = eval("_Div" + this.nameSuffix);
    divObj.style.display = "none";
}
/*
* 相应所有Tree控件的省公司选择框的变更事件
*/
function _parentSelectChange(treeIndex)
{
    
    var treeObj = _TreeReg[treeIndex];
    
    treeObj.changeParentSelect();
}

/*
* 相应所有Tree控件的市公司选择框的变更事件
*/
function _childrenSelectChange()
{
    //do nothing
}

/*
* 相应所有Tree控件的确定按钮点击事件
*/
function _okBtnClick(treeIndex)
{
    var treeObj = _TreeReg[treeIndex];
    treeObj.ok();
}

/*
* 相应所有Tree控件的取消按钮点击事件
*/
function _cancleBtnClick(treeIndex)
{
    var treeObj = _TreeReg[treeIndex];
    
    treeObj.cancel();
}

function _mouseOut()
{
    var srcEle = event.srcElement;
    var srcId = srcEle.id;
    var index = srcId.lastIndexOf("_");
    var cnt = srcId.substring(index + 1, srcId.length);
    var treeObj = _TreeReg[cnt];
    
    treeObj.cancel();
}

function _findNextSibling(obj)
{
    if(obj)
    {
        var nextObj = obj.nextSibling;
        while(nextObj)
        {
            if(nextObj.nodeName == "#text")
            {
                nextObj = nextObj.nextSibling;
            }
            else
            {
                break;
            }
        }
        
        return nextObj;
    }
    else
    {
        return null;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -