HEX
Server: Apache
System: Linux srv13.cpanelhost.cl 3.10.0-962.3.2.lve1.5.38.el7.x86_64 #1 SMP Thu Jun 18 05:28:41 EDT 2020 x86_64
User: cca63905 (4205)
PHP: 7.3.20
Disabled: NONE
Upload Files
File: //proc/self/cwd/nueva/modules/roja45quotationsprofree/views/js/roja45quotationspro_summary.js
/**
 * roja45quotationspro_order.js.
 *
 * @author    Roja45
 * @copyright 2016 Roja45
 * @license   license.txt
 *
 * 2016 ROJA45 - All rights reserved.
 *
 * DISCLAIMER
 * Changing this file will render any support provided by us null and void.
 */

$(document).ready(function () {
    $(document.body).on('click', '.request-quotation', function (e) {
        e.preventDefault();
        if (roja45quotationspro_summary.processSend()) {
            roja45quotationspro_summary.submitForm();
        }
    });

    $(document).on('click', '.quote_quantity .quote_quantity_up', function(e) {
        roja45quotationspro_summary.updateQty($(this), 'up');
    });

    $(document).on('click', '.quote_quantity .quote_quantity_down', function(e) {
        roja45quotationspro_summary.updateQty($(this), 'down');
    });

    $(document).on('change', '.quote_quantity .quote_quantity_input ', function(e) {
        roja45quotationspro_summary.updateQty($(this), 'update');
    });
});

roja45quotationspro_summary = {
    processSend : function() {
        var url = $('#quotationspro_request_form').attr('action')
        var errors = 0;
        $('#quotationspro_request_form').find('input.validate', 'textarea.validate').each(function (index, value) {
            if ($(this).hasClass('is_required')) {
                var invalid = false;

                if ($(this).val().length == 0) {
                    invalid = true;
                } else if ($(this).attr('data-validate') != 'none') {
                    if ($(this).attr('name') == 'postcode' && typeof(countriesNeedZipCode[$('#id_country option:selected').val()]) != 'undefined')
                        var result = window['validate_' + $(this).attr('data-validate')]($(this).val(), countriesNeedZipCode[$('#id_country option:selected').val()]);
                    else
                        var result = window['validate_' + $(this).attr('data-validate')]($(this).val())
                    if (result) {
                        invalid = false;
                    } else {
                        invalid = true;
                    }
                }

                if (invalid) {
                    $(this).parent().addClass('form-error').removeClass('form-ok');
                    errors++;
                } else {
                    $(this).parent().removeClass('form-error').addClass('form-ok');
                }
            }
        });

        if (errors == 0) {
            return true;
        } else {
            return false;
        }
    },

    submitForm: function () {
        $('.btn.btn-default.request-quotation').prop('disabled', 'disabled').addClass('disabled');
        var request = {};
        request.columns = [];
        $('#quotationspro_request_form .quotationspro_request.column').each(function (i) {
            var column = {};
            var heading = $(this).find('.page-subheading').html();
            column.heading = heading;
            // column id
            var col = $(this).data('column');
            column.num = col;
            column.fields = [];

            $(this).find('.form-control').each(function (j) {
                var label = $(this).closest('.form-group').find('.control-label').html();
                var field = {};
                field.pos = j;
                field.name = $(this).attr('name');
                field.label = label.trim();
                field.value = $(this).val();
                column.fields[j] = field;
            });
            request.columns[i] = column;
        });
        var json = JSON.stringify(request);
        $('input[name=ROJA45QUOTATIONSPRO_FORMDATA]').val(json);
        $('#quotationspro_request_form').submit();
    },

    updateButtons: function (id_product) {
        var url = $('.request-quote').attr('href');
        $.ajax({
            url: url + '?submitUpdateSummaryButtons=1&id_product='+id_product+'&ajax=1',
            type: 'post',
            dataType: 'json',
            success: function (data) {
                if (data.result == 'success') {
                    roja45quotationsprofree.displaySuccessMsg(data.response);
                    if (data.enable == 0) {
                        $('.standard-checkout').show();
                        $('.request-quote').hide();
                    }
                } else if (data.result == 'error') {
                    $.each(data.errors, function (index, value) {
                        roja45quotationsprofree.displayErrorMsg(value);
                    });
                }
            },
            error: function (data) {
                roja45quotationsprofree.displayErrorMsg(roja45quotationspro_sent_failed);
            },
            complete: function (data) {
            }
        });
    },

    updateQty: function (ele, mode) {
        var url = $(ele).closest('.quote_quantity').attr('data-url');
        var qty = parseInt($(ele).closest('.quote_quantity').find('.quote_quantity_input').val());

        if (mode == 'up') {
            var qty = qty + 1;
        } else if (mode == 'down') {
            var qty = qty - 1;
        }
        if (qty != 0) {
            $(ele).closest('.quote_quantity').find('.quote_quantity_input').val(qty);
        }
    },
}