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

📄 tree.js

📁 CallSun 人才招聘求职系统 V2.20
💻 JS
📖 第 1 页 / 共 2 页
字号:
    chkBox.setAttribute("ParentID",strParentID);
    chkBox.setAttribute("RowsAffected",0);
    chkBox.setAttribute("summary","");
    if (intType == 1)
    {
        chkBox.setAttribute("IsParent",false);
        chkBox.onclick = function(){setChecked(strID);};
    }
    else
    {
        chkBox.setAttribute("IsParent",true);
        chkBox.onclick = function(){setCheckedGroup(strID);};
    }
    return chkBox;
}

function setCheckedGroup(strID)
{
    var nodeList = null;
    nodeList = getChildren(strID);
    if (nodeList != null)
    {
        var checked = document.getElementById("chk" + strID).checked;
        
        for(var i = 0;i < nodeList.length; i ++)
        {
            nodeList[i].checked = checked;            
        }
    }
}

function setChecked(strID)
{
    var nodeParent = null;
    nodeParent = getParentByChildID(strID);
    if (nodeParent != null)
    {
        nodeParent.checked = hasSelected(nodeParent.value);
    }
}

function getParentByChildID(strID)
{
    var nodeParent = null;
    var pid = document.getElementById("chk" + strID).ParentID;
    nodeParent = document.getElementById("chk" + pid);
	return nodeParent;
}

function getChildren(strID)
{
    var nodeChildren = new Array();
    var intIndex = 0;
	var length = nodeList.length;
	for (var i = 0; i < length; i ++)
	{
		var row = nodeList[i];
		if (row[1] == strID)
		{
		    var id = "chk" + row[i][1];
		    nodeChildren[intIndex] = document.getElementById(id);
		    intIndex ++;
		}
	}
	if (nodeChildren.length == 0)
	{
	    nodeChildren = null;
	}
	return nodeChildren;
}

function hasSelected(strID)
{
    var bSelected = false;
    var intIndex = 0;
	var length = nodeList.length;
	for (var i = 0; i < length; i ++)
	{
		var row = nodeList[i];
		if (row[1] == strID)
		{
		    var id = "chk" + row[i][1];
		    if (document.getElementById(id).checked == true)
		    {
		        bSelected = true;
		        break;
		    }
		}
	}
	return bSelected;    
}

function MoveSortInputPart(id)
{
    var obj = document.getElementById("SortItem");
    var objEvent = document.getElementById("a" + id);
    obj.style.display = "block";
    obj.style.left = getBrowserPositionX(objEvent);
    obj.style.top = getBrowserPositionY(objEvent);
}

function GetNodeById(id)
{
    return nodeList[id];
}
/// <summary>
/// 显示类别输入板块
/// </summary>
/// <param name="id">引发事件的类别编号</param>
/// <param name="action">要实行的动作:(0表示添加子节点,1表示添加兄弟节点,2表示编辑当前节点)</param>
/// <returns></returns>
function ShowSortInputPart(id,action)
{
    HideMenu();
    NodeId = id;
    MethodId = action;
    if (action == 3)
    {
        DeleteNode();
    }
    else
    {
        if (action == 2)
        {
            var node = GetNodeById(id);
            document.getElementById("Name").value = node.text;
        }
        MoveSortInputPart(id);
        DisplayBlock("SortItem","block");
    }
}

function CheckSortNameExist(sortName,sortId)
{
    var result = false;
    for (var i = 0; i < nodeList.length; i++)
    {
        if ((nodeList[i].text.toLowerCase() == sortName.toLowerCase()) && (nodeList[i].id != sortId))
        {
            result = true;
            break;
        }
    }
    return result;
}

function AddChildNode()
{
    var result = false;
    var sort = document.getElementById("Name");
    var chk = CheckSortNameExist(sort.value, -99);
    if (chk)
    {
        sort.focus();
        alert("名称不能相同");
    }
    else
    {
        var node = GetNodeById(NodeId);
        var newNode = new TreeNode();
        newNode.id = nodeList.length;
        newNode.text = sort.value;
        newNode.parentId = node.id;
        newNode.parentText = node.text;
        newNode.num = newNode.id;
        newNode.hasChild = 0;
        nodeList[nodeList.length] = newNode;
        nodeList[node.id].hasChild = 1;
        processData();
        result = true;
    }
    return result;
}

function AddBrotherNode()
{
    var result = false;
    var sort = document.getElementById("Name");
    var chk = CheckSortNameExist(sort.value, -99);
    if (chk)
    {
        sort.focus();
        alert("名称不能相同");
    }
    else
    {
        var node = GetNodeById(NodeId);
        var newNode = new TreeNode();
        newNode.id = nodeList.length;
        newNode.text = sort.value;
        newNode.parentId = node.parentId;
        newNode.parentText = node.parentText;
        newNode.hasChild = 0;
        newNode.num = newNode.id;
        nodeList[nodeList.length] = newNode;
        processData();
        result = true;
    }
    return result;
}

function UpdateNode()
{
    var result = false;
    var sort = document.getElementById("Name");
    var chk = CheckSortNameExist(sort.value, NodeId);
    if (chk)
    {
        sort.focus();
        alert("名称不能相同");
    }
    else
    {
        nodeList[NodeId].text = sort.value;
        var nodes = getChildren(NodeId);
        if (nodes != null)
        {
            for (var i = 0; i < nodes.length; i++)
            {
                nodeList[nodes[i].id].parentText = sort.value;
            }
        }
        processData();
        result = true;
    }
    return result;
}

function DeleteNode()
{
    var result = false;
    if (hasChild(NodeId) == true)
    {
        alert("该节点下还有字节点,请先删除子节点。");
    }
    else
    {
        if (nodeList.length <= 1)
        {
            alert("不能删除节点,必须至少有一个节点存在.");
        }
        else
        {
            var node = GetNodeById(NodeId);
            var parentId = node.parentId;
            nodeList.splice(NodeId,1);
            if (!hasChild(parentId))
            {
                var parentNode = GetNodeById(parentId);
                parentNode.hasChild = 0;
            }
            processData();
            result = true;
        }
    }
    return result;
}

function Cancel()
{
    DisplayBlock("SortItem","none");
}

function OK()
{
    var result = false;
    if (ControlCheck(new FormControl("Name",CheckType.CheckEmpty,true,"请输入类别名称")))
    {
        AltMessage("block");
        switch(MethodId)
        {
            case 0 :
                result = AddChildNode();
                break;
            case 1 :
                result = AddBrotherNode();
                break;
            case 2 :
                result = UpdateNode();
                break;
        }
        AltMessage("none");
    }
    if (result)
    {
        Cancel();
    }
}

function AltMessage(action)
{
    var obj = document.getElementById("AltMessage");
    var objEvent = document.getElementById("a" + NodeId);
    if (objEvent != null)
    {
        obj.style.display = action;
        obj.style.left = objEvent.offsetLeft + objEvent.offsetWidth;
        obj.style.top = objEvent.offsetTop;
    }
}

function SaveTree()
{
    if (confirm("确定保存目录树吗?"))
    {
        var value = "";
        var ch0 = "\"";
        var ch1 = "\",\"";
        var spliter = "|-|";
        for (var i = 0; i < nodeList.length; i++)
        {
            value += ch0 + nodeList[i].text + ch1 + nodeList[i].parentText + ch1 + nodeList[i].text + ch1 + nodeList[i].num + ch0 + "," + nodeList[i].hasChild + spliter;
        }
        document.getElementById("TreeValue").value = value;
        document.forms[0].submit();
    }
}

⌨️ 快捷键说明

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