<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改模型对象数据库配置')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-modelDbs-edit" th:object="${modelDbs}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">数据库名称：</label>
                <div class="col-sm-8">
                    <input id="dbName" name="dbName" th:field="*{dbName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">driverClass：</label>
                <div class="col-sm-8">
                    <input id="driverClassName" name="driverClassName" th:field="*{driverClassName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">URL：</label>
                <div class="col-sm-8">
                    <textarea id="url" name="url" class="form-control" required>[[*{url}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">用户名：</label>
                <div class="col-sm-8">
                    <input id="userName" name="userName" th:field="*{userName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">密码：</label>
                <div class="col-sm-8">
                    <input id="password" name="password" th:field="*{password}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label"></label>
                <div class="col-sm-8">
                    <a class="btn btn-warning" onclick="pingLoadDriver()">
                        <i class="fa fa-link"></i> 连接测试
                    </a>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "model/modelDbs";
        $("#form-modelDbs-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-modelDbs-edit').serialize());
            }
        }


        function pingLoadDriver() {
            if ($.validate.form()) {
                // $.operate.post(prefix + "/pingLoadDriver", $('#form-modelDbs-add').serialize());

                var config = {
                    url: prefix + "/pingLoadDriver",
                    type: "post",
                    dataType: "json",
                    data: {
                        "driverClassName": $("#driverClassName").val(),
                        "url": $("#url").val(),
                        "userName": $("#userName").val(),
                        "password": $("#password").val()
                    },
                    beforeSend: function () {
                        $.modal.loading("正在处理中，请稍候...");
                    },
                    success: function(result) {
                        if (result.code == web_status.SUCCESS) {
                            $.modal.alertSuccess(result.msg)
                        }  else if (result.code == web_status.WARNING) {
                            $.modal.alertWarning(result.msg)
                        }  else {
                            $.modal.alertError(result.msg);
                        }
                        $.modal.closeLoading();
                    }
                };
                $.ajax(config);
            }
        }
    </script>
</body>
</html>