degrade.hbs 8.45 KB
<style>
    .degrade-page {
        padding: 20px;
    }

    .server-in-use,
    .connect-err .server-name,
    .connect-err .fa {
        font-size: 24px;
        color: #a94442;
    }

    .ip-port-modify-btn {
        color: #999;
        text-decoration: underline;
        cursor: pointer;
        margin-left: 10px;
    }

    .degrade-tab li {
        cursor: pointer;
    }

    .pc-degrade,
    .wap-degrade {
        list-style: none;
        padding: 20px;
    }

    .err-tip {
        color: #a94442;
    }

    .refresh {
        float: right;
        cursor: pointer;
    }

    .config-panel .server-port {
        width: 100px;
    }

    .config-panel .form-inline {
        padding: 20px 0;
        border-bottom: 1px solid #d9edf7;
    }
</style>
<div class="degrade-page">
    <div class="panel panel-info">
        <div class="panel-heading">zookeeper configure</div>
        <div class="panel-body">
            <div class="row">
                <div class="col-md-6 config-panel" data-type="qcloud">
                    <div class="panel panel-success">
                        <div class="panel-heading">
                            腾讯云
                            <span class="refresh">
                                <i class="glyphicon glyphicon-refresh"></i>
                            </span>
                        </div>
                        <div class="panel-body">
                            {{# qCloudConfig}}
                            <div class="form-inline">
                                <div class="current-server{{#unless ip}} hide{{/unless}}">
                                    当前server地址:
                                    <span class="server-in-use" data-ip="{{ip}}" data-port="{{port}}">{{ip}}:{{port}}</span>
                                    <span class="ip-port-modify-btn">修改</span>
                                </div>
                                <div class="server-editor{{#if ip}} hide{{/if}}">
                                    <div class="form-group">
                                        <label>Server IP</label>
                                        <input class="form-control server-ip" type="text" value="{{ip}}">
                                    </div>
                                    <div class="form-group">
                                        <label for="server-port">Server Port</label>
                                        <input class="form-control server-port" type="text" value="{{port}}">
                                    </div>
                                    <span class="btn btn-default server-sure">保存</span>
                                </div>
                            </div>
                            {{/ qCloudConfig}}

                            <div class="panel-body list-container">
                                Waitting for connecting to server...
                            </div>
                        </div>
                    </div>
                </div>
{{!--                 <div class="col-md-6 config-panel" data-type="aws">
                    <div class="panel panel-warning">
                        <div class="panel-heading">
                            AWS
                            <span class="refresh">
                                <i class="glyphicon glyphicon-refresh"></i>
                            </span>
                        </div>
                        <div class="panel-body">
                            {{# awsConfig}}
                            <div class="form-inline">
                                <div class="current-server{{#unless ip}} hide{{/unless}}">
                                    当前server地址:
                                    <span class="server-in-use" data-ip="{{ip}}" data-port="{{port}}">{{ip}}:{{port}}</span>
                                    <span class="ip-port-modify-btn">修改</span>
                                </div>
                                <div class="server-editor{{#if ip}} hide{{/if}}">
                                    <div class="form-group">
                                        <label>Server IP</label>
                                        <input class="form-control server-ip" type="text" value="{{ip}}">
                                    </div>
                                    <div class="form-group">
                                        <label>Server Port</label>
                                        <input class="form-control server-port" type="text" value="{{port}}">
                                    </div>
                                    <span class="btn btn-default server-sure">保存</span>
                                </div>
                            </div>
                            {{/ awsConfig}}

                            <div class="panel-body list-container">
                                Waitting for connecting to server...
                            </div>
                        </div>
                    </div>
                </div> --}}
            </div>
        </div>
    </div>
</div>

<script>
    $(function() {

        $('.ip-port-modify-btn').click(function() {
            var $form = $(this).closest('.form-inline');

            $('.server-editor', $form).removeClass('hide');
            $('.current-server', $form).addClass('hide');
        });

        // server
        $('.server-sure').click(function() {
            var $panel = $(this).closest('.config-panel');

            var $ip = $('.server-ip', $panel);
            var $port = $('.server-port', $panel);

            var ip = $.trim($ip.val());
            var port = $.trim($port.val());

            $.ajax({
                type: 'POST',
                url: '/degrade/server',
                data: {
                    ip: ip,
                    port: port,
                    type: $panel.data('type')
                }
            }).then(function(data) {
                if (data.code === 200) {
                    //$.pjax.reload('#pjax-container');
                    $('.server-editor', $panel).addClass('hide');
                    $('.current-server', $panel).removeClass('hide');

                    $('.server-in-use', $panel).text(ip + ':' + port).data('ip', ip).data('port', port);

                    $('.list-container', $panel).html('waiting for connecting server...');
                }
            });
        });

        $('.list-container').on('click', '.degrade-tab li', function() {
            var $this = $(this);
            var $panel = $this.closest('.config-panel');

            if ($this.hasClass('active')) {
                return;
            }

            $this.parent().children('li').toggleClass('active');

            var index = $this.index();

            if (index === 0) {

                //PC active
                $('.pc-degrade', $panel).removeClass('hide');
                $('.wap-degrade', $panel).addClass('hide');
            } else {

                // wap active
                $('.wap-degrade', $panel).removeClass('hide');
                $('.pc-degrade', $panel).addClass('hide');
            }
        }).on('change', '.degrade-content input[type="checkbox"]', function() {
            var $checkbox = $(this),
                $li = $checkbox.closest('li');

            var checked = $checkbox.prop('checked');

            var id = $li.data('id');

            $.ajax({
                url: '/degrade/setter',
                data: {
                    checked: checked,
                    id: id,
                    type: $checkbox.closest('.config-panel').data('type')
                }
            }).then(function(data) {
                if (data.code !== 200) {
                    $checkbox.prop('checked', !checked);
                    alert(data.message);
                }
            });
        });

        $('.refresh').click(function() {
            var $panel = $(this).closest('.config-panel');

            $.ajax({
                type: 'GET',
                url: '/degrade/connect',
                data: {
                    ip: $('.server-in-use', $panel).data('ip'),
                    port: $('.server-in-use', $panel).data('port')
                }
            }).then(function(data) {
                $('.list-container', $panel).html(data);
            });
        })
    })
</script>