<%@ page language="java" pageEncoding="UTF-8"
         contentType="text/html; charset=UTF-8" %>
<%@ page import="org.apache.commons.lang.StringEscapeUtils" %>
<%@ page isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String basePath = request.getContextPath();
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>兰亭集智知识管理系统-菜单管理</title>
    <jsp:include page="../../common/head.jsp"></jsp:include>
    <link rel="stylesheet" type="text/css" href="<%=basePath%>/resource/plugins/fundation-icons/foundation-icons.css">
</head>
<body>
<div class="easyui-layout" style="width:100%;height:100%;padding:0px 0px;">
    <table id="dgModule" class="easyui-treegrid" style="width:100%;height:100%"
           data-options="idField: 'id',treeField: 'menuname',toolbar:moduleToolbar,lines:true,emptyMsg:'没有符合检索条件的结果',loadMsg:'正在检索请稍后...',singleSelect:true,fitColumns:true,url:'<%=basePath%>/menu/json/module/list.action',method:'get'">
        <thead>
        <tr>
            <th data-options="field:'menuname',width:400">模块名称</th>
            <th data-options="field:'menucode',width:150">模块编码</th>
            <th data-options="field:'menuicon',width:80,align:'center',formatter:function(menuicon){
                return '<i class=\''+menuicon+'\'></i>';
            }">模块图标</th>
            <th data-options="field:'menuaction',width:400">模块地址</th>
            <th data-options="field:'menutype',width:100,formatter:function(menutype){
            if(menutype==0)
                return '分组';
            else if(menutype==1)
                return '菜单';
            else
                return '功能';
            }">模块类型</th>
            <th data-options="field:'menusequence',width:80">显示顺序</th>
            <th data-options="field:'menushow',width:80,formatter:function(menushow){
            if(menushow==1)
                return '显示';
            else
                return '隐藏';
            }">是否显示</th>
            <th data-options="field:'menushowtype',width:100,formatter:function(menutype){
            if(menutype=='tab')
                return '工作台';
             else if(menutype=='dialog')
                return '弹窗';
            else
                return '';
            }">显示类型</th>
            <th data-options="field:'addtime',width:180,formatter:function(date){
            return datetimeformat('Y-m-d H:i:s',date);
            }">注册时间</th>
            <th data-options="field:'_operation',width:80,formatter:optFormatter">操作</th>
        </tr>
        </thead>
    </table>
    <div id="editModule" class="easyui-window" title="模块管理" data-options="modal:true,closed:true,collapsible:false,resizable:false,minimizable:false,maximizable:false,iconCls:'icon-save'" style="width:500px;height:450px;padding:10px;">
        <div class="easyui-layout" data-options="fit:true">
            <div data-options="region:'center'" style="padding:10px;">
                <form>
                    <div style="margin-bottom:20px">
                        <input id="roleid" type="hidden">
                        <input class="easyui-textbox" id="modulecode" style="width:100%" data-options="label:'模块代码:',required:true">
                    </div>
                    <div style="margin-bottom:20px">
                        <input class="easyui-textbox" id="modulename" style="width:100%" data-options="label:'模块名称:',required:true">
                    </div>
                    <div style="margin-bottom:20px">
                        <input class="easyui-textbox" id="moduleicon" style="width:100%" data-options="label:'模块图标:',required:true">
                    </div>
                    <div style="margin-bottom:20px">
                        <input class="easyui-textbox" id="moduleurl" style="width:100%" data-options="label:'模块地址:',required:true">
                    </div>
                    <div style="margin-bottom:20px">
                        <input class="easyui-textbox" id="moduletype" style="width:100%" data-options="label:'模块类型:',required:true">
                    </div>
                    <div style="margin-bottom:20px">
                        <input class="easyui-textbox" id="ishow" style="width:100%" data-options="label:'是否显示:',required:true">
                    </div>
                    <div style="margin-bottom:20px">
                        <input class="easyui-combotree" id="parentid" data-options="idField: 'id',treeField: 'text',textField:'text',url:'<%=basePath%>/role/json/combox/list.action',method:'get',label:'父级角色:',labelPosition:'left,line:true'" style="width:100%">
                    </div>
                    <div style="margin-bottom:20px">
                        <input class="easyui-textbox" id="addtime" style="width:100%;" data-options="label:'注册时间:',disabled:true">
                    </div>
                </form>
            </div>
            <div data-options="region:'south',border:false" style="text-align:center;padding:5px 0 0;">
                <a id="btnSaveModule" href="javascript:void(0)" class="easyui-linkbutton" iconCls="fa fa-floppy-o" onclick="saveRoleInfo()" style="width:80px">保存</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="fa fa-times" onclick="moduleCancle()" style="width:80px">取消</a>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function optFormatter(value, row, index) {
        if(row.id>=100){
            return "--"
        }else {
            return "<a href='javascript:void(0);' onclick='editModule(" + row.id + ");'>编辑</a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' onclick='del(" + row.id + ");'>删除</a>";
        }
    }
    function del(id){
        var row = $('#dgModule').treegrid('find',id);
        $.messager.confirm("温馨提示", "你确定要删除当前节点：【" + row.menuname + "】及其子节点吗?", function (r) {
            if (r) {
            }
        });
        return false;
    }
    function editModule(id){
        if (id < 0) {
            $.messager.alert('温馨提示', '系统参数错误！');
        } else {
            var row = $('#dgModule').treegrid('find',id);
            //$("#roleid").val(row.id);
            $("#modulecode").textbox("setValue", row.menucode);
            $("#modulename").textbox("setValue", row.menuname);
            $("#moduleicon").textbox("setValue", row.menuicon);
            $("#moduleurl").textbox("setValue", row.menuaction);
            $("#moduletype").textbox("setValue", row.menutype);
            $("#ishow").textbox("setValue", row.menushow);
            var parentId=-1;
            if(row!=null&& row.parentid!=undefined && row.parentid!=null)
                parentId=row.parentid;
            $('#parentid').combotree('setValue',parentId);
           
        }
        $("#addtime").textbox("setValue", datetimeformat('Y-m-d H:i:s',new Date()));
        $('#btnSaveModule').linkbutton('enable');
        $('#editModule').window('open');
        return false;
    }
    function addModule(){
        $("#roleid").val("");
        $("#rolecode").textbox("clear");
        $("#rolename").textbox("clear");

        $('#rolecode').textbox('readonly',false);

        $('#addtime').textbox('readonly',true);
        $('#addtime').textbox('disable');

        $("#rolecode").textbox("enable");
        $("#rolename").textbox("enable");
        $('#parentid').combotree('enable');
        $('#parentid').combotree('setValue',-1);
        $("#addtime").textbox("setValue", datetimeformat('Y-m-d H:i:s',new Date()));
        $('#btnSaveRole').linkbutton('enable');
        $('#editModule').window('open');

        return false;
    }

    function moduleCancle(){
        $('#editModule').window('close');
    }

    var moduleToolbar = [{
        text:'新增模块',
        iconCls:'fa fa-arrows',
        handler:function(){
            addModule();
        }
    },'-',{
        text:'刷新模块',
        iconCls:'fa fa-repeat',
        handler:function(){
            $('#dgModule').treegrid('reload');
        }
    }];
</script>
</body>
</html>