$(document).ready(function(){
    $('.modal').modal();
    $(".send-quote-price").on("click", function(){
        var quoteId = $(this).data("quote");
        var $modal = $("#modal-send-" + quoteId);
        var $adText = $modal.find("textarea");
        var adTextVal = $adText.val();

        if(adTextVal.length && quoteId){

            $(this).addClass("disabled").text("Asteptati...");

            $.ajax({
                url: "/quote/" + quoteId + "/update",
                method: "POST",
                data: {
                    adText: adTextVal
                },
                success: function(resp){
                    window.location.reload();
                },
                error: function(err) {
                }
            });
        }else{
            $adText.focus();
        }
    });

    $('.deny-quote').on("click", function(){
        var quoteId = $(this).data("quote");
        if(quoteId){

            $(this).addClass("disabled").text("Asteptati...");

            $.ajax({
                url: "/quote/" + quoteId + "/update",
                method: "POST",
                data: {
                    status: 7
                },
                success: function(resp){
                    window.location.reload();
                },
                error: function(err) {
                }
            });
        }
    });

    $('.accept-quote').on("click", function(){
        var quoteId = $(this).data("quote");
        if(quoteId){

            $(this).addClass("disabled").text("Asteptati...");

            $.ajax({
                url: "/quote/" + quoteId + "/update",
                method: "POST",
                data: {
                    status: 3
                },
                success: function(resp){
                    window.location.reload();
                },
                error: function(err) {
                }
            });
        }
    });

    $('.delete-quote').on("click", function(){
        var quoteId = $(this).data("quote");
        if(quoteId){

            $(this).addClass("disabled").text("Asteptati...");

            $.ajax({
                url: "/quotation/" + quoteId,
                data: {},
                method: 'DELETE',
                success: function(resp){
                    window.location.reload();
                }
            });
        }
    });

    $('.pay-quote').on('click', function(){
        $(this).next("form").submit();
    });

});
