<#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="module-form">
        <div class="select-list">
            <ul>
                <li>
                    <@ctx.i18n text = "模块名称"/>：
                    <input type="text" class="form-control" name="moduleName"/>
                </li>
                <li>
                    <@ctx.i18n text = "状态"/>：
                    <@f.select name="status" blankValue="" blankLabel="所有" dictType="sys_module_status" />
                </li>
                <li>
                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>  <@ctx.i18n text = "查询"/></a>
                    <a class="btn btn-warning btn-rounded btn-sm" onclick="opt.form.reset()"><i class="fa fa-refresh"></i> <@ctx.i18n text = "重置"/></a>
                </li>
            </ul>
        </div>
    </@f.form>
    </div>
    <@table id="bootstrap-table">
        <@shiro.hasPermission name="sys:module:add">
            <a class="btn btn-success" onclick="opt.operate.add()"><i class="fa fa-plus"></i> <@ctx.i18n text = "新增"/></a>
        </@shiro.hasPermission>
        <@shiro.hasPermission name="sys:module:edit">
            <a class="btn btn-primary single disabled" onclick="opt.operate.edit()"><i class="fa fa-pencil-square-o"></i> <@ctx.i18n text = "修改"/></a>
        </@shiro.hasPermission>
        <@shiro.hasPermission name="sys:module: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:module:edit")}";
    var listFlag = "${permission.hasPermi("sys:module:add")}";
    var delFlag = "${permission.hasPermi("sys:module:del")}";
    var visible = ${permission.isPermitteds("sys:module:edit,
sys:module:del,sys:module:add")?string('true', 'false')};
    var statusDatas = ${dict.getDictListJson('sys_module_status')};
    var prefix = baseURL + "sys/module";

    $(function() {
        var options = {
            url: prefix + "/list",
            addUrl: prefix + "/add",
            editUrl: prefix + "/edit/{id}",
            delUrl: prefix + "/del",
            modalName: "模块",
            sortName: "id",
            uniqueId:    'id'                           , /* 唯一ID */
            columns: [{
                title: $.i18n.prop("序号"), width: 5, align: "center", formatter: function (value, row, index) {
                    return $.table.serialNumber(index);
                }
            }
                ,{
                    field : 'id'
                    ,title : '<@ctx.i18n text = "模块编码"/>'
                    ,visible: false
                }
                ,{
                    field : 'moduleName'
                    ,title : '<@ctx.i18n text = "模块名称"/>'
                    ,formatter: function(value, row, index) {
                        return "<i class='"+row.icon+"'></i> "+value;
                    }
                }
                ,{
                    field : 'moduleCode'
                    ,title : '<@ctx.i18n text = "模块编码"/>'
                }
                ,{
                    field : 'description'
                    ,title : '<@ctx.i18n text = "模块描述"/>'
                }
                ,{
                    field : 'currentVersion'
                    ,align: 'left'
                    ,halign: 'left'
                    ,title : '<@ctx.i18n text = "版本"/>'
                    ,formatter: function (value, row, index) {
                        var v = 0;
                        if(row.moduleCode == 'core'){
                            v = opt.common.compareVersion('${config.getVersion()}',value+"");
                        }
                        return '<div>'+value+(v==1?'  <i class="fa-fw ion-ios-cloud-upload-outline" style="color: red"></i>':'')+'</div></div>'
                    }
                }
                ,{
                    field : 'status'
                    ,title : '<@ctx.i18n text = "状态"/>'
                    ,formatter: function(value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                }
                ,{
                    title:"<@ctx.i18n text = "操作"/>"
                    ,align: 'left'
                    ,visible:visible
                    ,class:'action'
                    ,formatter: function(value, row, index) {
                        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' && row.moduleCode != 'core'){
                            actions.push('<a class="' + delFlag + '" href="javascript:void(0)" title="<@ctx.i18n text = "停用"/>" onclick="disable(\'' + row.id + '\')"><i class="glyphicon glyphicon-ban-circle"></i></a> ');
                        }
                        if(row.moduleCode == 'core'){
                            actions.push("  "+$.table.tooltip('禁止删除操作!',5));
                        }else{
                            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> ');
                        }
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });

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

    /* 用户管理启用 */
    function enable(id) {
        opt.modal.confirm("确认要启用模块吗？", function() {
            opt.operate.post(prefix + "/status", { "id": id, "status": 0 });
        })
    }
</script>
</@footer>
</@pageTheme>