$( function () { console.log('running?'); var $bmc = $('#baseMainContent'); function handleContactFormValidate() { $('#dhProjectTitle, #dhDescription, #dhFirstName, #dhLastName, #dhNewRequestEmail, #dhExistingRequestEmail, #dhCompany, #dhPhone, #dhRequestID, #tos').tooltipster({ trigger: 'custom', onlyOne: false, position: 'right', theme: 'tooltipster-errortip' }); $('#dhNewRequestEmail, #dhExistingRequestEmail, #dhRequestID').on('keyup', function () { $this = $(this); if ($this.val() !== $this.val().trim()) { $this.val($this.val().trim()).change(); } }); var jqvDefaultOptions = { debug: true, errorPlacement: function (err, elt) { var lastError = $(elt).data('lastError'), newError = $(err).text(); $(elt).data('lastError', newError); if (newError !== '' && newError !== lastError) { $(elt).tooltipster('content', $('
').append($('
').text(newError))); $(elt).tooltipster('show'); } }, submitHandler: function () {return false;}, success: function (label, elt) { ; //$(elt).tooltipster('hide'); } }; $.validator.setDefaults(jqvDefaultOptions); var jqvNewRequestOptions = { ignore: '.ignore', submitHandler: onCreateQuote, rules: { title: { required: true, minlength: 2, }, description: { required: true, minlength: 20, }, first: { required: true, minlength: 2, lettersonly: true }, last: { required: true, minlength: 2, lettersonly: true }, company: { minlength: 2 }, email: { required: true, email: false, strict_email: true }, phone: { required: false, phoneUS: true }, tos: { tosAgreement: true } } }; $('#quoteForm').validate(jqvNewRequestOptions); var jqvExistingRequestOptions = { rules: { existing_email: { required: true, email: false, strict_email: true }, request_id: { required: true, minlength: 32, maxlength: 32 } } }; $('#dhExistingRequestForm').validate(jqvExistingRequestOptions); } handleContactFormValidate(); function handleCreateQuote (result) { if (result.status === 'error') { $('#quoteForm').validate(validationOptions); $('#createQuoteBtn').prop('disabled', false); } else if (result.status === 'success') { window.location.href = '/viewer'; } else { window.location.href = '/'; } } function onCreateQuote (form) { $('#createQuoteBtn').prop('disabled', false); var $form = $('#quoteForm'); $('#ref_file').attr('disabled', true).fileupload('disable'); var $this = $('#createQuoteBtn'); $this.css('position', 'relative'); $this.attr('disabled', true).addClass('btn-inverted').text('Creating Quote...'); $this.spindicator(); file_list = []; $('.quote-file').each( function () { var file_data = $(this).data('file_data'); if (file_data) { file_data.description = $(this).find('.quote-file-description').val(); file_list.push(file_data); } }); var creatingQuote = $.post('/quote', {action: 'create', 'file_list': JSON.stringify(file_list), formData: $form.serialize()}); creatingQuote.done( handleCreateQuote ); } $bmc.on('click', '#submitProjectReviewRequest', function () { console.log('click?'); $('#quoteRequestErrorMsg').remove(); if ($('#firstName').val() == '' || $('#lastName').val() == '' || $('#email').val() == '') { $('.btn-box-atc').append($('')); } else { $('#submitProjectReviewRequest').text(''); $('#submitProjectReviewRequest').spindicator(); var adding = _handleCreateQuote(); adding.done( function (data) { if (data === 'success') { window.location.href = '/thank-you'; } }); } }); var _handleCreateQuote = function () { var quoteFormData = { first : $('#firstName').val(), last : $('#lastName').val(), email : $('#email').val(), pagetype : $('#pagetype').val(), }; console.log('quote form data: '); console.log(quoteFormData); var addingToCart = new $.Deferred(); var convertToCart = $.post('/contact-form', {action: 'createSEOContact', formData: JSON.stringify(quoteFormData)}); convertToCart.done( function() { addingToCart.resolve('success'); }); return addingToCart; }; if (typeof String.prototype.endsWith !== 'function') { String.prototype.endsWith = function(suffix) { return this.indexOf(suffix, this.length - suffix.length) !== -1; }; } });