$(document).ready(function () {
    var app = {
        methods: {
            get: function () {
                $.ajax({
                    url: 'mgm/dc',
                    method: 'GET',
                    success: function (content) {
                        if (content.success) {
                            var data = content.data;
                            $('#urlInput').val(data.url);
                            $('#usernameInput').val(data.username);
                            $('#passwordInput').val(data.password);
                            $('#outerUrlInput').val(data.outerUrl);
                        } else {
                            alert(content.message);
                        }
                    }
                });
            },
            save: function () {
                $.ajax({
                    url: 'mgm/dc',
                    method: 'POST',
                    data: $('#form').serialize(),
                    success: function (content) {
                        if (content.success) {
                            alert('保存成功');
                            window.location.reload();
                        } else {
                            alert(content.message);
                        }
                    }
                });
            }
        },
        init: function () {
            $('.btn-save').click(function(){
                app.methods.save();
            });

            app.methods.get();
        }
    };

    app.init();
});