123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- <%@ page contentType="text/html; charset=utf-8" session="false" %>
- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
- <head>
- <title>我的工作台</title>
- <%@ include file="../common/header.jsp" %>
- <script type="text/javascript">
- var mydata,operType,loadCount = 0;
- $(document).ready( function() {
- loadList(); //加载jqgrid
- $("#list").jqGrid("setGridHeight",$(window).height() - 105);
- $("#list").jqGrid("setGridWidth",document.body.clientWidth - 5);
- });
-
- $(window).resize(function(){
- $("#list").jqGrid("setGridHeight",$(window).height() - 105);
- $("#list").jqGrid("setGridWidth",document.body.clientWidth - 5);
- });
-
- //jqgrid初始化
- function loadList(){
- jQuery("#list").jqGrid({
- datatype: "local", //从服务器端返回的数据类型,(表格期望接收的数据类型)。可选类型:xml,xmlstring,json,local,function
- height: "70%", //高度
- colNames:["主键","角色名称", "创建时间", "创建人", "是否启用"], //列名
- colModel:[
- {
- name: "ADMIN_ROLE_ID",
- index: "ADMIN_ROLE_ID",
- align: "center",
- sorttype: "string",
- editable: true,
- hidden: true
- //editoptions:{readonly:true} 如果要显示该列可以设置只读
- },
- {
- name: "ADMIN_ROLE_NAME",
- index: "ADMIN_ROLE_NAME",
- align: "center",
- sorttype: "string",
- editable: true,
- editrules:{
- required: true,
- custom: true,
- custom_func: checkName
- }
- },
- {
- name: "CREATE_DATETIME",
- index: "CREATE_DATETIME",
- align: "center",
- sorttype: "string"
- },
- {
- name: "CREATE_BY",
- index: "CREATE_BY",
- align: "center",
- sorttype: "string"
- },
- {
- name: "IS_VALID", //对应数据库字段
- index: "IS_VALID", //按照哪个字段进行排序
- align: "center", //显示位置
- sorttype: "string", //字段类型
- editable: true, //是否可以编辑
- editrules: {required:true}, //验证规则
- formatter: "checkbox",
- formatoptions: {disabled:true},
- edittype: "checkbox", //可以编辑的类型。可选值:text, textarea, select, checkbox, password, button, image and file.
- editoptions: {value:"Yes:No"} //默认值 和下拉框的默认值不同
- }
- ],
- caption: "角色管理", //标题
- editurl: "${contextPath }/admin/adminuser/roleupdate.html", //编辑行后发送请求到服务器的url
- delurl: "${contextPath }/admin/adminuser/roleupdate.html", //删除行后发送请求到服务器的url
-
- pager: "#page", //#page分页控件绑定的位置对象
- rowNum: 100, //每页显示条数
- rowList: [100,200,300,400], //分页下拉选项内容
- rownumbers: true, //是否显示行数
- viewrecords: true, //是否显示总条数
- emptyrecords: "无数据", //服务器返回空列表时显示的内容
- autowidth: true, //自动调节宽度
- sortname: "SORT", //按SORT进行排序 默认asc
- altRows: true, //设置表格是否允许行交替变色值
- altclass: "tdbgmouseover" //自定义隔行变色的样式
- });
-
- //获取数据集
- mydata = getLists();
-
- if(mydata!=null){
- for(var i=0;i<=mydata.length;i++){
- jQuery("#list").jqGrid('addRowData',i+1,mydata[i]);
- }
- jQuery("#list").jqGrid().trigger("reloadGrid"); //添加完数据后客户端自动刷新一次、实现客户端数据与服务器数据的完全分离
- }
- //绑定、设置工具栏
- jQuery("#list").jqGrid("navGrid","#page",{
- add: true, addtext: "添加",
- edit: true, edittext: "编辑",
- del: true, deltext: "删除",refresh: false,search: false,
- addfunc: addRow, //自定义添加方法
- editfunc: editRow, //自定义编辑方法
- delfunc: deleteRow, //自定义删除方法
- searchtext: "搜索",
- refreshtext: "刷新",
- alerttext:"请选择一条记录!"
- });
-
- if(loadCount == 0){
- $("#list").navButtonAdd("#page",{
- caption:"页面权限",
- buttonicon:"ui-icon-document",
- position: "last",
- title:"页面权限",
- cursor: "pointer", //光标类型
- onClickButton: viewRow
- });
-
- $("#list").navButtonAdd("#page",{
- caption:"栏舍权限",
- buttonicon:"ui-icon-document",
- position: "last",
- title:"栏舍权限",
- cursor: "pointer", //光标类型
- onClickButton: feedpRow
- });
- }
-
- }
-
- //获取服务器数据
- function getLists(){
- $.ajax({
- async: false,
- type: 'POST',
- dataType:'json', //返回类型json
- url: "${contextPath }/admin/adminuser/rolelist.html",
- error: function(){alert("系统错误");},
- success: function(json){
- mydata = json;
- }
- });
- return mydata;
- }
-
- //自定义添加方法
- function addRow(){
- loadCount = 1;
- operType = "add"; //自定义验证时使用的参数
- $("#list").jqGrid("editGridRow","new",{
- closeAfterAdd: false, //编辑弹出层不关闭
- //reloadAfterSubmit: true, //如果不重载数据想看到新增后的数据改变样子就需要添加这个属性
- afterSubmit: function(response, postdata){
- var result = eval('(' + response.responseText + ')');
- var errors = "";
- if(result.status == "success"){
- $("#list").clearGridData(); //清空原grid数据
- loadList(); //重新载入服务器数据
-
- }
- //需要返回条新记录给jqgrid知道
- var newId = null;
- return [result.success, errors, newId];
- }
- });
- }
-
- //自定义编辑方法
- function editRow(){
- operType = "modif"; //自定义验证时使用的参数
- var row = $("#list").jqGrid("getGridParam","selrow");
- $("#list").jqGrid("editGridRow",row,{closeAfterEdit: false,reloadAfterSubmit: false});
- }
-
- //自定义删除方法
- function deleteRow(){
- var row = $("#list").jqGrid("getGridParam","selrow");
- $("#list").jqGrid("delGridRow", row,{
- serializeDelData: function (postdata) {
- var rowData = $("#list").jqGrid("getRowData",postdata.id); //获取当前选中行真实对象
- //自定义配置提交到服务器时候的数据
- return{
- ADMIN_ROLE_ID: rowData.ADMIN_ROLE_ID,
- oper: postdata.oper,
- ADMIN_ROLE_NAME: rowData.ADMIN_ROLE_NAME,
- IS_VALID: rowData.IS_VALID
- };
- }
- });
- }
-
- //页面权限
- function viewRow(){
- var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
- if(selId!=null){
- var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
- document.location.href="${contextPath}/admin/adminuser/privilege.html?adminRoleId="+rowData.ADMIN_ROLE_ID+"&type=1";
- }else{
- alert("请选择角色");
- }
- }
-
- //栏舍权限
- function feedpRow(){
- var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
- if(selId!=null){
- var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
- document.location.href="${contextPath}/admin/adminuser/feedprow.html?adminRoleId="+rowData.ADMIN_ROLE_ID+"&type=1";
- }else{
- alert("请选择角色");
- }
- }
-
- //自定义验证名称是否存在方法
- function checkName(value, colname){
- var flag = 0;
- var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
- var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
- $.ajax({
- async: false,
- type: 'POST',
- data: "entityName="+value+"&type="+operType+"&entityId="+rowData.ADMIN_ROLE_ID,
- dataType: 'json',
- url: "${contextPath}/admin/adminuser/rolecheck.html",
- error: function(){alert("系统错误");},
- success: function(json){
- flag = json.status;
- }
- });
- if(flag == 0){
- return [true,""];
- }else{
- return [false,"角色名称已经存在!"];
- }
- }
- </script>
- </head>
- <body style="background-color: #E0E0E0">
- <div>
- <div class="navfrm">
- <span>当前位置:</span>
- <span><a href="${contextPath }/admin/welcome.html">首页</a></span>
- <span> >> </span>
- <span>角色管理</span>
- </div>
- <table id="list"></table>
- <div id="page"></div>
- <div id="msgbox" title="" style="display:none"></div>
- </div>
- </body>
- </html>
|