﻿/**
 *<p>Title:菜单对象的基类</p>
 *<p>Description: 生成菜单对象的基类，相对于C#中的抽像类</p>
 *<p>Copyright:Copyright(c)2008</p>
 *<p>Company:Null</p>
 *@author：宋雷鸣 QQ:10522779
 *@version：0.2
 */
 
//主方法
//参数xmlFilePath:要读取的XML文档的路径；
//参数TagId:菜单所处的HTML节点的Id,即容器id;
function Menu(xmlFilePath,TagId)
{	
	if(xmlFilePath!=null)
		this.XmlFilePath=xmlFilePath;	
	if(TagId!=null)
	{
		this.Container=document.getElementById(TagId);			
	}
	//如果菜单处在的容器id不为空，xml文档路径也为空，则开始生成
	if(this.Container!=null&&this.XmlFilePath!=null)
	{		
		this.Builder(this.XmlFilePath,this.TagId);	
	}else
	{
		return;
	}
}
//全局变量
//处于html页面中的容器的对象
Menu.prototype.Container=null;
//XML的文件路径
Menu.prototype.XmlFilePath=null;
//菜单对象在浏览器中的唯一标识
Menu.prototype.MenuId=0;
//附加节点
Menu.prototype.AppendNode=new Array();
//附加前节点
Menu.prototype.FrontNode=null;
//附加后节点
Menu.prototype.AfterNode=null;
//
// 全局变量
Menu.prototype.xmlPath="/Console/xml/";
Menu.prototype.cssPath="/Console/style/";
Menu.prototype.imgPath="/Console/image/";
//预载图片
Menu.prototype.loadingImg="/Console/image/loading/load_015.gif";
//生成菜单的主方法
Menu.prototype.Builder=function(xmlFilePath,TagId)
{
	if(xmlFilePath!=null)
		this.XmlFilePath=xmlFilePath;
	if(TagId!=null)
		this.Container=document.getElementById(TagId);
	//菜单唯一id
	window.MenuObjectNumber=window.MenuObjectNumber==null? 1 : window.MenuObjectNumber+1;
	this.MenuId="menu_"+window.MenuObjectNumber;
	this.Container.setAttribute("MenuContainer",this.MenuId);
	if(this.Container!=null&&this.XmlFilePath!=null)
	{
		//获取数据，默认为异步
		var xmlhelper=new XmlHelper(this.xmlPath+this.XmlFilePath);
		xmlhelper.Request(this);
	}	
};
//返回主菜单HTML节点,
//参数依次为：节点名称，层深，序号
Menu.prototype.BuilderHTML=function(nodeName,level)
{	
	level=level==null ? 0 : level;
	//菜单项的父节点，即菜单面板
	var divBox=document.createElement("div");	
	return divBox;
};
//菜单还原
Menu.prototype.Revert=function()
{	
	
};
//载入过程中的loading
Menu.prototype.Loading=function()
{	
	if(this.Container!=null)
	{
		//alert("loading...");		
		this.Container.innerHTML="<img src='"+this.loadingImg+"'/>";
				
	}
};
//当加载成功;正确返回后
Menu.prototype.SuccessEvent=function()
{
	if(this.Container!=null)
	{
		this.Container.innerHTML="";
	}
};
//当加载成功；完成所有的工作后
Menu.prototype.CompleteEvent=function()
{
	if(this.Container!=null)
	{
		//this.Container.innerHTML="";
	}
};
//当加载成功，但没有正确反返回，如请求信息不存在
Menu.prototype.NothingEvent=function()
{
	if(this.Container!=null)
	{
		var txt="读取完成，但没有获取到信息！";
		this.Container.innerHTML=txt;
		alert(txt);
	}
};
//加载过程中出现问题
Menu.prototype.ErrorEvent=function()
{
	if(this.Container!=null)
	{
		this.Container.innerHTML="加载出错";
	}
};
