<%include ../layout/second_menu.html %>
<div class="panel-content">
    <div class="panel-title">
        <div class="title-main">
            <h2><%= secondMenu[action].title %>
                <a href="#add-group" data-toggle="modal" data-target="#add-group" class="btn btn-default btn-sm pull-right">添加新组</a>
            </h2>
        </div>
    </div>
    <div class="content-wrap">
        <div class="c-header">
        </div>
        <div class="c-body">
            <table class="table table-hover">
                <thead>
                <tr>
                    <th>组名</th>
                    <th>权限</th>
                    <th>使用账号</th>
                    <th width="100">操作</th>
                </tr>
                </thead>
                <tbody>
                <% for (let group of groupList) { %>
                <tr>
                    <td><%= group.name %></td>
                    <td><%= group.top_name %></td>
                    <td><%= group.manager_count %></td>
                    <td>
                        <a href="#edit-group" class="edit_permission btn btn-xs"
                           data-permission-id="<%= group._id %>"
                           data-permission-name="<%= group.name %>"
                           data-permission="<%= group.permission %>" data-toggle="modal" data-target="#edit-group">编辑</a>
                        <a href="#del-group" data-id="<%= group._id %>" class="del_permission btn btn-xs text-danger" data-toggle="modal" data-target="#del-group">删除</a>
                    </td>
                </tr>
                <% } %>
                </tbody>
            </table>
            <nav aria-label="Page navigation">
                <%include ../layout/page.html %>
            </nav>
        </div>
    </div>
</div>

<script type="text/javascript" src="/web/users/js/manager.js"></script>
<!-- 编辑组 -->
<div class="modal fade" id="edit-group" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <form method="post" action="/manager/authority/save">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel1">编辑权限组</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="title">组名</label>
                        <input class="form-control" type="text" id="title1" name="name" placeholder="输入组名" value="">
                        <input type="hidden" id="id" name="id" value="">
                    </div>
                    <div class="form-group">
                        <label for="title">权限</label>
                        <div class="checkbox" id="top_permission">
                            <% for(let permission of topPermissionList){ %>
                            <label><input type="checkbox" name="topPermission[]" id="<%= permission.controller %>" value="<%= permission._id %>"> <%= permission.name %> </label>&nbsp;
                            <% } %>
                        </div>
                    </div>
                    <!--打勾管理二级权限-->
                    <% for (let permission of permissionList) { %>
                    <% if (permission.count > 0) { %>
                    <div class="form-group">
                        <label for="title"><%= permission.name %>二级权限</label>
                        <div class="checkbox" id="<%= permission.controller %>_permission">
                            <% for(let second of permission.secondPermissionList){ %>
                            <label>
                                <input type="checkbox" data-controller="<%= permission.controller %>" name="permission_<%= permission.controller %>[]" value="<%= second._id %>"> <%= second.name %>
                            </label>&nbsp;
                            <% } %>
                        </div>
                    </div>
                    <% } %>
                    <% } %>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-primary">确定</button>
                </div>
            </div>
        </form>
    </div>
</div>
<!-- 添加组 -->
<div class="modal fade" id="add-group" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel2">添加新组</h4>
            </div>
            <form action="/manager/authority/add" method="post">
                <div class="modal-body">
                    <div class="form-group">
                        <label for="title">组名</label>
                        <input class="form-control" id="title" name="name" placeholder="输入组名">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="sumbit" class="btn btn-primary" >确认</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- 删除组 -->
<div class="modal fade" id="del-group" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel3">删除组</h4>
            </div>
            <div class="modal-body">
                <h4>删除后，相关账号将无法正常使用。</h4>
            </div>
            <form action="/manager/authority/delete" method="post">
                <input type="hidden" id="delete_id" name="id" value="">
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-danger" >确认删除</button>
                </div>
            </form>
        </div>
    </div>
</div>