j-r
4/9/2015 - 5:36 PM

BASK JS

$('.edit-options').on('click', function(e) {
    e.preventDefault();
    var productCode = $(this).attr('data-product'),
        qty = $(this).attr('data-quantity'),
        baskline = $(this).attr('data-basketline'),
        errors = 0,
        eoURl = location.protocol + '//' + location.host + '/mm5/merchant.mvc?Screen=PROD&Product_Code=' + productCode + '&qty=' + qty + '&baskline=' + baskline + '&editoptions=1';

        $.get(eoURl, function(data) {
            $('#options-modal .modal-content').html(data);
        }).done(function() {
            $('#options-modal').modal('show');
            $('#change-options').on('click', function(e) {
                $(this).html('Processing');
                $(this).attr('disabled', 'disabled');

                var cform = $('#purchase-form'),
                    cformData = cform.serialize(),
                    cformUrl = cform.attr('action'),
                    cformMethod = cform.attr('method'),
                    responseMsg = $('#ajax-message');

                $.ajax({
                    url: cformUrl + '&request=AJAX',
                    type: cformMethod,
                    data: cformData,
                    success: function(data, textStatus, jqXHR) {
                        if (data.search(/id="BASK"/i) != -1) {						
                            // Re-Initialize Attribute Machine (if it is active)
                            if (typeof attrMachCall !== 'undefined') {
                                attrMachCall.Initialize();
                            };
                        } else if(data.search(/id="JS_PLMT"/i) != -1) {
                            responseMsg.html('We do not have enough of the Size/Color you have selected. Please review your options.').fadeIn().delay(3000).fadeOut();
                            errors = 1;
                        } else if(data.search(/id="JS_POUT"/i) != -1) {
                            responseMsg.html('The Size/Color you have selected is out of stock. Please review your options or check back later.').fadeIn().delay(3000).fadeOut(); 
                            errors = 1;
                        } else {
                            responseMsg.html('Unable to add to cart. Please review options.').fadeIn().delay(3000).fadeOut();
                            errors = 1;
                        };
                        cform.data('formstatus', 'idle');
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        console.log(errorThrown);
                    }
                }).done(function() {
                    if (errors == 1) {
                        $('#change-options').html('Change Options');
                        $('#change-options').removeAttr('disabled');
                    } else {
                        $('#remove-form').submit();
                    }
                });
        });
    }); 
});