{% extends base.html %}

{% block body_left %}

{% import web %}

<div class="col-md-12 card">
    {% include common/title/base_title.html %}
</div>

<div class="card">
    {% render system_sync_tab %}
</div>

<div class="card">
    {% render system_sync_info_list %}
</div>


{% if is_leader %}
    {% include system/page/system_sync_leader.html %}
{% end %}


{% if not is_leader %}
    {% include system/page/system_sync_follower_view.html %}
{% end %}

{% include system/page/system_sync_cluster_info.html %}

<script type="text/javascript">
$(function () {
    $(".config-btn").click(function (e) {
        var configKey = $(e.target).attr("data-key");
        var promptTitle = $(e.target).attr("data-title");
        var defaultValue = $(e.target).attr("data-default");
        xnote.prompt(promptTitle, defaultValue, function (inputValue) {
            var params = {};
            params.p = "set_config";
            params.key = configKey;
            params.value = inputValue;

            xnote.http.post("/system/sync", params, function (resp) {
                if (resp.code == "success") {
                    window.location.reload();
                } else {
                    xnote.alert(resp.message);
                }
            });
        });
    });

    $(".confirm-btn").click(function(e) {
        var configKey = $(e.target).attr("data-key");
        var promptTitle = $(e.target).attr("data-title");
        var defaultValue = $(e.target).attr("data-default");

        xnote.confirm(promptTitle, function (inputValue) {
            var params = {};
            params.p = "set_config";
            params.key = configKey;
            params.value = inputValue;

            xnote.http.post("/system/sync", params, function (resp) {
                if (resp.code == "success") {
                    window.location.reload();
                } else {
                    xnote.alert(resp.message);
                }
            });
        });
    });

    $(".refresh-btn").click(function(e) {
        xnote.http.get("/system/sync?p=ping", function (resp) {
            window.location.reload();
        });
    });

    $(".view-btn").click(function (e) {
        var value = $(e.target).attr("data-value");
        xnote.alert(value);
    });

    $(".view-ajax-btn").click(function (e) {
        var dataType = $(e.target).attr("data-type");
        var dataKey  = $(e.target).attr("data-key");
        var params = {type: dataType, key: dataKey};
        xnote.http.get("/system/sync?p=get_detail", params, function (resp) {
            xnote.showTextDialog("详情", resp.text);
        });
    });
});
</script>
{% end %}

{% block body_right %}
    {% include system/component/admin_nav.html %}
{% end %}
