<%@ page contentType="text/html; charset=GBK"%>
<%@ page import = "zr.zrpower.common.util.SysPreperty"%>
<%@ page import = "zr.zrpower.entity.sys.SessionUser"%>
<%@ page import = "zr.zrpower.entity.sys.BPIP_ROLE"%>
<%@ page import = "zr.zrpower.entity.sys.BPIP_USER"%>
<%@ page import = "zr.zrpower.entity.sys.BPIP_MENU"%>
<%@ page import = "zr.zrpower.ejb.sys.UIService" %>
<%@ page import = "zr.zrpower.ejb.sys.UserService"%>
<%@ page import = "zr.zrpower.ejb.sys.SecurityService"%>

<HTML>
<%
SessionUser user = (SessionUser)session.getAttribute("userinfo");
UIService userUI =new UIService();
UserService UserSer = new UserService();
String usertype = "1";
BPIP_ROLE[] role = null;
BPIP_USER[] userList = null;
BPIP_MENU[] rolemenu = null;
BPIP_MENU[] allmenu = null;
SecurityService SeService =new SecurityService();
String strRole_ID = request.getParameter("SelectedItems");
String roleMenuNoStr="";


//得到查询记录集
   allmenu = SeService.GetMenuAllList();
   rolemenu =SeService.GetRoleMenuList(strRole_ID);

   if (rolemenu!=null && rolemenu.length>0){
      for(int i=0;i<rolemenu.length;i++){
          roleMenuNoStr+=","+rolemenu[i].getMENUNO();
      }
    }

    String strshow_data = "";

     if (allmenu!=null && allmenu.length>0){
       strshow_data = strshow_data + "[";
       String name = "";
       String name1 = "";
       String name2 = "";

       for(int i=0;i<allmenu.length;i++){

         strshow_data = strshow_data + "[";


         strshow_data = strshow_data + "'<input type=checkbox name=select_check value="+allmenu[i].getMENUNO()+">',";
         strshow_data = strshow_data + "'"+allmenu[i].getMENUNO()+"',";

         name = SeService.Get_Menu_ParentName(allmenu[i].getMENUNO(),1);
         name1 = SeService.Get_Menu_ParentName(allmenu[i].getMENUNO(),2);
         name2 = "【"+name+"】"+"【"+name1+"】"+allmenu[i].getMENUNAME();

         if (i < allmenu.length-1 )
         {
            strshow_data = strshow_data + "'"+name2+"'],\r\n";
         }else
         {
            strshow_data = strshow_data + "'"+name2+"']";
         }

       }
       strshow_data = strshow_data + "]";
    }else
    {
       strshow_data = "null";
    }

%>
<HTML>
<HEAD>
<TITLE></TITLE>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META http-equiv="Content-Type" content="text/html; charset=GBK">
<link REL="stylesheet" type="text/css" href="../../zrsysmanage/css/<%=user.getUserCSS()%>">
<SCRIPT LANGUAGE="JavaScript" src="../../zrsysmanage/script/Public.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" src="../../zrsysmanage/script/DealList.js"></SCRIPT>

<link rel="stylesheet" type="text/css" media="all" href="../../ZrwebGui/sigma_grid/grid/calendar/calendar-blue.css">
<script type="text/javascript" src="../../ZrwebGui/sigma_grid/grid/calendar/calendar.js"></script>
<script type="text/javascript" src="../../ZrwebGui/sigma_grid/grid/calendar/calendar-setup.js"></script>
<link rel="stylesheet" type="text/css" href="../../ZrwebGui/sigma_grid/grid/gt_grid.css">
<link rel="stylesheet" type="text/css" href="../../ZrwebGui/sigma_grid/grid/skin/vista/skinstyle.css">
<link rel="stylesheet" type="text/css" href="../../ZrwebGui/sigma_grid/grid/skin/pink/skinstyle.css">
<link rel="stylesheet" type="text/css" href="../../ZrwebGui/sigma_grid/grid/skin/mac/skinstyle.css">
<script type="text/javascript" src="../../ZrwebGui/sigma_grid/grid/gt_msg_en.js"></script>
<script type="text/javascript" src="../../ZrwebGui/sigma_grid/grid/gt_const.js"></script>
<script type="text/javascript" src="../../ZrwebGui/sigma_grid/grid/gt_grid_all.js"></script>
<%if("6".equals(user.getUserWINDOWTYPE())){ %>
<LINK type="text/css" rel="stylesheet" href="../../zrsysmanage/html5/css/style_tables.css">
<SCRIPT LANGUAGE="JavaScript" src="../../zrsysmanage/html5/script/jquery-2.0.3.min.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" src="../../zrsysmanage/html5/layer/layer.js"></SCRIPT>
<%}%>

<script type="text/javascript" >
var css = "<%=user.getUserCSS()%>";
var skincss = "vista";

if (css=="Blue.css")
{skincss = "vista";}
if (css=="Public.css")
{skincss = "default";}
if (css=="Window.css" || css=="nBlue.css")
{skincss = "mac";}
if (css=="Yellow.css")
{skincss = "pink";}


var grid_demo_id = "myGrid1" ;
var show_data= <%=strshow_data%>;

var dsOption= {

	fields :[
                {name : 'SID'  },
		{name : 'MENUNO'  },
		{name : 'MENUNAME'  }
	],

	recordType : 'array',
	data : show_data
}


var colsOption = [
           {id: 'SID' , header: "<center>选择</center>" , width :50 , align : 'center'  },
           {id: 'MENUNO' , header: "<center>菜单编号</center>" , width :100 , align : 'center'  },
           {id: 'MENUNAME' , header: "<center>菜单名称</center>" , width :600,  align : 'left'  }
];

Sigma.ToolFactroy.register(
	'mybutton',
	{
		cls : 'mybutton-cls',
		toolTip : '全选',
		action : function(event,grid) {selectall(); }
	}
);

var gridOption={
	id : grid_demo_id,
	width: "800",
	height: "70%",
	container : 'gridbox',
	replaceContainer : true,
	dataset : dsOption ,
	columns : colsOption,
	pageSize : 2000,
	toolbarContent : 'mybutton',
        skin : skincss,

       showIndexColumn : true
};

<%if(!"6".equals(user.getUserWINDOWTYPE())){ %>
var mygrid=new Sigma.Grid( gridOption );
Sigma.Util.onLoad( Sigma.Grid.render(mygrid));
<%}%>


</script>

<style type="text/css">
 .mybutton-cls {
		background : url(../../ZrwebGui/sigma_grid/grid/skin/select.gif) no-repeat center center;
}
</style>


</HEAD>
<BODY class="BodyMain">
<%
//得到角色的记录集
String strWhere = " where ROLEID="+strRole_ID;
role = SeService.GetRoleList(strWhere);
//
if (role!=null)
{
  %>
  <FORM name="RegForm" method="post" action="../../actionrole.do">
    <input type="hidden" name="Menu_No" value="">
    <input type="hidden" name="Act" value="">
<%if("6".equals(user.getUserWINDOWTYPE())){ %>
   <br/>
<%} %>


     <table border='0' width="800"  cellspacing="0" cellpadding="0">
      <tr>
          <td class="PutdSet">角色编号：</td>
          <td><input class="text" type="text" name="ROLEID" size="15" maxlength="3" onkeypress="if(event.keyCode<48 || event.keyCode>57) event.returnValue=false;" value="<%=role[0].getROLEID()%>" readonly="readonly"><Font class="WriteSign">*</Font></td>
          <td class="PutdSet">角色名称：</td>
          <td><input class="text" type="text" name="ROLENAME" size="50" maxlength="15" value="<%=role[0].getROLENAME()%>"><Font class="WriteSign">*</Font></td>
      </tr>
      <tr>
          <td class="PutdSet">

          </td>
          <td>

          </td>
          <td class="PutdSet">角色描述：</td>
          <td><input class="text" type="text" name="DESCRIPTION" size="50" maxlength="50" value="<%=role[0].getDESCRIPTION()%>"></td>
      </tr>

         </table>
<%



  %>
  角色分配的菜单:
  <br>


<%if("6".equals(user.getUserWINDOWTYPE())){ %>
  <div id="mianRole" style="height: 300px;overflow: auto;">
  <table class="bordered" id="html5_table">

<thead>
<tr>
<th style="width:5%;">序号</th>
<th style="width:5%;">选择</th>
<th style="width:30%;">菜单编号</th>
<th style="width:50%;">菜单名称</th>

</tr>
</thead>

<%
if (allmenu!=null && allmenu.length>0){
  for(int i=0;i<allmenu.length;i++){
      String name = SeService.Get_Menu_ParentName(allmenu[i].getMENUNO(),1);
      String name1= SeService.Get_Menu_ParentName(allmenu[i].getMENUNO(),2);
      String name2= "【"+name+"】"+"【"+name1+"】"+allmenu[i].getMENUNAME();
     %>
     <tr onclick="click_color(this,'<%=allmenu[i].getMENUNO() %>');">
        <td style="text-align:center;"><%=i+1 %></td>
        <td style="text-align:center;"><input type=checkbox name=select_check value="<%=allmenu[i].getMENUNO() %>"></td>
        <td style="text-align:center;"><%=allmenu[i].getMENUNO() %></td>
        <td style="text-align:left;"><%=name2 %></td>



     </tr>

     <%
  }
}

 %>
</table>
</div>
  <%}else{ %>
 <div id="gridbox" style="border:0px solid #cccccc;background-color:#f3f3f3;padding:5px;height:600px;width:800px;" ></div>
  <% }%>



   <br>
             <center>
             <table cellspacing="0" cellpadding="0" border='0'><tr>
                 <%if("6".equals(user.getUserWINDOWTYPE())){ %>
                   <%=userUI.ClickButton("全选","JavaScript:selectall();","buttonReturn.gif",user.getUserImage())%>
                <%}%>
                 <%=userUI.ClickButton("保存","JavaScript:if(Check(document.RegForm)){document.RegForm.submit();}","buttonSave.gif",user.getUserImage())%>
                 <%=userUI.ClickButton("删除","JavaScript:if(Check1(document.RegForm)){document.RegForm.submit();}","buttonDelete.gif",user.getUserImage())%>
                 <%=userUI.ClickButton("返回","JavaScript:history.back();","buttonReturn.gif",user.getUserImage())%>
              </tr></table>
              </center>



</FORM>
<%
  }
%>
</BODY>
<script language="javascript">
<%if("6".equals(user.getUserWINDOWTYPE())){ %>
 var h=$(document.body).height();//浏览器当前窗口文档body的高度
 h=h*1-200;
 $('div').css('height',h);
  var allvalue="";
function clickValue(value){
    allvalue=value;
}
<%}%>
function MenuChecked()
{
  var roleMenuNoStr="<%=roleMenuNoStr%>";

   var chkList=document.getElementsByName("select_check");

   for(i=0;i<chkList.length;i++)
   {
     if(roleMenuNoStr.indexOf(chkList[i].value)>-1)
     {
       chkList[i].checked=true;
     }else
     {
       chkList[i].checked=false;
     }
    }
}
function selectall(vaule){
  var chkList=document.getElementsByName("select_check");
  var setcheck;

  if (chkList.length>0)
  {
    if (chkList[0].checked){
       setcheck = false;
    }else{
       setcheck = true;
    }
  }

  for(i=0;i<chkList.length;i++)
  {

    chkList[i].checked=setcheck;
  }

}

window.onload  = function()
{
  var obj = window.dialogArguments;
}

setTimeout("MenuChecked();",500);
</script>
<SCRIPT language="javascript">
function Check(theForm){
  if ((trim(theForm.ROLEID.value)=="")){
    <%if("6".equals(user.getUserWINDOWTYPE())){ %>
        layer.alert('角色编号不能为空!', {icon: 7});
    <%}else{%>
        alert("角色编号不能为空!");
    <%}%>
    theForm.ROLEID.focus();
    return false;
  }
  if((trim(theForm.ROLEID.value)!="")){
    var Letters ="0123456789";
    for(i=0;i<(theForm.ROLEID.value.length);i++){
          var CheckChar = theForm.ROLEID.value.charAt(i);
          if (Letters.indexOf(CheckChar)== -1){

              <%if("6".equals(user.getUserWINDOWTYPE())){ %>
              layer.alert('角色编号只能输入数字!', {icon: 7});
             <%}else{%>
              alert("角色编号只能输入数字！");
             <%}%>
              theForm.ROLEID.focus();
              return false;
            }
        }
    }
  if ((trim(theForm.ROLENAME.value)=="")){
    <%if("6".equals(user.getUserWINDOWTYPE())){ %>
    layer.alert('角色名称不能为空!', {icon: 7});
    <%}else{%>
    alert("角色名称不能为空!");
    <%}%>

    theForm.ROLENAME.focus();
    return false;
  }

  var str=document.getElementsByName("select_check");
    var objarray=str.length;
    var chestr="";
    for (i=0;i<objarray;i++)
    {
      if(str[i].checked == true)
      {
        if (chestr=="")
        {
          chestr = str[i].value;
        }else
        {chestr = chestr + "," + str[i].value;}
      }
    }

  theForm.Menu_No.value = chestr;
  theForm.Act.value='edit';
  return true;
}
function Check1(theForm){
  if (confirm("将删除所有关联信息,确定要删除吗？"))
  { theForm.Act.value='delete';
    return true;}
  else
  {return false;}
}

</SCRIPT>
</HTML>
<%
//清空相关对象
user = null;
userUI = null;
UserSer = null;
role = null;
userList = null;
rolemenu = null;
allmenu = null;
SeService = null;
%>
