<%@include file="/WEB-INF/common/layouts/common.jsp" %>
<%@ page language="java" pageEncoding="UTF-8" %>
<html>
<head>
    <title>登陆请求列表</title>
</head>
<body>
<link rel="stylesheet" href="${static_common}/jquery.qtip.custom/jquery.qtip.min.css" type="text/css">
<!-- 面包屑 begin -->
<div class="row-fluid">
    <div class="span12">
        <ul class="breadcrumb">
            <li><span class="divider" style="color:#26a0da;font-weight:bold;">/</span>登陆请求列表</li>
        </ul>
    </div>
</div>
<!-- 面包屑 begin -->

<div class="page-container">
    <div class="row${fluid}">
        <div class="span12">
            <form id="filterForm" class="form-inline filterForm" action="${ctx}/authorization" method="get">
                <%--<input type="text" name="search_LIKE_title" value="${param['search_LIKE_title']}"--%>
                       <%--class="m-wrap small span2" placeholder="标题">--%>
                <%--<input type="text" name="search_LIKE_content" value="${param['search_LIKE_content']}"--%>
                       <%--class="m-wrap small span2" placeholder="内容">--%>
                <%--<div class="buttons pull-right" style="margin-left:15px;">--%>
                    <%--<a href="${ctx}/notice?action=create" class="btn blue pull-right" title="新增"><i--%>
                            <%--class="icon-plus"></i></a>--%>
                <%--</div>--%>
                <%--<div class="buttons pull-right">--%>
                    <%--<a href="javascript:void(0);" onclick="deleteById('')" class="btn blue pull-right" title="删除"><i--%>
                            <%--class="icon-minus"></i></a>--%>
                <%--</div>--%>
                <%--<div class="buttons pull-right" style="margin:3px 30px 0 0;">--%>
                    <%--<i class="icon-search icon-2x pointer" onclick="$('#filterForm').submit();" title="搜索"></i>--%>
                <%--</div>--%>
            </form>
        </div>
    </div>
    <table class="table table-striped table-advance table-hover">
        <thead>
        <tr>
            <%--<th width="40" style="text-align:center"><input id="memberCheckAll" type="checkbox"--%>
                                                            <%--onclick="checkAll(this)"/></th>--%>
            <th width="100">序号</th>
            <th width="100">姓名</th>
            <th width="100">账号</th>
            <th width="100">登录IP</th>
            <th width="100">登录地址</th>
            <th width="100">请求登录时间</th>
            <th width="150">状态</th>
            <th width="150">操作</th>
        </tr>
        </thead>
        <c:forEach items="${requestAuthorizations}" var="requestAuthorization">
            <tr>
                <%--<td nowrap="nowrap" style="text-align:center">--%>
                    <%--<input type="checkbox" name="memberCheck" value="${notice.id}" onclick="checkMember(this)"/>--%>
                <%--</td>--%>
                <td nowrap="nowrap">
                    <c:out value="${requestAuthorization.id}"/>
                </td>
                <td nowrap="nowrap">
                    <c:out value="${requestAuthorization.realName}"/>
                </td>
                <td nowrap="nowrap">
                    <c:out value="${requestAuthorization.name}"/>
                </td>
                <td nowrap="nowrap">
                    <c:out value="${requestAuthorization.loginIp}"/>
                </td>
                <td nowrap="nowrap">
                    <c:out value="${requestAuthorization.loginCity}"/>
                </td>
                <td nowrap="nowrap">
                    <f:formatDate value='${requestAuthorization.loginTime}' pattern='yyyy-MM-dd HH:mm:ss'/>
                </td>
                <td nowrap="nowrap">
                    <c:if test="${0 eq requestAuthorization.status}">
                        <c:out value="未授权"/>
                    </c:if>
                    <c:if test="${1 eq requestAuthorization.status}">
                        <c:out value="已授权"/>
                    </c:if>
                    <c:if test="${2 eq requestAuthorization.status}">
                        <c:out value="失效"/>
                    </c:if>
                </td>
                <td nowrap="nowrap">
                    <c:if test="${0 eq requestAuthorization.status}">
                        <%--<c:out value="授权"/>--%>
                        <button type="button" class="btn btn-warning" onclick="authorizationById(${requestAuthorization.id})">授权
                        </button>
                    </c:if>
                    <c:if test="${1 eq requestAuthorization.status || 2 eq requestAuthorization.status}">
                        <c:out value="-"/>
                    </c:if>
                </td>
            </tr>
        </c:forEach>
    </table>
    <div class="row${fluid}">
        <house365:pagination page="${page}"/>
    </div>
</div>
<script language="javascript" type="text/javascript"
        src="${ctx}/resources/jquery.qtip.custom/jquery.qtip.min.js"></script>
<script type="text/javascript">

    function authorizationById(id) {
        $.ajax({
            url: '${ctx}/authorization/' + id,
//            type: "UPDATE",
            success: function (data) {
                if(data.RESULTFLAG == "1"){
                    window.location.reload();
//                    alert("已授权")
                }else{
                    alert("授权失败");
                    return false;
                }
            }
        });
    }

    $(document).keydown(function (event) {
        if (event.keyCode == "13") {
            //回车执行查询
            $('#filterForm').submit();
        }
    })

    //全选
    function checkAll(btn) {
        if (btn.checked) {
            for (i = 0; i < document.all("memberCheck").length; i++) {
                document.all("memberCheck")[i].checked = "checked";
            }
        }
        else {
            for (i = 0; i < document.all("memberCheck").length; i++) {
                document.all("memberCheck")[i].checked = "";
            }
        }
    }

    //单选
    function checkMember(btn) {
        if (btn.checked) {
            var checkAll = true;
            for (i = 0; i < document.all("memberCheck").length; i++) {
                if (document.all("memberCheck")[i].checked == false) {
                    checkAll = false;
                }
            }

            if (checkAll) {
                document.getElementById("memberCheckAll").checked = true;
            }
        }
        else {
            document.getElementById("memberCheckAll").checked = false;
        }
    }

    var deleteById = function (selectedId) {
        /*
         id为空则是多选  判断是否为空
         为空 提示选择
         不为空 确认后删除
         不为空单选确认后删除
         */
        if (selectedId == "") {
            for (i = 0; i < document.getElementsByName('memberCheck').length; i++) {
                if (document.getElementsByName('memberCheck')[i].checked) {
                    selectedId += document.getElementsByName('memberCheck')[i].value + ",";
                }
            }

            var str = "";
            if (selectedId != "") {
                str = selectedId.split(",");

                if (str[str.length - 1] == "") {
                    selectedId = selectedId.substring(0, selectedId.length - 1);
                }
            }
        }

        if (selectedId == "") {
            House365Util.createModal("删除公告", "请至少选择一条公告!", function () {
            });
        }
        else {
            House365Util.createModal("删除公告", "确定要删除该公告？", function () {
                $.ajax({
                    url: '${ctx}/notice/' + selectedId,
                    type: "DELETE",
                    success: function () {
                        window.location.reload();
                    }
                });
            });
        }

    };

</script>
</body>
</html>
