layui.extend({driver: `{/}${ctx}/js/business/datasource/driver`})
/**
 * <p>
 *  edit.js
 * </p>
 *
 * @author Administrator
 * @since 2021/5/24
 */
let editPage;
layui.use(['form', 'layer', 'editPage', 'driver'], function () {
    editPage = layui.editPage;
    // 获取请求参数
    const requestParam = layui.url().search;

    editPage.init({
        formId: 'datasourceForm',
        formInitUrl: `${ctx}/business/datasource/get/${requestParam.id}`,
        formSubmitUrl: `${ctx}/business/datasource/save`,
        formInitDone(data){
            //$('#driverLabel').text(data.driverName);
        }
    });

    /*layui.driver.init({elem: '#chooseDriverBtn', area:['550px','500px'], yes(data){
            if (data) {
                let formVal = {
                    driverId: data.id,
                    jdbcDriverClass: data.driverClass,
                };
                layui.form.val('datasourceForm', formVal);
                $('#driverLabel').text(data.name);
            }
        }, done(){

        }});*/

});

/**
 * 对父页面暴露save方法
 * @returns {*}
 */
function save() {
    return editPage.submit();
}

/**
 * 测试连接
 */
function connectTest() {
    let data = editPage.getData();
    $.post(`${ctx}/business/datasource/connection/test`, data, function (res) {
        if (res.flag) {
            showOkMsg('连接成功');
        } else {
            showErrorMsg(res.msg);
        }
    });
}