<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8" />
<title>工作流</title>
</head>
<body>
	<div>
		<button class="log" onclick="logout()">退出</button>
	</div>
	<table th:if="${forms.size()}>0">
		<thead>
			<tr>
				<td>请假标题</td>
				<td>请假内容</td>
				<td>请假人</td>
				<td>状态</td>
				<td>操作</td>
			</tr>
		</thead>
		<tr th:each="form:${forms}">
			<td th:text="${form.title}"></td>
			<td th:text="${form.content}"></td>
			<td th:text="${form.applicant}"></td>
			<td th:text="${form.state}"></td>
			<td>
				<button th:onclick="'javascript:approve(\''+${form.id}+'\')'">审批通过</button>
				<button th:onclick="'javascript:giveup(\''+${form.id}+'\')'">审批不通过</button>
			</td>
		</tr>
	</table>
	<div th:if="${forms.size()}==0">
		<br />暂无请假数据
	</div>
</body>
</html>

<style>
* {
	font-family: "微软雅黑";
	font-size: 15px;
}

td {
	padding: 5px 10px;
	border: 1px solid #ccc;
}

button {
	padding: 5px;
	margin: 5px 0;
	border: 1px solid #aaa;
	border-radius: 4px;
}
.log{
	float:right;
	padding:5px 8px;
	background:#ec5757;
	color:#fff;
}
</style>

<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<script>
	function writeForm(){
		location.href = "/form";
	}
	
	function logout(){
		$.ajax({
			url : "/logout",
			success : function(data) {
				if(data.code == 200){
					location.href="/";
				}
			}
		});
	}
	
	function approve(formId){
		var operator = getUser();
		debugger;
		if(operator == ""){
			location.href = "/";
		}
		$.ajax({
			url : "/approve",
			data : {
				"formId" : formId,
				"operator" : operator
			},
			success : function(data) {
				if(data.code == 200){
					location.href="/homeApprover";
				}
			}
		});
	}

    function giveup(formId) {
        var operator = getUser();
        if (operator == "") {
            location.href = "/";
        }
        $.ajax({
            url : "/giveups",
            data : {
                "formId" : formId,
                "operator" : operator
            },
            success : function(data) {
                if (data.code == 200) {
                    location.href = "/homeApprover";
                }
            }
        });
    }

	//获取cookie中的用户信息
	function getUser(){
		var name="userInfo=";
		var user = "";
		var ca = document.cookie.split(';');
		$.each(ca, function(i, item){
			if(item.indexOf(name) != -1){
				user = item.substring(name.length,item.length);
			}    
		});
		return user;
	}
</script>