<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setDateHeader("Expires", -10);
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@include file="/WEB-INF/views/base.jsp"%>
<!DOCTYPE html>
<html>

<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>角色管理</title>

<link href="${cssPath }/bootstrap.min.css" rel="stylesheet">
<link href="${fontAwsPath }/css/font-awesome.css" rel="stylesheet">

<!-- Data Tables -->
<link href="${cssPath }/plugins/dataTables/dataTables.bootstrap.css"
	rel="stylesheet">
<link href="${cssPath }/plugins/dataTables/dataTables.responsive.css"
	rel="stylesheet">
<link
	href="${cssPath }/plugins/dataTables/dataTables.tableTools.min.css"
	rel="stylesheet">
<link
	href="${cssPath }/plugins/sweetalert/sweetalert.css"
	rel="stylesheet">
	

<link href="${cssPath }/animate.css" rel="stylesheet">
<link href="${cssPath }/style.css" rel="stylesheet">

</head>

<body>
<input type="hidden" id="basePath" value="<%=basePath %>"  >
	<div id="wrapper">

		<jsp:include page="../menu.jsp"></jsp:include>

		<div id="page-wrapper" class="gray-bg">
			<jsp:include page="../head.jsp"></jsp:include>
			<jsp:include page="../pageNav.jsp"></jsp:include>
			
			<div class="wrapper wrapper-content animated fadeInRight">
				<div class="row">
					<div class="ibox-content m-b-sm border-bottom">
						<div class="row">
							<div class="col-sm-6">
								<div class="form-group">
									<label class="control-label" for="product_name">角色名称</label>
									<input type="text" id="roleName" name="roleName" value="" placeholder="角色名称" class="form-control">
									<input type="hidden" id="pageNo" name="pageNo" value="1">
								</div>
							</div>
							<div class="col-sm-6">
								<div class="form-group">
									<label class="control-label" for="status">查询</label>
									<button onclick="query();" class="btn btn-w-m btn-success form-control"><i class="fa fa-search"></i>&nbsp;&nbsp;查询
									</button>
								</div>
							</div>
						</div>
					</div>
					<div class="ibox float-e-margins">
						<div class="ibox-title">
							<a href="addRole" class="btn btn-w-m btn-primary"><i class="fa fa-plus-square"></i>&nbsp;&nbsp;新增</a>
						</div>
						<div class="ibox-content" id="RoleListPartial">
										

								
						</div>
					</div>
					
		
			</div>
	</div>
	</div>
	</div>


 <!-- Mainly scripts -->
    <%@include file="/WEB-INF/views/common_base_script.jsp"%>
	
	<script type="text/javascript">
			var basePath = "<%=basePath %>";
			function initData(){
            	var roleName = $("#roleName").val();
	            var pageNo = $("#pageNo").val();
				//第一次加载数据
				$.ajax({
					type : 'POST',
					async : false,
					url : basePath + 'sysRole/initDataList',
					data : {'pageNo' : pageNo, 'roleName':roleName },
					dataType : 'html',
					success : function(data){
						$("#RoleListPartial").html(data);
					}
				})
            }
	
	$(function(){
		var bathPath = $("#basePath").val();
		initData();
		$("#RoleListPartial").delegate('.op_enable', 'click', function(){
			var RoleID = $(this).attr("RoleID");
			var $this = $(this);
			$.ajax({
				type : 'POST',
				async : false,
				url : bathPath + 'sysRole/updateRoleStatus.json',
				data : {'RoleID' : RoleID },
				dataType : 'json',
				success : function(data){
					if(data.success){
						//操作成功, 当前用户已经 冻结
						if(data.roleStatus) {
							$this.html("解冻");
							$(".role_satus_"+RoleID).find("i").attr("class", "fa fa-minus text-danger");
						} else {
							$this.html("冻结");
							$(".role_satus_"+RoleID).find("i").attr("class", "fa fa-check text-navy");
						}
					} else {
						//提醒用户操作失败
						toastr['error']('操作失败');
					}
				}, 
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					//提醒用户操作失败
					toastr['error']('操作失败');
				}
			})
		});
	});
	
		

    //删除角色
    function DeleteRole(RoleID,RoleName) {
        swal({
            title: "删除角色【" + RoleName + "】？",
            text: "确认删除？",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: false
        }, function () {
            $.post("deleteRole", { RoleID: RoleID }, function (data) {
            	debugger;
                if (data == 0) {
                    swal("删除失败!", "角色删除失败，请重试！", "error");
                } else {
                    swal("删除成功!", "角色删除完成！", "success");
                  //  $("#RoleListPartial").html(data);
                    window.location.reload();
                }
            })
        });

    }
	
	
	function query(){
        $("#pageNo").val("1");
        initData();
     }
	
	</script>
</body>

</html>
