<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.util.*" %>
<%@ page import="com.gx.webpage.engine.menupage.designdbengine.factory.*" %>
<%@ page import="com.gx.webpage.engine.menupage.designdbengine.valueobject.*" %>
<%@ page import="com.gx.webpage.framework.valueobject.*" %>
<%@ page import="com.gx.webpage.engine.menupage.designdbengine.api.*" %>
<%@ page import="com.gx.webpage.framework.util.inoutformat.DataBean" %>
<%
    boolean isSave = false;
    boolean isError = false;
    String errStr = "";
    String parentUuid = "";
    String parentMenuName = "";
    SysMenuModel menuModel = null;
		String icon = "";
    String name = "";
    String desc = "";
    String uuid = "";
		int indexNum = 0;
		int menuLevel = 0;
		int systemId = 0;
		String targetPage = "";
		String parentUuidPath = "";
    try
    {
        UserInfoCtxModel uicm = new UserInfoCtxModel();
        uicm.setUserId("cc");
        EbiMenuMgr delegate = MenuFactory.getInstance().getEbiMenuMgr();
        uuid = DataBean.getStr(request, "uuid");
        menuModel = delegate.findSysMenu(uuid,false, uicm);
				parentUuidPath = menuModel.getParentCatPath();
				if(parentUuidPath==null || parentUuidPath.trim().length()==0){
					parentUuidPath = "com.cc.menu."+uuid;
				}else{
					parentUuidPath = "com.cc.menu"+"."+parentUuidPath+"."+uuid;
				}
        parentUuid = DataBean.getStr(request, "parentUuid");
        if(parentUuid.length() == 0)
        {
            parentUuid = DataBean.getStr(menuModel.getParentUuid());
        }
        if(request.getMethod().equalsIgnoreCase("POST"))
        {
            isSave = true;
            icon = DataBean.getStr(request, "icon");
            name = DataBean.getStr(request, "name");
            desc = DataBean.getStr(request, "desc");
						indexNum = DataBean.getInt(request, "indexNum");
						targetPage = DataBean.getStr(request, "targetPage");
						menuLevel = SysMenuModel.getMenuLevel(DataBean.getStr(request, "menuLevel"));
						systemId = SysMenuModel.getSysId(DataBean.getStr(request, "systemId"));
            menuModel.setDescription(desc);
            menuModel.setSystemId(systemId);
            menuModel.setName(name);
            menuModel.setParentUuid(parentUuid);
						menuModel.setIcon(icon);
						menuModel.setIndexNum(indexNum);
						menuModel.setMenuLevel(menuLevel);
						menuModel.setTargetPage(targetPage);
						menuModel.setParentTarget("parent.cfpMain");
						uicm.setNeedAcl(false);
						uicm.setAclType(uicm.ACLTYPE_ROW);
						uicm.setRowCatPath("com.cc.menu");
						Collection colPerIds = new ArrayList();
						colPerIds.add("modify");
						uicm.setRowColPerId(colPerIds);
						uicm.setNeedUpdateAcl(false);
            if(delegate.updateSysMenu(menuModel,uicm) == false)
            {
                isError = true;
            }
        }
        else
        {
            if(parentUuid.length() > 0)
            {
                SysMenuModel menuModelParent = delegate.findSysMenu(parentUuid,false,uicm);
                if((menuModelParent != null))
                {
                    parentMenuName = DataBean.getStr(menuModelParent.getName());
                }
            }
        }
    }
    catch(Exception ex)
    {
      errStr = DataBean.getErrStr(ex);
      isError = true;
    }
%>
<html>
    <head>
    <meta http-equiv="Content-Language" content="zh-cn">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="./../../webpage/common/css/common.css" rel="StyleSheet"  type="text/css" />
<script language="javascript" src="./../../webpage/common/engine/constant.js"></script>
<script language="JScript.Encode" src="./../../webpage/common/engine/common.js"></script>
<script language="javascript">
<!--
    function formSubmit()
    {
        var ret = UTIL.checkNull("name", "请填写菜单(公司)的名称.");
        if(ret == false) return;
        window.addForm.submit();
    }
	function updateAcl(){
        var acl = new CfpDefaultPowerDefModel();
        acl.setCatPath("<%=parentUuidPath%>");
        acl.setPowerType(acl.POWER_TYPE_ROW);
        acl.setName("菜单权限");
        acl.setAddWithForm(false);
        var ret = CHILDWIN.showPowerDialog(acl);
	}
//-->
</script>
    </head>
    <body class="main">
    <p class="title">修改菜单
<%
    if(isSave)
    {
        if(isError)
        {
%>
            <p class="error">修改失败.(<%= errStr %>)
            <p class="error"><input class="butACTION" type='button' name='butOK' value='确　　定' onclick='CFPFORM.cancel();'>
<%
        }
        else
        {
%>
            <p class="information">修改成功．
            <p class="information"><input class="butACTION" type='button' name='butOK' value='确　　定' onclick="window.navigate('menuInfo.jsp?uuid=<%= menuModel.getUuid() %>')">
           <script language="javascript">
           <!--
              try{
                  parent.window.leftFrame.window.location.reload();
              }catch(e){}
           //-->
           </script>
<%
        }
    }
    else
    {
        if(isError)
        {
%>
            <p class="error">错误，请联系管理员．(<%= errStr%>)
<%
        }
        else
        {
%>
<form name="addForm" method="POST" >
  <div align="center">
    <table class="content">
			<tr>
        <td width = "30%">所属系统</td>
        <td width = "70%"><input class="txtInput" type="text" name="systemIdStr" size="50" disabled="false" value="<%=menuModel.getViewSysId()%>"></td>
						<input type="hidden" name="systemId" size="50" value="<%=menuModel.getViewSysId()%>">
      </tr>
			<tr>
        <td width = "30%">菜单层次</td>
        <td width = "70%"><input class="txtInput" type="text" name="menuLevelStr" size="50" disabled="false" value="<%= menuModel.getViewMenuLevel()%>"></td>
						<input type="hidden" name="menuLevel" size="50" value="<%= menuModel.getViewMenuLevel()%>">
      </tr>
			<tr>
        <td width = "30%">上级菜单名称<input type = "hidden" name = "parentUuid" value="<%= parentUuid%>"></td>
        <td width = "70%"><input class="txtInput" type="text" name="txtMenuName" size="50" disabled="false" value="<%=parentMenuName%>">
				</td>
      </tr>
      <tr>
        <td width = "30%">本级菜单名称</td>
        <td width = "70%"><input class="txtInput" type="text" name="name" size="50" value="<%= DataBean.getStr(menuModel.getName())%>"></td>
      </tr>
			<tr>
        <td width = "30%">菜单序列号</td>
        <td width = "70%"><input class="txtInput" type="text" name="indexNum" size="50" value="<%= menuModel.getIndexNum()%>"></td>
      </tr>
			<tr>
        <td width = "30%">图标位置</td>
        <td width = "70%"><input class="txtInput" type="text" name="icon" size="50" value="<%= DataBean.getStr(menuModel.getIcon())%>"></td>
      </tr>
			<tr>
        <td width = "30%">操作页面</td>
        <td width = "70%"><input class="txtInput" type="text" name="targetPage" size="50" value="<%= DataBean.getStr(menuModel.getTargetPage())%>"></td>
      </tr>
      <tr>
        <td width = "30%">描述</td>
        <td width = "70%"><textarea rows="5" name="desc" cols="50"><%= DataBean.getStr(menuModel.getDescription())%></textarea></td>
      </tr>
    </table>
    <table class="buttable1">
      <tr>
        <td align = "center" width = "33%"><input class="butACTION" type="button" value="修　　改" name="butSubmit" onclick="formSubmit();"></td>
        <td align = "center" width = "33%"><input class="butACTION" type="button" value="修改权限" name="butSubmit" onclick="updateAcl();"></td>
        <td align = "center" width = "33%"><input class="butACTION" type="reset"  value="全部重写" name="butReset"></td>
      </tr>
    </table>
  </div>
</form>
<%}}%>
    </body>
</html>
