当前位置: 首页 > 工具软件 > YAD_Designer > 使用案例 >

menu designer

郭修平
2023-12-01
function MenuDesigner() {
	
	this.onDrapEventId = "";
	this.designerRelationMgr = null;
	this.mediator = null;
	this.selectParent_frame = null;            //调用选择上级节点页面(创建或修改页面)的_frame对象
	this.menuEntity = null;                    //菜单实体对象
	this.dhxWin = null;                        //dhxWindow对象
	this.dhxAccord = null;                     //dhxAccordion对象
	this.dhxTreeMap = null;                    //各百叶窗下所属的dhxTree的Map集合
	
	
	this.create = createMenu;                  //创建菜单单元
	this.loadXml = loadMenu                    //加载菜单单元
	this.preview = previewMenu;                //预览菜单单元
	this.toXml = toXmlMenu;                    //返回菜单单元数据
	this.destory = destoryMenu;                 //销毁菜单单元
	this.resize = resizeMenu;
	this.setVersion = setMenuVersion;          //设置菜单单元版本
	
	this.drapFunction=drapMenuFunction;
	
}

/**
 * 保存菜单的资源地址
 * @param menuId 菜单项Id
 * @param menuResourceURL 资源地址URL
 * @return BOC保存资源地址状态,"true"为保存成功,"false"为保存失败
 */
function setMenuResourceURL(menuId, menuResourceURL) {
	//调用BOC执行菜单项资源地址更新操作----------START------------
	var clientBoc = new ClientBOController('menuitem_boc','updateResourceURL');
	clientBoc.addParameter("id",menuId);
	clientBoc.addParameter("resourceURL",menuResourceURL);
	bocInvoker.bocName = "BOControllerAction";
	bocInvoker.bocMethod = "executeBoc";
	var update_result = bocInvoker.invokeSynchronized(clientBoc);
	//调用BOC执行菜单项资源地址更新操作----------END------------
	return update_result;
}




/**
 * 设置菜单版本
 * @param version 版本号
 */
function setMenuVersion(version) {
	this.menuEntity.version = version;
}




/**
 * 调整高度/宽度
 * @param unitId 当前填充单元的ID
 * @param height 当前填充单元高度
 * @param width 当前填充单元宽度
 */
function resizeMenu(unitId,height,width){
	
}


/**
 * 将菜单单元Xml格式数据返回给布局进行保存操作
 * @return 菜单单元Xml字符串格式
 */
function toXmlMenu() {
	var menuEntityXml = this.menuEntity.toXmlString();
	return menuEntityXml;
}


/**
 * 创建预览的百叶窗菜单项
 * @param menuItemObj 菜单项实体
 * @param mediator 父类提供的mediator对象
 * @param currentMode "USER_MODE"为用户模式,"NORMAL_MODE"为预览模式
 * @param containerObj 布局容器对象
 * @param targetId 目标Id
 * @param layoutType 布局类型,"MAIN_LAYOUT"为主界面布局
 * @param applicationId 应用Id
 */
function _createPreviewAccord(menuItemObj, mediator, currentMode, containerObj, targetId, layoutType, applicationId, designer) {
	var menuItemId = menuItemObj.id;
	var menuItemName = menuItemObj.name;
	var resourceURL = menuItemObj.resourceURL;
	var menuItemType = menuItemObj.type;
	
	designer.dhxAccord.addItem(menuItemId, menuItemName, targetId);
	var labelDivId = "dhxAccord_item_labelId_"+targetId+"_"+menuItemId;
	var $lableObj = jQuery("div #" + labelDivId);
	$lableObj.bind('mouseup',function(e) {
		if (!e) e = window.event;
		if (e.button == 0 || e.button == 1) {
			designer.dhxAccord.cells(menuItemId).open();
			//点击菜单项,链接到资源地址或装配的页面
			_linkURL(mediator, resourceURL, menuItemId, currentMode, menuItemType);
		}
	});
	var contDivId = "dhxAccord_contentId_"+targetId+"_"+menuItemId;
	var $contObj = jQuery("div #" + contDivId);
	$contObj.bind('mouseup',function(e) {
		if (!e) e = window.event;
		if (e.button == 2) {
			var contMenu = new dhtmlXMenuObject();
			contMenu.setSkin('dhx_ibusblue');
			contMenu.setIconsPath(path+"/jsp/developcenter/unitdesigner/menu/imgs/dhtmlx/dhtmlxMenu/");
			contMenu.renderAsContextMenu();
			contMenu.addContextZone(contDivId);
			contMenu.attachEvent("onClick",function(itemId) {
				if(itemId == "reflush") { //重新刷新菜单
					//调用BOC执行重新加载菜单XML操作----------START------------
					var clientBoc = new ClientBOController('menuitem_boc','reLoad');
					clientBoc.addParameter("unitId",targetId);
					bocInvoker.bocName = "BOControllerAction";
					bocInvoker.bocMethod = "executeBoc";
					var menuXml = bocInvoker.invokeSynchronized(clientBoc);
					//调用BOC执行重新加载菜单XML操作----------END------------
					designer.menuEntity = null;
					designer.dhxWin = null;
					designer.dhxAccord = null;
					designer.dhxTreeMap = null;
					var menuEntityDoc = parseXml(menuXml);
					_showPreviewMenu(menuEntityDoc, containerObj, targetId,layoutType,applicationId, currentMode, mediator, designer);  //创建显示重新加载的菜单
				}
			});
			var contMenuXML = "<?xml version='1.0'?>" +
							  "<menu>" + 
							  	"<item id='reflush' text='刷新'/>" +
							  "</menu>";
			contMenu.clearAll();
			contMenu.loadXMLString(contMenuXML);
			cancleEventUp(e);
			return true;
		}
	});
	
	designer.menuEntity.items.put(menuItemId, menuItemObj);
	var dhxTree = designer.dhxAccord.cells(menuItemId).attachTree(0);
	dhxTree.setSkin('dhx_ibusblue');
	dhxTree.setImagePath(path+"/jsp/developcenter/unitdesigner/menu/imgs/dhtmlx/dhtmlxTree/ibus_blue/");
	designer.dhxTreeMap.put(menuItemId, dhxTree);
}






/**
 * 创建显示预览菜单
 * @param menuEntityDoc 菜单XMLDOM
 * @param containerObj 布局容器对象
 * @param targetId 目标Id
 * @param layoutType 布局类型,"MAIN_LAYOUT"为主界面布局
 * @param applicationId 应用Id
 * @param currentMode "USER_MODE"为用户模式,"NORMAL_MODE"为预览模式
 * @param mediator 父类提供的mediator对象
 * @return
 */
function _showPreviewMenu(menuEntityDoc, containerObj, targetId,layoutType,applicationId, currentMode, mediator, designer) {
	var menuEntityRoot = menuEntityDoc.documentElement;				//获得根节点
	var entityChildNodes = menuEntityRoot.childNodes;
	_initMenuResource(containerObj, targetId, layoutType, applicationId, designer);
	var loadMenuEntity = designer.menuEntity;
	loadMenuEntity.setAttribute(menuEntityRoot.getAttributeNode("name").nodeValue, menuEntityRoot.getAttributeNode("style").nodeValue);
	loadMenuEntity.appId = applicationId;
	
	for(var i=0; i<entityChildNodes.length; i++) {
		
		var loadItemObj = new MenuObject();
		var itemId = entityChildNodes[i].getAttributeNode("id").nodeValue;
		var itemAppId = entityChildNodes[i].getAttributeNode("appId").nodeValue;
		var itemName = entityChildNodes[i].getAttributeNode("name").nodeValue;
		var itemCode = entityChildNodes[i].getAttributeNode("code").nodeValue;
		var itemParentId = entityChildNodes[i].getAttributeNode("parentId").nodeValue;
		var itemAbbreviation = entityChildNodes[i].getAttributeNode("abbreviation").nodeValue;
		var itemEnglishName = entityChildNodes[i].getAttributeNode("englishName").nodeValue;
		var itemType = entityChildNodes[i].getAttributeNode("type").nodeValue;
		var itemImage = entityChildNodes[i].getAttributeNode("image").nodeValue;
		var itemImageType = entityChildNodes[i].getAttributeNode("imageType").nodeValue;
		var itemResourceURL = entityChildNodes[i].getAttributeNode("resourceURL").nodeValue;
		var itemRemark = entityChildNodes[i].getAttributeNode("remark").nodeValue;
		var itemOrder = entityChildNodes[i].getAttributeNode("order").nodeValue;
		
		loadItemObj.init(itemId, itemAppId, itemCode, itemName, itemParentId, itemAbbreviation, 
				itemEnglishName, itemType, itemImage, itemImageType, itemResourceURL, itemRemark,itemOrder);
		
		_createPreviewAccord(loadItemObj, mediator, currentMode, containerObj, targetId, layoutType, applicationId, designer); //创建预览的百叶窗菜单项
		var dhtmlxTree = designer.dhxTreeMap.get(itemId);
		dhtmlxTree.enableDragAndDrop("temporary_disabled", false);
		dhtmlxTree.attachEvent("onClick", function(id){
			var itemObj = designer.menuEntity.items.get(id);
			var resourceURL = itemObj.resourceURL;
			var menuItemType = itemObj.type;
			//点击菜单项,链接到资源地址或装配的页面
			_linkURL(mediator, resourceURL, id, currentMode, menuItemType);
		});
		if(entityChildNodes[i].getAttributeNode("isleaf").nodeValue=="0") {
			_tree(entityChildNodes[i], itemId, designer);
		}
	}
}





/**
 * 预览菜单单元
 * @param el 单元定义的Element
 * @param containerObj 布局容器对象
 * @param targetId 目标Id
 * @param layoutType 布局类型,"MAIN_LAYOUT"为主界面布局
 * @param applicationId 应用Id
 * @param currentMode "USER_MODE"为用户模式,"NORMAL_MODE"为预览模式
 */
function previewMenu(el, containerObj, targetId,layoutType,applicationId, currentMode) {
	var menuEntityDoc = parseXml(serializeXml(el));
	var mediator = this.mediator;
	_showPreviewMenu(menuEntityDoc, containerObj, targetId,layoutType,applicationId, currentMode, mediator, this); //创建显示预览菜单
}



/**
 * 加载菜单单元
 * @param containerObj 布局容器对象
 * @param targetId 目标Id
 * @param layoutType 布局类型,"MAIN_LAYOUT"为主界面布局
 * @param applicationId 应用Id
 */
function loadMenu(el, containerObj, targetId,layoutType,applicationId) {
	var menuEntityDoc = parseXml(serializeXml(el));
	var menuEntityRoot = menuEntityDoc.documentElement;				//获得根节点
	var entityChildNodes = menuEntityRoot.childNodes;
	_initMenuResource(containerObj, targetId, layoutType, applicationId, this);
	this.menuEntity.setAttribute(el.getAttributeNode("name").nodeValue, el.getAttributeNode("style").nodeValue);
	this.menuEntity.appId = applicationId;
	_showMenu(entityChildNodes, targetId, this);
	
}


/**
 * 初始化菜单资源
 * @param containerObj 布局容器对象
 * @param targetId 目标Id
 * @param layoutType 布局类型,"MAIN_LAYOUT"为主界面布局
 * @param applicationId 应用Id
 */
function _initMenuResource(containerObj, targetId, layoutType, applicationId, designer) {
	designer.dhxTreeMap = new Map();
	designer.dhxWin = _initDhxWindow(targetId); 
	designer.menuEntity = new MenuEntity(targetId);
	designer.menuEntity.setAttribute("新建菜单单元", "百叶窗");
	designer.menuEntity.appId = applicationId;
	
	if(layoutType == "MAIN_LAYOUT") {
		designer.dhxAccord = containerObj.attachAccordion();
	}else {
		containerObj.setTabActive(targetId);
		designer.dhxAccord = containerObj.cells(targetId).attachAccordion();
	}
	designer.dhxAccord.setSkin('dhx_ibusblue');
}


/**
 * 创建菜单单元
 * @param containerObj 布局容器对象
 * @param targetId 目标Id
 */
function createMenu(containerObj, targetId, layoutType, applicationId) {
	
	_initMenuResource(containerObj, targetId, layoutType, applicationId, this);  //初始化菜单资源
	
	var menuXml = _loadSubsistentMenu(applicationId);  //通过BOC加载该应用已有菜单
	var menuEntityDoc = parseXml(menuXml);
	var menuEntityRoot = menuEntityDoc.documentElement;				//获得根节点
	var entityChildNodes = menuEntityRoot.childNodes;
	
	if(entityChildNodes!=null && entityChildNodes.length!=0) { //若该应用下不存在已有的菜单,则默认创建一个百叶窗(平台级)菜单项
		_showMenu(entityChildNodes, targetId, this);  //创建显示菜单
	}else {
		var menuItemObj = new MenuObject();
		menuItemObj.init(new UUID().id, applicationId, "default_pt1", "平台1", "ibus_menu_root_0", "", "", "1", "", "", "", "","0");
		_createAccordItem(menuItemObj, "create", targetId, this);
	}

}


/**
 * 根据菜单节点信息创建显示菜单
 * @param entityChildNodes 所有菜单节点
 */
function _showMenu(entityChildNodes, targetId, designer) {
	
	for(var i=0; i<entityChildNodes.length; i++) {
		
		var loadItemObj = new MenuObject();
		var itemId = entityChildNodes[i].getAttributeNode("id").nodeValue;
		var itemAppId = entityChildNodes[i].getAttributeNode("appId").nodeValue;
		var itemName = entityChildNodes[i].getAttributeNode("name").nodeValue;
		var itemCode = entityChildNodes[i].getAttributeNode("code").nodeValue;
		var itemParentId = entityChildNodes[i].getAttributeNode("parentId").nodeValue;
		var itemAbbreviation = entityChildNodes[i].getAttributeNode("abbreviation").nodeValue;
		var itemEnglishName = entityChildNodes[i].getAttributeNode("englishName").nodeValue;
		var itemType = entityChildNodes[i].getAttributeNode("type").nodeValue;
		var itemImage = entityChildNodes[i].getAttributeNode("image").nodeValue;
		var itemImageType = entityChildNodes[i].getAttributeNode("imageType").nodeValue;
		var itemResourceURL = entityChildNodes[i].getAttributeNode("resourceURL").nodeValue;
		var itemRemark = entityChildNodes[i].getAttributeNode("remark").nodeValue;
		var itemOrder = entityChildNodes[i].getAttributeNode("order").nodeValue;
		
		loadItemObj.init(itemId, itemAppId, itemCode, itemName, itemParentId, itemAbbreviation, 
				itemEnglishName, itemType, itemImage, itemImageType, itemResourceURL, itemRemark,itemOrder);
		
		_createAccordItem(loadItemObj, '', targetId, designer);
		if(entityChildNodes[i].getAttributeNode("isleaf").nodeValue=="0") {
			_tree(entityChildNodes[i], itemId, designer);
		}
	}
}

/**
 * 递归获取百叶窗下的树节点
 * @param thisLevelNode 当前节点
 * @param accordItemId 百叶窗菜单项Id
 */
function _tree(thisLevelNode, accordItemId, designer) {
	var nodes = thisLevelNode.childNodes;
	for(var i=0; i<nodes.length; i++) {
		
		var loadItemObj = new MenuObject();
		var itemId = nodes[i].getAttributeNode("id").nodeValue;
		var itemAppId = nodes[i].getAttributeNode("appId").nodeValue;
		var itemName = nodes[i].getAttributeNode("name").nodeValue;
		var itemCode = nodes[i].getAttributeNode("code").nodeValue;
		var itemParentId = nodes[i].getAttributeNode("parentId").nodeValue;
		var itemAbbreviation = nodes[i].getAttributeNode("abbreviation").nodeValue;
		var itemEnglishName = nodes[i].getAttributeNode("englishName").nodeValue;
		var itemType = nodes[i].getAttributeNode("type").nodeValue;
		var itemImage = nodes[i].getAttributeNode("image").nodeValue;
		var itemImageType = nodes[i].getAttributeNode("imageType").nodeValue;
		var itemResourceURL = nodes[i].getAttributeNode("resourceURL").nodeValue;
		var itemRemark = nodes[i].getAttributeNode("remark").nodeValue;
		var itemOrder = nodes[i].getAttributeNode("order").nodeValue;
		
		loadItemObj.init(itemId, itemAppId, itemCode, itemName, itemParentId, itemAbbreviation, 
				itemEnglishName, itemType, itemImage, itemImageType, itemResourceURL, itemRemark, itemOrder);
		
		_createTreeItem(loadItemObj, accordItemId, '', designer);
		if(nodes[i].getAttributeNode("isleaf").nodeValue=="0") {
			_tree(nodes[i], accordItemId, designer);
		}
	}
}


/**
 * 创建树菜单项及其右键菜单
 * @param menuItemObj 菜单项实体
 * @param accordItemId 所属百叶窗Id
 * @param status 创建状态标记,若为"create"则先对菜单项实体数据进行保存再创建,否则不保存直接创建
 */
function _createTreeItem(menuItemObj, accordItemId, status, designer) {
	var save_result = (status!=null&&status=="create") ? menuItemObj.save() : "true";

	if(save_result =="true") { 
		var menuItemId = menuItemObj.id;
		var menuName = menuItemObj.name;
		var parentItemId = menuItemObj.parentId;
		var dhxTree = designer.dhxTreeMap.get(accordItemId);
		var parentTreeItemId = parentItemId!=accordItemId ? parentItemId : 0;
		var menuItemImage = menuItemObj.image;
		var defaultImagePath = path+"/jsp/developcenter/unitdesigner/menu/" + menuItemImage.substring(0, menuItemImage.lastIndexOf("/")); //获取图标路径
		dhxTree.setImagePath(defaultImagePath + "/"); //设置图标资源路径(注:修改图标前必须指定图标资源路径,不然dhxTree找不到自定义的图标)
		var image = menuItemImage.substring(menuItemImage.lastIndexOf("/")+1, menuItemImage.length);   //获取图标名称
		dhxTree.insertNewChild(parentTreeItemId,menuItemId, menuName,0,image,image,image,"SELECT,TOP,CHILD,CHECKED");
		designer.menuEntity.items.put(menuItemId, menuItemObj);
		
		

	} else {
		alert("菜单项新增失败!");
	}
}


/**
 * 创建百叶窗菜单项及其右键菜单
 * @param menuItemObj 菜单项实体
 * @param status 创建状态标记,若为"create"则先对菜单项实体数据进行保存再创建,否则不保存直接创建
 */
function _createAccordItem(menuItemObj, status, targetId, designer) {
	
	var save_result = (status!=null&&status=="create") ? menuItemObj.save() : "true";

	if(save_result =="true") {
		var menuItemId = menuItemObj.id;
		var menuItemName = menuItemObj.name;
		var appId = menuItemObj.appId;
		designer.dhxAccord.addItem(menuItemId, menuItemName, targetId);
		
		//---------------百叶窗菜单项右键START--------------
		var labelDivId = "dhxAccord_item_labelId_"+targetId+"_"+menuItemId;
		var $lableObj = jQuery("div #" + labelDivId);
		$lableObj.bind('mouseup',function(e) {
			if (!e) e = window.event;
			if (e.button == 2) {
				var labelMenu = new dhtmlXMenuObject();
				labelMenu.setSkin('dhx_ibusblue');
				labelMenu.setIconsPath(path+"/jsp/developcenter/unitdesigner/menu/imgs/dhtmlx/dhtmlxMenu/");
				labelMenu.renderAsContextMenu();
				labelMenu.addContextZone(labelDivId);
				
				labelMenu.attachEvent("onClick",function(itemId) {
					if(itemId == "increase") {
						_addMenuItem(menuItemId, menuItemId, appId, designer, targetId);
					}else if(itemId == "modify") {
						_editMenuItem(menuItemId, menuItemId, appId, designer, targetId);
					}else if(itemId == "del") { 
						_delFirstMenuItem(menuItemId, designer)
					}
				});
				
				var labelMenuXML = "<?xml version='1.0'?>" +
								   "<menu>" + 
								   	"<item id='increase' text='新增菜单项'/>" +
								   	"<item id='modify' text='修改菜单项'/>" + 
								   	"<item id='del' text='删除菜单项'/>" + 
								   "</menu>";
				labelMenu.clearAll();
				labelMenu.loadXMLString(labelMenuXML);
				cancleEventUp(e); //阻止事件上溯
				return true;
			}
		});
		//---------------百叶窗菜单项右键END-------------
		
		
		
		
		//---------------菜单空白处右键START--------------

		var contDivId = "dhxAccord_contentId_"+targetId+"_"+menuItemId;
		var $contObj = jQuery("div #" + contDivId);
		$contObj.bind('mouseup',function(e) {
			if (!e) e = window.event;
			if (e.button == 2) {
				var contMenu = new dhtmlXMenuObject();
				contMenu.setSkin('dhx_ibusblue');
				contMenu.setIconsPath(path+"/jsp/developcenter/unitdesigner/menu/imgs/dhtmlx/dhtmlxMenu/");
				contMenu.renderAsContextMenu();
				contMenu.addContextZone(contDivId);
				
				contMenu.attachEvent("onClick",function(itemId) {
					if(itemId == "setting") {
						_setMenuAttribute(targetId, designer);
					}else if(itemId == "remove") {
						if (confirm("确定要删除吗?")) {
							designer.mediator.deleteUnit(designer.menuEntity.id);
						}
					}else if(itemId == "addItem") {
						_addMenuItem(menuItemId, menuItemId, appId, designer, targetId);
					}
				});
				var contMenuXML = "<?xml version='1.0'?>" +
								  "<menu>" + 
								  	"<item id='setting' text='设置菜单单元属性'/>" +
								  	"<item id='remove' text='删除菜单单元'/>" + 
								  	"<item id='addItem' text='新增菜单项'/>" + 
								  "</menu>";
				contMenu.clearAll();
				contMenu.loadXMLString(contMenuXML);
				cancleEventUp(e);
				return true;
			}
		});
		//---------------菜单空白处右键END--------------
		
		
		designer.menuEntity.items.put(menuItemId, menuItemObj);
		var dhxTree = designer.dhxAccord.cells(menuItemId).attachTree(0);
		dhxTree.setSkin('dhx_ibusblue');
		dhxTree.setImagePath(path+"/jsp/developcenter/unitdesigner/menu/imgs/dhtmlx/dhtmlxTree/ibus_blue/");
		
		//树型菜单项的右键菜单---------START--------------
		var thisTreeItemId = ""; //当前树节点菜单项Id
		var treeMenu = new dhtmlXMenuObject();
		treeMenu.setSkin('dhx_ibusblue');
		treeMenu.setIconsPath(path+"/jsp/developcenter/unitdesigner/menu/imgs/dhtmlx/dhtmlxMenu/");
		treeMenu.renderAsContextMenu();
		treeMenu.attachEvent("onClick",function(itemId) {
			if(itemId == "increase") {
				_addMenuItem(thisTreeItemId, menuItemId, appId, designer, targetId);
			}else if(itemId == "modify") {
				_editMenuItem(thisTreeItemId, menuItemId, appId, designer, targetId);
			}else if(itemId == "del") {
				_delMenuItem(thisTreeItemId, menuItemId, designer);
			}
		});
		
		
		dhxTree.enableContextMenu(treeMenu);
		dhxTree.attachEvent("onBeforeContextMenu", function(itemId) {
			thisTreeItemId = itemId;
			dhxTree.selectItem(itemId,false,false);
			var treeMenuXml = "<?xml version='1.0'?>" +
							  "<menu>" + 
							  	"<item id='increase' text='新增菜单项'/>" +
							  	"<item id='modify' text='修改菜单项'/>" + 
							  	"<item id='del' text='删除菜单项'/>" + 
							  "</menu>";
			treeMenu.clearAll();
			treeMenu.loadXMLString(treeMenuXml);
			return true;
		});
		//树型菜单项的右键菜单---------END--------------
		
		dhxTree.enableDragAndDrop(true);

		designer.onDrapEventId = dhxTree.attachEvent("onDrag", function(sId,tId){
			
			var sName=dhxTree.getItemText(sId);
			var tName=dhxTree.getItemText(tId);
			if(tName==""){
				tName=designer.dhxAccord.cells(menuItemId).getText();
			}
			
			var r = confirm("确定要拖动  \""+sName+"\" 到  \""+tName+"\" 节点下?");
			if (r == true) {
				var pid = tId!=0 ? tId : menuItemId;
				var itemObj = designer.menuEntity.items.get(sId);
				itemObj.setParentId(pid);
				//调用BOC执行菜单项上级节点更新操作----------START------------
				var clientBoc = new ClientBOController('menuitem_boc','updateParentId');
				clientBoc.addParameter("id",itemObj.id);
				clientBoc.addParameter("parentId",itemObj.parentId);
				bocInvoker.bocName = "BOControllerAction";
				bocInvoker.bocMethod = "executeBoc";
				var save_result = bocInvoker.invokeSynchronized(clientBoc);
				//调用BOC执行菜单项上级节点更新操作----------END------------
				return true;
			}
			
		});
		designer.dhxTreeMap.put(menuItemId, dhxTree);
		
	} else {
		alert("菜单项新增失败!");
	}
}


function drapMenuFunction(sId,tId) {
	
	var r = confirm("确定要拖动该节点吗?");
	if (r == true) {
		var pid = tId!=0 ? tId : sId;
		var itemObj = this.menuEntity.items.get(sId);
		itemObj.setParentId(pid);
		//调用BOC执行菜单项上级节点更新操作----------START------------
		var clientBoc = new ClientBOController('menuitem_boc','updateParentId');
		clientBoc.addParameter("id",itemObj.id);
		clientBoc.addParameter("parentId",itemObj.parentId);
		bocInvoker.bocName = "BOControllerAction";
		bocInvoker.bocMethod = "executeBoc";
		var save_result = bocInvoker.invokeSynchronized(clientBoc);
		//调用BOC执行菜单项上级节点更新操作----------END------------
		return true;
	}
}



/**
 * 弹出新增菜单项面板
 * @param parentItemId 父节点Id
 * @param accordItemId 所属百叶窗Id
 * @param appId 所属应用Id
 */
function _addMenuItem(parentItemId, accordItemId, appId, designer, targetId) {
	
	if(designer.dhxWin.isWindow("addWin")) return;
	var w1 = designer.dhxWin.createWindow("addWin", 200, 0, 500, 500); 
	w1.setText("新增菜单项");
	w1.button("minmax1").hide();
  	w1.button("park").hide();
	w1.denyResize();
	w1.attachURL(path+"/jsp/developcenter/unitdesigner/menu/menuitem_add.jsp" +
			"?parentItemId="+ parentItemId +"&accordItemId=" + accordItemId + "&appId=" + appId+"&targetId="+targetId);
	designer.selectParent_frame = w1._frame;
}


/**
 * 弹出修改菜单项面板
 * @param menuItemId 需要修改的菜单项Id 
 * @param accordItemId 所属百叶窗Id
 * @param appId 所属应用Id
 */
function _editMenuItem(menuItemId, accordItemId, appId,designer,targetId) {
	if(designer.dhxWin.isWindow("editWin")) return;
	var w2 = designer.dhxWin.createWindow("editWin", 200, 0, 500, 500); 
	w2.setText("修改菜单项");
	w2.button("minmax1").hide();
	w2.button("park").hide();
	w2.denyResize();
	w2.attachURL(path+"/jsp/developcenter/unitdesigner/menu/menuitem_edit.jsp" +
			"?menuItemId=" + menuItemId +"&accordItemId=" + accordItemId + "&appId" + appId+"&targetId="+targetId);
	designer.selectParent_frame = w2._frame;
}


/**
 * 弹出设置菜单单元属性面板
 */
function _setMenuAttribute(targetId, designer) {
	if(designer.dhxWin.isWindow("setMenuWin")) return;
	var w1 = designer.dhxWin.createWindow("setMenuWin", 180, 0, 380, 430); 
	w1.setText("设置菜单单元属性");
	w1.button("minmax1").hide();
  	w1.button("park").hide();
	w1.denyResize();
	w1.attachURL(path+"/jsp/developcenter/unitdesigner/menu/menu_set.jsp?targetId="+targetId);
}


function _delFirstMenuItem(menuItemId, designer){
	var accordItemObj = designer.menuEntity.items.get(menuItemId);
	var r = confirm("确定要删除吗?");
	if (r == true) {

		//删除需要去后台查询,只有无子菜单项的菜单项才能够被删除
		//调用BOC执行菜单项删除操作----------START------------
		var clientBoc = new ClientBOController('menuitem_boc','delete');
		clientBoc.addParameter("id",accordItemObj.id);
		bocInvoker.bocName = "BOControllerAction";
		bocInvoker.bocMethod = "executeBoc";
		var del_result = bocInvoker.invokeSynchronized(clientBoc);
		//调用BOC执行菜单项删除操作----------END------------

		if(del_result == "true") {
			designer.dhxAccord.removeItem(menuItemId);
			designer.menuEntity.items.remove(menuItemId);
			designer.dhxAccord.forEachItem(function(item){
		        var id = item.getId();
		        designer.dhxAccord.cells(id).open();
		    });
		} else {
			alert("删除菜单项失败,不能删除带有子菜单项的菜单项!");
		}
	}
}


function _delMenuItem(thisTreeItemId, menuItemId, designer){
	
	var treeItemObj = designer.menuEntity.items.get(thisTreeItemId);
	if (confirm("确定要删除吗?")) {
		//调用BOC执行菜单项删除操作----------START------------
		var clientBoc = new ClientBOController('menuitem_boc','delete');
		clientBoc.addParameter("id",treeItemObj.id);
		bocInvoker.bocName = "BOControllerAction";
		bocInvoker.bocMethod = "executeBoc";
		var del_result = bocInvoker.invokeSynchronized(clientBoc);
		//调用BOC执行菜单项删除操作----------END------------
		if(del_result == "true") {
			designer.dhxTreeMap.get(menuItemId).deleteItem(thisTreeItemId,false);
			designer.menuEntity.items.remove(thisTreeItemId);
		} else {
			alert("删除菜单项失败,不能删除带有子菜单项的菜单项!");
		}
	}
	
}



/**
 * 初始化dhxWindow对象
 * @param targetId 目标Id
 * @return dhxWindow对象
 */
function _initDhxWindow(targetId) {
	var dhxWinow = new dhtmlXWindows();	
	dhxWinow.setSkin('dhx_ibusblue');
	dhxWinow.attachViewportTo("winVP"+targetId);
	dhxWinow.setImagePath(path+"/jsp/developcenter/unitdesigner/menu/imgs/dhtmlx/dhxWindows/");
	return dhxWinow;
}


/**
 * 菜单单元实体
 * @param unit_id 单元ID
 */
function MenuEntity(unit_id) {
	this.id = unit_id;            //菜单Id
	this.appId = "";               // 应用Id
	this.name = "";               // 菜单名称
	this.style = "";              //菜单风格
	this.version = "";            //菜单版本
	this.items = new Map();       //菜单项Map集合(menuItemId为Key,menuItemObj为value)
	
	/**
	 * 设置菜单单元是属性
	 * @param menuName 菜单名称
	 * @param menuStyle 菜单风格
	 */
	this.setAttribute = function(menuName, menuStyle) {
		this.name = menuName;
		this.style = menuStyle;
	}
	
	/**
	 * 将菜单单元实体转化为Xml字符串格式
	 * @return 菜单单元Xml字符串格式
	 */
	this.toXmlString = function() {
		var menuEntityXml = "<MenuEntity id=\"" + this.id + 
									 "\" appId=\"" + this.appId + 
									 "\" name=\"" + this.name + 
									 "\" style=\"" + this.style + 
									 "\" version=\"" + this.version + 
									 "\" >";
		menuEntityXml += "</MenuEntity>";
		return menuEntityXml;
	}
}


/**
 * 根据应用Id加载该应用下的菜单
 * @param appId 应用Id
 * @return 菜单Xml格式字符串
 */
function _loadSubsistentMenu(appId) {
	//加载已有的菜单---------START-----------
	var clientBoc = new ClientBOController('menuitem_boc','load');
	clientBoc.addParameter("appId",appId);
	bocInvoker.bocName = "BOControllerAction";
	bocInvoker.bocMethod = "executeBoc";
	var menuXml = bocInvoker.invokeSynchronized(clientBoc);
	//加载已有的菜单---------END-----------
	return menuXml;
}


/**
 * 销毁菜单单元
 * @return 
 */
function destoryMenu() {
	for(var i=0; i<this.menuEntity.items.keys.length; i++) {
		var menuItemObj = this.menuEntity.items.get(this.menuEntity.items.keys[i]);
		if(menuItemObj.parentId=="ibus_menu_root_0") {
			this.dhxAccord.removeItem(menuItemObj.id);
		}
	}
	this.designerRelationMgr=null;
	this.selectParent_frame = null;
	this.menuEntity = null;
	this.dhxWin = null;
	this.dhxAccord = null;
	this.dhxTreeMap = null;
	return true;
}


/**
 * 加载url参数
 * @param paramType 参数类型,"TOKEN"为获取权限令牌参数,"LAYOUTID"为获取模块布局Id参数
 * @param menuId 获取模块布局Id需要的菜单项Id
 * @return url参数值
 */
function _loadUrlParam(paramType, menuId) {
	var param = "";
	if(paramType == "TOKEN") {
		//调用BOC查询Token----------START------------
		var clientBoc = new ClientBOController('menuitem_boc','getAuToken');
		clientBoc.addParameter("queryToken","auNeedAToken");
		bocInvoker.bocName = "BOControllerAction";
		bocInvoker.bocMethod = "executeBoc";
		var token = bocInvoker.invokeSynchronized(clientBoc);
		//调用BOC查询Token----------END------------
		param = token;
	} else if(paramType == "LAYOUTID") {
		//调用BOC查询该菜单项关联的布局Id----------START------------
		var clientBoc = new ClientBOController('menuitem_boc','loadLayoutId');
		clientBoc.addParameter("menuId",menuId);
		bocInvoker.bocName = "BOControllerAction";
		bocInvoker.bocMethod = "executeBoc";
		var layoutId = bocInvoker.invokeSynchronized(clientBoc);
		//调用BOC查询该菜单项关联的布局Id----------END------------
		param = layoutId;
	}
	return param;
}


/**
 * 使用mediator对象链接到指定URL
 * @param mediator 父类提供的mediator对象
 * @param resourceURL 资源地址
 * @param menuId 菜单项Id
 * @param currentMode 当前使用模式,"USER_MODE"为用户模式,"NORMAL_MODE"为预览模式
 * @param menuItemType 菜单项类型(1:平台,2:系统,3:子系统,4:模块)
 */
function _linkURL(mediator, resourceURL, menuId, currentMode, menuItemType) {
	if(currentMode == "USER_MODE") { 
		if(resourceURL!=null && resourceURL!="") {
			var token = _loadUrlParam("TOKEN"); //获取权限需要的token
			mediator.attachURLToApps(resourceURL + "?token="+token);
		} else {
			if(menuItemType == "4") { //只有当菜单项类型为"模块"时,菜单项才能进行装配
				var layoutId = _loadUrlParam("LAYOUTID", menuId); //获取当前菜单项关联的模块布局的Id
				mediator.attachURLToApps(path+"/function_skip.jsp?layoutId="+layoutId+"&menuId="+menuId);
			}
		}
	} else { //当前使用模式不是用户模式(即为预览模式)时,若资源地址为空或者页面没装配(模块布局Id为空)则不弹出装配页面
		if(resourceURL!=null && resourceURL!="") {
			var token = _loadUrlParam("TOKEN");
			mediator.attachURLToApps(resourceURL + "?token="+token);
		} else {
			var layoutId = _loadUrlParam("LAYOUTID", menuId);
			if(layoutId!="null") {
				mediator.attachURLToApps(path+"/function_skip.jsp?layoutId="+layoutId+"&menuId="+menuId);
			}
		}
	}
}

 
 类似资料:

相关阅读

相关文章

相关问答