$(document).ready(function(){

    $('.wrapp-button').on('click', function(){
        var $this = $(this);
        //var form = $(this).parent().parent()[0].querySelector('form');
        var form = $(this).parent('form')[0];
        var formData = new FormData(form);
        var redirect;

        if ($this.eq(0).hasClass("reset")) {
            var redirectUrl = $this.eq(0).data("url");
            redirect = function () {
                document.location.href = redirectUrl;
            };

            setTimeout(
                function () {
                    $("main").animate({
                        opacity: 0
                    }, 500);
                    setTimeout(redirect, 500);
                },
                1000
            );
        } else {
            $.ajax({
                url: $(form).attr("data-url"),
                type: "POST",
                contentType: false,
                processData: false,
                data: formData,
                successUrl: form.getAttribute("data-url-success"),
                fadePanel: $this,
                success: function(data) {
                    if (data.result) {
                        console.log(data);
                      
                        $.showMessage('info', $this.data('action'));
                        setTimeout(function(){
                            document.location.reload();
                        }, 1000);                        
                    } else {
                        console.log(data);
                    }
                },
                error: function (e) {
                    console.log('error: ', e);
                }
            });
        }

        return false;
    });

    
});