<#include "/common/defaultEngine.html"/>
<@pageTheme mark="${config.optimize()?string('true', 'false')}">
<@header title="角色列表" libs=["table"]/>
<div class="container-div">
	<div class="row">
        <div class="col-sm-12 search-collapse">
        <@f.form id="role-form">
        <div class="select-list">
            <ul>
                <li>
                    <@ctx.i18n text = "角色名称"/>：<input type="text"  class="form-control" name="roleName"/>
                </li>

                <li>
                    <@ctx.i18n text = "权限字符"/>：<input type="text" class="form-control" name="roleKey"/>
                </li>
                <li>
                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;<@ctx.i18n text = "查询"/></a>
                    <a class="btn btn-warning btn-rounded btn-sm" onclick="opt.form.reset()"><i class="fa fa-refresh"></i>&nbsp;<@ctx.i18n text = "重置"/></a>
                </li>
            </ul>
        </div>
        </@f.form>
        </div>
        <@table id="bootstrap-table">
            <@shiro.hasPermission name="sys:role:add">
                <a class="btn btn-success" onclick="opt.operate.add()"><i class="fa fa-plus"></i>&nbsp;<@ctx.i18n text = "新增"/></a>
            </@shiro.hasPermission>
            <@shiro.hasPermission name="sys:role:edit">
                <a class="btn btn-primary single disabled" onclick="opt.operate.edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;<@ctx.i18n text = "修改"/></a>
            </@shiro.hasPermission>
            <@shiro.hasPermission name="sys:role:del">
                <a class="btn btn-danger multiple disabled" onclick="opt.operate.delAll()">
                    <i class="fa fa-remove"></i> <@ctx.i18n text = "删除"/>
                </a>
            </@shiro.hasPermission>
        </@table>
    </div>
</div>
<@footer>
<script>
    var editFlag = "${permission.hasPermi('sys:role:edit')}";
    var delFlag = "${permission.hasPermi('sys:role:del')}";
    var datas = ${dict.getDictListJson('sys_normal_disable')};
    var dataScope = ${dict.getDictListJson('sys_role_data_scope')};
    var visible = ${permission.isPermitteds("sys:role:edit,sys:role:del")?string('true', 'false')};
    var prefix = baseURL + 'sys/role';
    $(function() {
            /*初始表格对象*/
            var options = {
                url: prefix + "/list",
                addUrl: prefix + "/add",
                editUrl: prefix + "/edit/{id}",
                delUrl: prefix + "/del",
                sortName: "createTime",
                /* rightFixedColumns: true,
                 rightFixedNumber: 1, */
                uniqueId: "id", /*唯一ID*/
                modalName: "角色",
                columns: [
                    /*{title: "序号",width:10,align:"center", formatter: function (value, row, index) {
                             return $.table.serialNumber(index);
                     }},
                     {checkbox: true},*/
                    {field: 'id',title: "<@ctx.i18n text = "角色编码"/>", sortable: true},
                    {field: 'roleName', title: "<@ctx.i18n text = "角色名称"/>"},
                    {field: 'roleKey', title: "<@ctx.i18n text = "权限字符"/>"},
                    {field: 'dataScope', title: "<@ctx.i18n text = "数据范围"/>", formatter: function(value, row, index) {
                            return $.table.selectDictLabel(dataScope, value);
                    }},
                    {field: 'roleSort', title: "<@ctx.i18n text = "顺序"/>",sortable:true},
                    {field: 'status', title: "<@ctx.i18n text = "状态"/>", align: 'center', formatter: function(value, row, index) {
                            return $.table.selectDictLabel(datas, value);
                    }},
                    {field: 'createTime', title: "<@ctx.i18n text = "创建时间"/>",sortable: true},
                    {title: "<@ctx.i18n text = "操作"/>", align: 'center',visible:visible, class:'action', formatter: function(value, row, index) {
                            /*var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="opt.operate.edit(\'' + row.roleId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + delFlag + '" href="javascript:void(0)" onclick="opt.operate.del(\'' + row.roleId + '\')"><i class="fa fa-remove"></i>删除</a>');
                            return actions.join('');*/
                            var actions = [];
                            actions.push('<a class="' + editFlag + '" href="javascript:void(0)" title="<@ctx.i18n text = "修改"/>" onclick="opt.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i></a> ');
                            if(row.status === "0"){
                                actions.push('<a class="' + editFlag + '" href="javascript:void(0)" title="<@ctx.i18n text = "停用"/>" onclick="disable(\'' + row.id + '\')"><i class="glyphicon glyphicon-ban-circle"></i></a> ');
                            }else{
                                actions.push('<a class="' + editFlag + '" href="javascript:void(0)" title="<@ctx.i18n text = "启用"/>" onclick="enable(\'' + row.id + '\')"><i class="glyphicon glyphicon-ok-circle"></i></a> ');
                            }
                            actions.push('<a class="' + delFlag + '" href="javascript:void(0)" title="<@ctx.i18n text = "删除"/>" onclick="opt.operate.del(\'' + row.id + '\')"><i class="fa fa-trash-o"></i></a> ');
                            var info = "<a  class='btn btn-default btn-xs' onclick=javascript:authorization(\'" + row.id + "\');><i class='fa icon-check'></i> <@ctx.i18n text = "授权菜单"/></a>&nbsp;";
                            info += "<a  class='btn btn-default btn-xs' onclick=javascript:authData(\'" + row.id + "\');><i class='fa fa-shield'></i> <@ctx.i18n text = "数据授权"/></a>&nbsp;";
                            info += "<a  class='btn btn-default btn-xs' onclick=javascript:authUser(\'" + row.id + "\');><i class='fa icon-user'></i> <@ctx.i18n text = "分配用户"/></a>&nbsp;";
                            actions.push('<a tabindex="0" class="' + delFlag + '" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="'+info+'"><i class="fa fa-chevron-circle-right"  title="<@ctx.i18n text = "更多操作"/>"></i></a>');
                            return actions.join('');
                        }}]
            };
            $.table.init(options);
    });

    /* 用户管理-停用 */
    function disable(roleId) {
        opt.modal.confirm("确认要停用角色吗？", function() {
            opt.operate.post(prefix + "/changeStatus", { "id": roleId, "status": 1 });
        });
        return;
    }

    /* 用户管理启用 */
    function enable(roleId) {
        opt.modal.confirm("确认要启用角色吗？", function() {
            opt.operate.post(prefix + "/changeStatus", { "id": roleId, "status": 0 });
        });
        return;
    }
    
    /*授权菜单*/
    function authorization(roleId) {
        opt.modal.open("<@ctx.i18n text = "授权菜单"/>", prefix + "/authorization/" + roleId,1100,500);
        return;
    }

    /*角色分配用户*/
    function authUser(roleId) {
        var url = prefix + '/authUser/' + roleId;
        opt.modal.openTab("<@ctx.i18n text = "角色分配用户"/>", url);
    }

    /*角色分配数据权限*/
    function authData(roleId){
        var url = prefix + '/authData/' + roleId;
        opt.modal.openTab("<@ctx.i18n text = "角色分配数据权限"/>", url);
    }
</script>
</@footer>
</@pageTheme>