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

📄 xmlobject.js

📁 一个用javascript实现的工作流定义工具
💻 JS
字号:
function xmlstep(id, txt, type)
{
	this.id = id;
	this.text = txt;
	this.type = type;
	this.left = 0;
	this.top = 0;

	this.toXML = function()
	{
		var ret = '<Step>';
		ret += '<Properties id="' + this.id + '"';
		ret += ' text="' + this.text + '"';
		ret += ' type="' + this.type + '"';
		ret += ' left="' + this.left + '"';
		ret += ' top="' + this.top + '"/>';

		// ------  其他属性  ------

		ret += '</Step>';

		return ret;
	}

	this.parseData = function(e)
	{
		var bp = e.contents[0];

		this.id = bp.attributes["id"];
		this.text = bp.attributes["text"];	
		this.type = bp.attributes["type"];
		this.left = parseInt(bp.attributes["left"]);
		this.top = parseInt(bp.attributes["top"]);

		// -------- 其他属性 -------
	}
}

function xmlsteplist()
{
	this.steps = null;

	this.toXML = function()
	{
		var ret = '';

		if (this.steps == null)
			return ret;

		ret = '<Steps>';

		for (var n = 0; n < this.steps.length; n ++)
			ret += this.steps[n].toXML();

		ret += '</Steps>';
		
		return ret;
	}
	
	this.parseData = function(e)
	{
		for (var n = 0; n < e.contents.length; n ++)
		{
			var step = new xmlstep('', '', '');
			step.parseData(e.contents[n]);
			this.addStep(step);
		}
	}

	this.addStep = function(stp)
	{
		if (this.steps == null)
		{
			this.steps = new Array();
			this.steps[0] = stp;
		}
		else
			this.steps[this.steps.length] = stp;	
	}

	this.newStep = function(id, txt, type)
	{
		var step = new xmlstep(id, txt, type);

		this.addStep(step);

		return step;
	}

	this.getStep = function(id)
	{
		var ret = null;
		if (this.steps == null)
			return ret;

		for (var n = 0; n < this.steps.length; n ++)
		{
			if (this.steps[n].id == id)
			{
				ret = this.steps[n];
				break;
			}
		}

		return ret;
	}

	this.deleteStep = function(id)
	{
		var ret = false;
		if (this.steps == null)
			return ret;

		var find = false;
		for (var n = 0; n < this.steps.length; n ++)
		{
			if ((this.steps[n].id == id) && (! find))
			{
				find = true;
				ret = true;
			}
			if ((find) && (n != this.steps.length - 1))
			{
				this.steps[n] = this.steps[n + 1];
			}
		}

		this.steps.length = this.steps.length - 1;

		return ret;
	}
}

function xmlaction(id, txt, from, to)
{
	this.id = id;
	this.text = txt;
	this.from = from;
	this.to = to;

	this.toXML = function()
	{
		var ret = '<Action>';
		ret += '<Properties id="' + this.id + '"';
		ret += ' text="' + this.text + '"';
		ret += ' from="' + this.from + '"';
		ret += ' to="' + this.to + '"/>';
		// -------- 其他属性 -------

		ret += '</Action>';

		return ret;
	}

	this.parseData = function(e)
	{
		var bp = e.contents[0];

		this.id = bp.attributes["id"];
		this.text = bp.attributes["text"];	
		this.from = bp.attributes["from"];
		this.to = bp.attributes["to"];

		// -------- 其他属性 -------
	}
}

function xmlactionlist()
{
	this.actions = null;

	this.toXML = function()
	{
		var ret = '';

		if (this.actions == null)
			return ret;

		ret = '<Actions>';

		for (var n = 0; n < this.actions.length; n ++)
			ret += this.actions[n].toXML();

		ret += '</Actions>';
		
		return ret;
	}
	
	this.parseData = function(e)
	{
		for (var n = 0; n < e.contents.length; n ++)
		{
			var act = new xmlaction('', '', '', '');
			act.parseData(e.contents[n]);
			this.addAction(act);
		}
	}

	this.addAction = function(act)
	{
		if (this.actions == null)
		{
			this.actions = new Array();
			this.actions[0] = act;
		}
		else
			this.actions[this.actions.length] = act;	
	}

	this.newAction = function(id, txt, from, to)
	{
		var act = new xmlaction(id, txt, from, to);

		this.addAction(act);

		return act;
	}

	this.getAction = function(id)
	{
		var ret = null;
		if (this.actions == null)
			return ret;

		for (var n = 0; n < this.actions.length; n ++)
		{
			if (this.actions[n].id == id)
			{
				ret = this.actions[n];
				break;
			}
		}

		return ret;
	}

	this.deleteAction = function(id)
	{
		var ret = false;
		if (this.actions == null)
			return ret;

		var find = false;
		for (var n = 0; n < this.actions.length; n ++)
		{
			if ((this.actions[n].id == id) && (! find))
			{
				find = true;
				ret = true;
			}
			if ((find) && (n != this.actions.length - 1))
			{
				this.actions[n] = this.actions[n + 1];
			}
		}

		this.actions.length = this.actions.length - 1;

		return ret;
	}

	this.deleteActByStepID = function(id)
	{
		var ret = false;
		if (this.actions == null)
			return ret;
		for (var n = this.actions.length - 1; n >= 0; n --)
		{
			//alert(id + '-' + this.actions[n].from + '+' + this.actions[n].to);
			if ((id == this.actions[n].from) || (id == this.actions[n].to))
				this.deleteAction(this.actions[n].id);
		}
	}
}

function xmlflow(XML)
{
	this.InitByXML = false;

	this.text = '新建流程';
	this.id = 'newflow1';

	this.steps = new xmlsteplist();
	this.actions = new xmlactionlist();

	this.parseSelf = function(obj)
	{
		var prop = obj.contents[0];
		this.id = prop.attributes['id'];
		this.text = prop.attributes['text'];
	}

	this.parseData = function(xml)
	{
		if((xml != null) && (xml != ''))
		{

			var xmlRoot = new Xparse(xml);

			var flowObj = xmlRoot.contents[0];
			//alert(flowObj.contents);
			var cfgObj = flowObj.contents[0];     // 流程属性
			var stpObj = flowObj.contents[1];     // 步骤列表 
			var actObj = flowObj.contents[2];     // 动作列表

			this.parseSelf(cfgObj);
			this.steps.parseData(stpObj);
			this.actions.parseData(actObj);

			this.InitByXML = true;
		}
	}
	
	this.parseData(XML);

	this.getConfig = function()
	{
		var ret = '<Config>';
		ret += '<Properties id="' + this.id + '" text="' + this.text + '"/>';
		ret += '</Config>';
		return ret;
	}

	this.toXML = function()
	{
		var ret = '<?xml version="1.0" encoding="GBK" ?>';

		ret += '<Flow>';
		ret += this.getConfig();
		ret += this.steps.toXML();
		ret += this.actions.toXML();
		ret += '</Flow>';
		return ret;
	}
}

⌨️ 快捷键说明

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