<%--
  Created by IntelliJ IDEA.
  User: herbert
  Date: 2017/11/8
  Time: 08:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String basePath = request.getContextPath();
%>
<html>
<head>
    <meta charset="UTF-8">
    <title>兰亭集智知识管理系统-KBase文献管理</title>
    <jsp:include page="../../common/head.jsp"></jsp:include>
</head>
<body>
<div class="easyui-layout" title="Register" style="width:100%;height:100%;padding:0px 0px;">
    <table id="tbLog">

    </table>
    <div id="toolLog" style="padding-left: 10px;">
        请输入检索数据库：<input name="dateStr" id="dateStr" class="easyui-searchbox" style="width: 200px;">
        请输入检索关键词：<input name="keywords" id="keywords" class="easyui-searchbox" style="width: 200px;">
        <a id="submit_search" href="javascript:void(0);" class="easyui-linkbutton">开始检索</a>
    </div>

    <div id="logContentInfo" class="easyui-window" title="日志详细信息"
         data-options="modal:true,closed:true,collapsible:false,resizable:false,minimizable:false,maximizable:false,iconCls:'fi-marker'"
         style="width:600px;height:600px;padding:10px;">
        <div class="easyui-layout" data-options="fit:true">
            <div data-options="region:'center'" style="padding:10px;">
                <table style="table-layout:fixed;">
                    <tbody>
                        <tr><td style="width: 100px;text-align: right;padding-bottom: 5px;padding-top: 5px;padding-right: 5px;">服务器:</td><td  style="width: 460px;" id="log-server-ip"></td></tr>
                        <tr><td style="width: 100px;text-align: right;padding-bottom: 5px;padding-top: 5px;padding-right: 5px;">日志时间:</td><td style="width: 460px;" id="log-server-time"></td></tr>
                        <tr><td style="width: 100px;text-align: right;padding-bottom: 5px;padding-top: 5px;padding-right: 5px;">日志级别:</td><td style="width: 460px;" id="log-server-level"></td></tr>
                        <tr><td style="width: 100px;text-align: right;padding-bottom: 5px;padding-top: 5px;padding-right: 5px;">日志位置:</td><td style="width: 460px;" id="log-server-location"></td></tr>
                        <tr><td style="width: 100px;vertical-align: top;text-align: right;padding-bottom: 5px;padding-top: 5px;padding-right: 5px;">日志内容:</td><td style="width: 460px;word-wrap:break-word;word-break:break-all;" id="log-server-content"></td></tr>
                    </tbody>
                </table>
            </div>
            <div data-options="region:'south',border:false" style="text-align:center;padding:5px 0 0;">
                <a id="btnCancle" href="javascript:void(0)" class="easyui-linkbutton" iconCls="fa fa-times" onclick="cancleSubmit()"
                   style="width:80px">取消</a>
            </div>
        </div>
    </div>
</div>
<script text="text/javascript">
    $(function () {
        search();
    })
    $("#submit_search").linkbutton({iconCls: 'icon-search', plain: true})
        .click(function () {
            search();
        });
    function logformat(value){
        if (value.length > 100) value = value.substr(0, 100) + "...";
        return value;
    }
    function search() {
        var dateStr = $("#dateStr").val();
        var keywords = $("#keywords").val();

        $("#tbLog").datagrid({
            toolbar: "#toolLog",
            method: "Get",
            singleSelect: true,
            url: "<%=basePath%>/log/json/mtlogs.action?dateStr=" + dateStr + "&keywords=" + keywords,
            loadMsg: '数据加载中请稍后……',
            nowrap: false,
            fit:true,
            rownumbers: true,
            pagination: true,
            fitColumns:true,
            pageSize: 20,
            columns: [[
                {field: 'level', title: '级别',formatter:formatLevel, width: 50},
                {field: 'logger', title: '日志位置', width: 300},
                {field: 'message', title: '日志内容', formatter: logformat, width: 900,},
                {field: 'userName', title: '服务器', width: 150},
                {field: 'date', title: '时间', formatter: formatDatebox, width: 150},
                {field: '_operation', title: '操作', formatter: formatOperation, width: 150}
            ]]
        });
    }

    Date.prototype.format = function (format) {
        var o = {
            "M+": this.getMonth() + 1, // month
            "d+": this.getDate(), // day
            "h+": this.getHours(), // hour
            "m+": this.getMinutes(), // minute
            "s+": this.getSeconds(), // second
            "q+": Math.floor((this.getMonth() + 3) / 3), // quarter
            "S": this.getMilliseconds() // millisecond
        }
        if (/(y+)/.test(format))
            format = format.replace(RegExp.$1, (this.getFullYear() + "")
                .substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(format))
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        return format;
    };
    function formatDatebox(value) {
        if (value == null || value == '') {
            return '';
        }
        var dt;
        if (value instanceof Date) {
            dt = value;
        } else {
            dt = new Date(value);
        }
        return dt.format("yyyy-MM-dd hh:mm:ss");
    };
    function formatOperation(value,row,index){
        return "<a href='javascript:void(0);' style='text-decoration:none' onclick='viewLogContent("+index+");'>[详情]</a>"
    }
    function formatLevel(value,row,index){
        if(value=="Info"){
            return  "<span style=\'color:black;\'>信息</span>";
        }else if(value=="Debug"){
            return "<span style=\'color:yellowgreen;\'>调试</span>";
        }else if(value=="Error"){
            return "<span style=\'color:red;\'>严重</span>";
        }else{
            return value;
        }
    }
    $(function(){
        $('#tbLog').datagrid().datagrid('getPager').pagination({showPageList:false});
    });
    function viewLogContent(index){
        var item = $('#tbLog').datagrid('getRows')[index];
        $("#log-server-ip").html(item.userName);
        $("#log-server-time").html(formatDatebox(item.date));
        $("#log-server-level").html(formatLevel(item.level,null,0));
        $("#log-server-location").html(item.logger);
        $("#log-server-content").html(item.message);
        $('#logContentInfo').window('open');
    }
    function cancleSubmit(){
        $('#logContentInfo').window('close');
    }
</script>
</body>
</html>
