<%@include file="/WEB-INF/common/layouts/common.jsp" %>
<%@ page language="java" pageEncoding="UTF-8" %>
<html>
<head>
    <title>权限列表</title>
    <link href="${static_common}/treeTable/themes/vsStyle/treeTable.min.css" rel="stylesheet" type="text/css"/>
    <script src="${static_common}/treeTable/jquery.treeTable.min.js" type="text/javascript"></script>
</head>
<body>
<%-- <div class="row${fluid}">
    <div class="span6">
        <h2 class="page-title">权限列表</h2>
    </div>
    <div class="span6 header_buttons">
        <a href="${ctx}/permission?action=create" class="btn blue pull-right"><i class="icon-plus"></i></a>
    </div>
</div> --%>

<ul class="nav nav-tabs">
    <li class="active"><a href="${ctx}/permission/">菜单列表</a></li>
    <li><a href="${ctx}/permission?action=create">菜单添加</a></li>
</ul>

<div class="page-container">
    <%--<div class="row${fluid}">--%>
    <%--<div class="span12">--%>
    <%--<form id="filterForm" class="form-inline filterForm" action="${ctx}/permission" method="get">--%>
    <%--<div class="buttons pull-right" style="margin-left:15px;">--%>
    <%--<a href="${ctx}/permission?action=create" class="btn blue pull-right" title="新增"><i--%>
    <%--class="icon-plus"></i></a>--%>
    <%--</div>--%>
    <%--</form>--%>
    <%--</div>--%>
    <%--</div>--%>
    <table id="treeTable" class="table table-striped table-bordered table-condensed hide">
        <thead>
        <tr>
            <!-- <th width="40" style="text-align:center"><input id="memberCheckAll" type="checkbox" onclick="checkAll(this)" /></th> -->
            <!-- <th width="100">id</th> -->
            <!-- <th width="100">编码</th> -->
            <th width="100">名称</th>
            <th width="100">链接</th>
            <th width="100">可见</th>
            <th width="100">权限</th>
            <!-- <th width="100">父权限ID</th> -->
            <!-- <th width="100">排序</th> -->
            <!-- <th width="100">对应资源</th>
            <th width="100">特别权限</th> -->
            <!-- <th width="100">1 菜单 2 页面 3 操作</th>
            <th width="100">创建人用户ID</th> -->
            <!-- <th width="100">创建人</th>
            <th width="100">创建时间</th> -->
            <!-- <th width="100">创建人电脑IP</th>
            <th width="100">最后一次修改人用户ID</th>
            <th width="100">最后一次修改人用户名</th>
            <th width="100">最后一次修改时间</th>
            <th width="100">最后一次修改人电脑IP</th> -->
            <th width="150">操作</th>
        </tr>
        </thead>
        <c:forEach items="${permissions}" var="permission">
            <tr id="${permission.id}" pId="${permission.parentId}">
                    <%-- <td nowrap="nowrap" style="text-align:center">
                        <input type="checkbox" name="memberCheck" value="${permission.id}" onclick="checkMember(this)"/>
                    </td> --%>
                    <%-- <td nowrap="nowrap">
                        <a href="${ctx}/permission/${permission.id}">						<c:if test="${null ne permission.id && '' ne permission.id}">
                                <c:out value="${permission.id}" />
                            </c:if>
                            <c:if test="${null eq permission.id || '' eq permission.id}">
                                &nbsp;
                            </c:if>
                        </a>
                    </td> --%>
                    <%-- <td nowrap="nowrap">
                            <c:if test="${null ne permission.code && '' ne permission.code}">
                                <c:out value="${permission.levelStr}${permission.code}" />
                            </c:if>
                            <c:if test="${null eq permission.code || '' eq permission.code}">
                                &nbsp;
                            </c:if>
                    </td> --%>
                <td nowrap="nowrap">
                        ${permission.name}
                </td>
                <td nowrap="nowrap">
                    <c:if test="${null ne permission.resource && '' ne permission.resource}">
                        <c:out value="${permission.resource}"/>
                    </c:if>
                    <c:if test="${null eq permission.resource || '' eq permission.resource}">
                        &nbsp;
                    </c:if>
                </td>

                <td nowrap="nowrap">
                    <c:if test="${null ne permission.isShow && '' ne permission.isShow}">
                        ${permission.isShow eq '1'?'显示':'隐藏'}
                    </c:if>
                    <c:if test="${null eq permission.isShow || '' eq permission.isShow}">
                        &nbsp;
                    </c:if>
                </td>

                <td nowrap="nowrap" title="${permission.permission}">
                    <c:if test="${null ne permission.permission && '' ne permission.permission}">
                        <c:out value="${house365:abbr(permission.permission,30)}"/>
                    </c:if>
                    <c:if test="${null eq permission.permission || '' eq permission.permission}">
                        &nbsp;
                    </c:if>
                </td>

                <td nowrap="nowrap">
                    <i class="icon-edit pointer icon-large"
                       onclick="window.location='${ctx}/permission/${permission.id}?action=edit'"></i>
                    &nbsp;&nbsp; <i
                        title="删除"
                        class="icon-minus pointer icon-large"
                        onclick="deleteById('${permission.id}')"> </i>
                </td>
            </tr>
        </c:forEach>
    </table>
    <div class="row${fluid}">
        <house365:pagination page="${page}"/>
    </div>
</div>

<script type="text/javascript">

    $(document).ready(function () {
        $("#treeTable").treeTable({expandLevel: 3}).show();
    });
    //全选
    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}/permission/' + selectedId,
                    type: "DELETE",
                    success: function () {
                        window.location.reload();
                    }
                });
            });
        }

    };

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