$(document).ready(function () {
    var app = {
        methods: {
            setLoading: function (load) {
                if (load) {
                    $('#loadingModal').modal({backdrop: 'static', keyboard: false});
                } else {
                    $('#loadingModal').hide();
                }
            },
            sync: function () {
                app.methods.setLoading(true);
                $.ajax({
                    url: 'mgm/addrbook/sync',
                    method: 'POST',
                    success: function (content) {
                        app.methods.setLoading(false);
                        if (content.success) {
                            alert('同步成功');
                        } else {
                            alert(content.message);
                        }
                    }
                });
            }
        },
        init: function () {
            $('.btn-primary').click(function () {
                app.methods.sync();
            });
        }
    };

    app.init();
});