<%@ 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>
</head>
<body>
<div  class="easyui-layout"  title="Register" style="width:100%;height:100%;padding:0px 0px;">
    <table id="dgCache" style="width:100%;height:100%"
           data-options="emptyMsg:'没有符合检索条件的结果',loadMsg:'正在检索请稍后...',toolbar:'#tbCache',singleSelect:true,pagination:true,fitColumns:true,url:'<%=basePath%>/cache/json/list.action',method:'get'">
        <thead>
        <tr>
            <th data-options="field:'id',width:80">编号</th>
            <th data-options="field:'serverip',width:150">用户名</th>
            <th data-options="field:'serverdescription',width:400">全称</th>
            <th data-options="field:'cachetype',width:100,formatter:function(lock){
                if(lock==0)
                    return 'redis';
                else if(lock==1)
                    return 'memcache';
                else if(lock==2)
                    return 'Mongo';
                else
                    return '其他';
            }">缓存类型</th>
            <th data-options="field:'registertime',width:200,formatter:function(date){
            return datetimeformat('Y-m-d H:i:s',date);
            }">注册时间</th>
            <th data-options="field:'_operation',width:180,formatter:optFormatter">操作</th>
        </tr>
        </thead>
    </table>

    <div id="tbCache" style="padding-left: 10px;">
        <input class="easyui-searchbox" style="width: 200px;" data-options="prompt:'请输入检索关键词'">
        <a href="javascript:void(0);" onclick="searchServer()" class="easyui-linkbutton" data-options="iconCls:'fa fa-search-plus',plain:true">开始检索</a>
        <a href="javascript:void(0);" onclick="addServer()" class="easyui-linkbutton" data-options="iconCls:'fa fa-arrows',plain:true">添加服务器</a>
        <a href="javascript:void(0);" onclick="refreshServers()" class="easyui-linkbutton" data-options="iconCls:'fa fa-repeat',plain:true">刷新服务器</a>
    </div>

    <div id="w" 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:390px;padding:10px;">
        <div class="easyui-layout" data-options="fit:true">
            <div data-options="region:'center'" style="padding:10px;">
                <form id="ff" method="post">
                    <div style="margin-bottom:20px">
                        <input class="easyui-textbox" id="serverip" style="width:100%" data-options="label:'服务器IP:',readonly:true">
                    </div>
                    <div style="margin-bottom:20px">
                        <select class="easyui-combobox" id="cacheType" label="缓存类型:" style="width:100%"><option value="-1">请选择</option><option value="0">Redis</option><option value="1">Memcached</option><option value="2">Mongo</option><option value="3">Other</option></select>
                    </div>
                    <div style="margin-bottom:20px">
                        <input class="easyui-textbox" id="cacheKey" style="width:100%" data-options="label:'缓存Key:',required:true">
                    </div>
                    <div style="margin-bottom:20px">
                        <input class="easyui-textbox" id="cacheValue" style="width:100%;height:100px" data-options="label:'缓存值:',multiline:true">
                    </div>
                </form>
            </div>
            <div data-options="region:'south',border:false" style="text-align:center;padding:5px 0 0;">
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="getCacheValue()" style="width:80px">查看</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-reload" onclick="submitForm()" style="width:80px">更新</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="clearForm()" style="width:80px">删除</a>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        function optFormatter(value,row,index){
            return "<a href='javascript:void(0);' onclick='manageServer("+index+");'>管理</a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);'>编辑</a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' onclick='return del(\"" + row.serverip + "\"," + row.id + ");'>删除</a>";
        }
        function del(showname,id){
            $.messager.confirm("温馨提示", "你确定要删除服务器：【" + showname + "】吗?", function (r) {
                if (r) {
                }
            });
            return false;
        }
        function getCacheValue(){
            $.ajax({
                type: "GET",
                url: "<%=basePath%>/cache/json/cache.action",
                data: {ip:$("#serverip").textbox("getValue"), type:$("#cacheType").combobox("getValue"), key:$("#cacheKey").textbox("getValue")},
                dataType: "json",
                beforeSend:function(XMLHttpRequest){
                },
                success: function(data){
                    $("#cacheValue").textbox("setValue", data.message);
                },
                complete:function(XMLHttpRequest, textStatus){
                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                }
            });
            return false;
        }
        function manageServer(index){
            if(index<0){
                $("#serverip").textbox("clear");
                $("#cacheType").textbox("clear");
                $("#cacheType").combobox("setValue",-1);
            }else {
                var row = $('#dgCache').datagrid('getRows')[index];
                $("#serverip").textbox("setValue", row.serverip);
                $("#cacheType").combobox("setValue", row.cachetype);
                $("#cacheType").combobox('readonly',true);
            }
            $('#w').window('open');
        }
        $(function(){
            var pager = $('#dgCache').datagrid().datagrid('getPager');
        })
    </script>
</div>
</body>
</html>