<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('科大讯飞TTS参数配置')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
    <style>
    </style>
</head>

<body>
<div class="main-content">
    <div class="h4 form-header" th:text="#{switchconf.tts.xf.header}"></div>
    <div id="baseConfigs"></div>

    <div class="row"></div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button id="saveConfig" type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i><span th:text="#{switchconf.btn.save}"></span></button>&nbsp;
        </div>
    </div>
</div>

<th:block th:include="include :: footer" />
<th:block th:include="include :: layout-latest-js" />
<script>
    var prefix = ctx + "cc/fsconf";
    $(function() {
        $.ajax({
            url: prefix + '/getXfTtsConf',
            type: 'GET',
            success: function(_data) {
                var baseConfigsHtml = '';
                var data = _data.data;

                $.each(data, function(index, config) {
                    baseConfigsHtml += '<div className="row">';
                    baseConfigsHtml += '<div class="col-sm-12">';
                    baseConfigsHtml += '<label class="col-sm-2 control-label">' + config.aliasName + '</label><div class="col-sm-10"><input class="config-value form-control" type="text" id="' + config.name + '" value="' + config.value + '" /></div>';
                    baseConfigsHtml += '</div>';
                    baseConfigsHtml += '</div>';
                });
                $('#baseConfigs').html(baseConfigsHtml);
            },
            error: function(error) {
                console.error('Error fetching configuration:', error);
            }
        });
    });

    $('#saveConfig').click(function() {
        var configs = [];
        $('input.config-value').each(function() {
            var config = {
                name: $(this).attr('id'),
                value: $(this).val().trim()
            };
            configs.push(config);
        });
        $.ajax({
            url: prefix + '/setXfTtsConf',
            type: 'POST',
            contentType: 'application/json',
            data: JSON.stringify(configs),
            beforeSend: function () {
                $.modal.loading(i18n("common.tip.loading"));
                $.modal.disable();
            },
            success: function(response) {
                processAjaxReponseJson(response);
            },
            error: function(error) {
            }
        });
    });

</script>

</body>
</html>
