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

📄 deptree.js

📁 很全面的hrm管理。提供通用的企业人力资源管理。
💻 JS
📖 第 1 页 / 共 2 页
字号:
/*--------------------------------------------------|
| dTree 2.05 | www.destroydrop.com/javascript/tree/ |
|---------------------------------------------------|
| Copyright (c) 2002-2003 Geir Landr?              |
|                                                   |
| This script can be used freely as long as all     |
| copyright messages are intact.                    |
|                                                   |
| Updated: 17.04.2003                               |
|--------------------------------------------------*/

var checkedValueArray = new Array();
var inputValueArray = new Array();
var isGetParent = false;

// Node object 
function Node(id, pid, name, radioValue, isLeaf, url, title, target, icon, iconOpen, open) {
	this.id = id;
	this.pid = pid;
	this.name = name;
	this.radioValue = radioValue;
	this.url = url;
	this.title = title;
	this.target = target;
	this.icon = icon;
	this.iconOpen = iconOpen;
	this._io = open || false;
	this._is = false;
	this._ls = false;
	this._hc = false;
	this._ai = 0;
	this._p;	
	this.leaf = isLeaf;
};

// Tree object
function dTree(objName,inputParameter,isOnlyLeafRadio, checkOrRadio) {
	this.config = {
		target					: null,
		folderLinks			: true,
		useSelection		: true,
		useCookies			: true,
		useLines				: true,
		useIcons				: true,
		useStatusText		: false,
		closeSameLevel	: false,
		inOrder					: false
	}
	this.icon = {
		root				: '../images/dtree/base.gif',
		folder			: '../images/dtree/folder.gif',
		folderOpen	: '../images/dtree/folderopen.gif',
		node				: '../images/dtree/page.gif',
		empty				: '../images/dtree/empty.gif',
		line				: '../images/dtree/line.gif',
		join				: '../images/dtree/join.gif',
		joinBottom	: '../images/dtree/joinbottom.gif',
		plus				: '../images/dtree/plus.gif',
		plusBottom	: '../images/dtree/plusbottom.gif',
		minus				: '../images/dtree/minus.gif',
		minusBottom	: '../images/dtree/minusbottom.gif',
		nlPlus			: '../images/dtree/nolines_plus.gif',
		nlMinus			: '../images/dtree/nolines_minus.gif'
	};
	this.obj = objName;
	this.inputValue = inputParameter;
	this.onlyLeafRadio = isOnlyLeafRadio;
	this.checkOrRadio = checkOrRadio;
	this.postPara = "";	
	this.aNodes = [];
	this.aIndent = [];
	this.root = new Node(-1);
	this.selectedNode = null;
	this.selectedFound = false;
	this.completed = false;
	this.onclick = _tree_on_click;
	this.id = "dtreeId_"+this.obj;
	
	if(this.inputValue != undefined){
		for (key in this.inputValue)   {
      this.postPara += key+"="+this.inputValue[key]+"&";
   	}
   	this.postPara = this.postPara.substr(0,this.postPara.length - 1);
	}
};

function _tree_on_click(obj) {
	if(obj.flag="treeRadio"){
		//setValueByTree(obj);		
		setValueWithParentByList(obj);
	}
};

// Returns the checked node
function getCheckedValue() {
	return checkedValueArray;
};

// Returns the checked node
function getCheckedValueArray() {
	return checkedValueArray;
};



// [Cookie] Sets value in a cookie
function  setValueByTree(radioObj) {
	if(radioObj.checked == true){
		checkedValueArray['value'] = radioObj.value;
		checkedValueArray['text'] = radioObj.text;
		for (key in inputValueArray)   {	
			if(radioObj.getAttribute(key) != null){		
    		checkedValueArray[key] = radioObj.getAttribute(key);    	
    	}
  	} 
	}			
}

function setValueByList(obj){
	if(obj.checked == true){
		checkedValueArray['value'] = obj.value;
		checkedValueArray['text'] = obj.text;
		for (key in inputValueArray)   {	
			if(obj.getAttribute(key) != null){
    		checkedValueArray[key] = obj.getAttribute(key);    	
    	}
  	} 
	}
}

function setValueWithParentByList(obj,isGetParent){
	if(obj.checked == true){
		document.getElementById("current_dept_uuid_div").innerHTML = "<input type='text' name='CurrentDeptUuid' value='"+obj.value+"'>";
		if(isGetParent){
			checkedValueArray['current'] = new Array();
			checkedValueArray['current']['id'] = obj.value;
			checkedValueArray['current']['name'] = obj.text;
			for (key in inputValueArray)   {	
				if(obj.getAttribute(key) != null){
	    		checkedValueArray['current'][key] = obj.getAttribute(key);    	
	    	}
	  	} 
	  	  	
	  	var parent = document.getElementById(obj.parentElement.getAttribute("parentId"));
	  	var pvalue = parent.getElementsByTagName("INPUT");	  

	  	checkedValueArray['parent'] = new Array();
	  	checkedValueArray['parent']['id'] = pvalue[0].value;
		checkedValueArray['parent']['name'] = pvalue[0].text;
		for (key in inputValueArray){
			if(pvalue[0].getAttribute(key) != undefined && pvalue[0].getAttribute(key) != null)	{
	    		checkedValueArray['parent'][key] = pvalue[0].getAttribute(key);    	
	    	}
	  	}   	
	  }else{	  
		checkedValueArray = new Array();
		checkedValueArray['id'] = obj.value;
		checkedValueArray['name'] = obj.text;
		for (key in inputValueArray)   {	
			if(obj.getAttribute(key) != null){
		    	checkedValueArray[key] = obj.getAttribute(key);    	
		    }
		  }  	
		}
	}
}

function setDepartmentValue(val,text,type){
	var valueObj = document.getElementById(val);
	var textObj = document.getElementById(text);	
	if(type == undefined || type == null || type == ""){
		type = "T";
	}
	var newWindow = window.showModalDialog("../common/deptListAction.do?DisplayType="+type);
	if(newWindow['id'] == undefined || newWindow['name'] == undefined){
			alert("请选择值");
			return;
	}
	valueObj.value = newWindow['id'];
	//newWindow['current']['value'];
	textObj.value =  newWindow['name'];
	//newWindow['current']['text'];
}

function getDepartmentValue(type){
	if(type == undefined || type == null || type == ""){
		type = "T";
	}
	var newWindow = window.showModalDialog("../common/deptListAction.do?DisplayType="+type);
	if(newWindow['id'] == undefined || newWindow['name'] == undefined){
			alert("请选择值");
			return;
	}
	return newWindow;
}

function getDepartmentValueByPara(contenUrl){
	var newWindow = window.showModalDialog("department.html",inputValueArray);
	return newWindow;
}


function setPersonValue(valId,textId){
	var valueObj = document.getElementById(valId);
	var textObj = document.getElementById(textId);	
	var newWindow = window.showModalDialog("person.html");
	if(newWindow == undefined){
			alert("请选择值");
			return;
	}
	if(newWindow['value'] == undefined || newWindow['value'] == undefined){
		valueObj.value = newWindow[0]['value'];
		textObj.value =  newWindow[0]['text'];
		return;
	}
	valueObj.value = newWindow['value'];
	textObj.value =  newWindow['text'];
	
}

//得到人员代号,名称并赋值给id号为:val,text的对象
function getPersonValueByPara(contenUrl){
	var newWindow = window.showModalDialog("person.html",inputValueArray);
	return newWindow;
}

function setValue(key,val){
	inputValueArray[key] = val;
}


// Adds a new node to the node array
dTree.prototype.add = function(id, pid, name, radioValue, isLeaf, URL, title, target, icon, iconOpen, open) {
	this.aNodes[this.aNodes.length] = new Node(id, pid, name, radioValue, isLeaf, URL, title, target, icon, iconOpen, open);
};

// Open/close all nodes
dTree.prototype.openAll = function() {
	this.oAll(true);
};
dTree.prototype.closeAll = function() {
	this.oAll(false);
};

// Outputs the tree to the page
dTree.prototype.toString = function() {
	var str = '<div id="'+this.id+'" class="dtree">\n';
	if (document.getElementById) {
		if (this.config.useCookies) this.selectedNode = this.getSelected();
		str += this.addNode(this.root);
	} else str += 'Browser not supported.';
	str += '</div>';
	if (!this.selectedFound) this.selectedNode = null;
	this.completed = true;
	//str+="<textarea rows='40' cols='400'>"+str+"</textarea>";
	return str;
};

// Creates the tree structure
dTree.prototype.addNode = function(pNode) {
	var str = '';
	var n=0;
	if (this.config.inOrder) n = pNode._ai;
	for (n; n<this.aNodes.length; n++) {
		if (this.aNodes[n].pid == pNode.id) {
			var cn = this.aNodes[n];
			cn._p = pNode;
			cn._ai = n;
			this.setCS(cn);
			if (!cn.target && this.config.target) cn.target = this.config.target;
			if (cn._hc && !cn._io && this.config.useCookies) cn._io = this.isOpen(cn.id);
			if (!this.config.folderLinks && cn._hc) cn.url = null;
			if (this.config.useSelection && cn.id == this.selectedNode && !this.selectedFound) {
					cn._is = true;
					this.selectedNode = n;
					this.selectedFound = true;
			}
			str += this.node(cn, n);
			if (cn._ls) break;
		}
	}
	return str;
};

// Creates the node icon, url and text
dTree.prototype.node = function(node, nodeId) {
	var str = '<div id="nodeId'+nodeId+'" parentId=\"nodeId'+node.pid+'\" style="height:13px" class="dTreeNode">' + this.indent(node, nodeId);
	var inputType = (this.checkOrRadio == 1 ? "checkbox" : "radio");
	if(this.onlyLeafRadio == undefined || !this.onlyLeafRadio){
		str += '<input type=\"'+inputType+'\" id="FlagInput" name="radiobox" flag="treeRadio"';
		for (key in this.inputValue)   {
			str = str + " "+key+"='"+this.inputValue[key]+"' ";
		}  
		str +='value="'+node.radioValue+'" text="'+node.name+'" onclick="setCheckedValue(this)" style="height:13px;width:13px">&nbsp;';	
	}
	
	if((node.leaf == undefined || !node.leaf) && this.onlyLeafRadio){
		str += '<input type=\"hidden\" id="FlagInput" name="radiobox" flag="treeRadio"';
		//for (key in this.inputValue)   {
			//str = str + " "+key+"='"+this.inputValue[key]+"' ";
		//}  
		str +='value="'+node.radioValue+'" text="'+node.name+'" onclick="setCheckedValue(this)" style="height:13px;width:13px">&nbsp;';	
	}
	
	if(node.leaf && this.onlyLeafRadio){
		str += '<input type=\"'+inputType+'\" name="radiobox" flag="treeRadio"';

⌨️ 快捷键说明

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