1jQuery(document).ready(function($) { 2 3 function isValidationCheckFailed() { 4 return $('#submittal-emails').val().length < 5 || $('.js-cover-letter.is-invalid').length > 0; 5 } 6 function isSubmitAllowed() { 7 return !isValidationCheckFailed() && grecaptcha.getResponse(); 8 } 9 window.handleRecaptchaSuccess = function() { 10 $('.js-send-submittal-email').prop( 11 'disabled', isValidationCheckFailed()); 12 } 13 14 const displayNotification = function(message, place, fadeOut = 3000, type = 'success') { 15 const classes = { 16 'success': 'woocommerce-message', 17 'error': 'woocommerce-error' 18 }; 19 20 let notification = $( 21 `<div class="woocommerce-notices-wrapper"> 22 <div class="${classes[type]}" role="alert">${message}</div> 23 </div>` 24 ); 25 26 $(place).first().prepend(notification); 27 28 if (fadeOut) { 29 setTimeout(function() { 30 notification.fadeOut('slow', function() { 31 $(this).remove(); 32 }); 33 }, fadeOut); 34 } 35 } 36 37 const hideNotification = function() { 38 $('.woocommerce-notices-wrapper').remove(); 39 } 40 41 const productPageContainer = '#main-content .inner'; 42 const submittalPageContainer = '#main .container'; 43 44 $('#submittal-button').click(function(event) { 45 event.preventDefault(); 46 let that = $(this); 47 48 if (that.data('action') == 'add') { 49 let data = { 50 'action': 'add_to_submittal', 51 'product_id': that.data('product-id') 52 }; 53 54 $.post(SubmittalData.ajaxUrl, data, function(response) { 55 that.data('action', 'remove').text('Remove from submittal'); 56 displayNotification('Product added to submittal list', productPageContainer); 57 }).fail(function(response) { 58 if (response.status == 409) { 59 that.data('action', 'remove').text('Remove from submittal'); 60 displayNotification('Product is already in submittal list', productPageContainer); 61 } 62 }); 63 } else { 64 let data = { 65 'action': 'remove_from_submittal', 66 'product_id': that.data('product-id') 67 }; 68 69 $.post(SubmittalData.ajaxUrl, data, function(response) { 70 that.data('action', 'add').text('Add to submittal'); 71 displayNotification('Product removed from submittal list', productPageContainer); 72 }); 73 } 74 }); 75 76 $('.js-remove-from-submittal-page').click(function(event) { 77 event.preventDefault(); 78 let that = $(this); 79 80 let data = { 81 'action': 'remove_from_submittal', 82 'product_id': that.data('product-id') 83 }; 84 85 let message = 'Product ' + that.data('product-title') + ' removed from submittal list'; 86 displayNotification(message, submittalPageContainer); 87 88 $.post(SubmittalData.ajaxUrl, data, function(response) { // @TODO add checking response 89 that.closest('.row').remove(); 90 91 // change value of total products counter 92 let counter = $('#products-counter'); 93 let totalProducts = counter.data('total'); 94 counter.data('total', totalProducts - 1); 95 counter.text(totalProducts - 1); 96 97 // show/hide empty submittal placeholder 98 if (counter.data('total') == 0) { 99 $('#empty-submittal, #main-submittal').toggleClass('d-none'); 100 } 101 }); 102 103 }); 104 105 $('.js-send-submittal-email').click(function(event) { 106 event.preventDefault(); 107 108 let data = { 109 'action': 'send_submittal_email', 110 'emails': $('#submittal-emails').val(), 111 'coverLetter': { 112 'include': $('#include-cover-letter').prop('checked'), 113 'date': $('#cover-letter-date').val(), 114 'projectName': $('#cover-letter-project-name').val(), 115 'generalContractor': $('#cover-letter-general-contractor').val(), 116 'electricalContractor': $('#cover-letter-electrical-contractor').val(), 117 'engineer': $('#cover-letter-engineer').val(),
118 'salesContact': $('#cover-letter-sales-contact').val() 119 } 120 }; 121 122 $.post(SubmittalData.ajaxUrl, data, function(response) { 123 window.location.href = SubmittalData.specificationPageUrl; 124 }).fail(function(response) { 125 displayNotification( 126 response.responseJSON.data || 'Something went wrong', 127 submittalPageContainer, 128 5000, 129 'error' 130 ); 131 }); 132 }); 133 134 $('#include-cover-letter').on('change', function() { 135 $('#cover-letter-fields').toggleClass('d-none'); 136 }); 137 138 $('#submittal-emails').on('input', function() { 139 $('.js-send-submittal-email').prop( 140 'disabled', !isSubmitAllowed() 141 ); 142 }); 143 144 $('#submittal-title').on('input', function() { 145 let isInvalid = $(this).val().length > 255; 146 147 $('#add-submittal').prop( 148 'disabled', 149 $(this).val().length === 0 || isInvalid 150 ); 151 152 $(this).toggleClass('is-invalid', isInvalid); 153 $('#title-validation-feedback').toggleClass('d-block', isInvalid); 154 }); 155 156 $('.js-cover-letter').on('input', function() { 157 let isInvalid = $(this).val().length > 255; 158 $(this).toggleClass('is-invalid', isInvalid); 159 $('.js-send-submittal-email').prop( 160 'disabled', 161 !isSubmitAllowed() 162 ); 163 }); 164 165 $('#submittals-list').on('change', function() { 166 let data = { 167 'action': 'set_submittal', 168 'id': $(this).val() 169 }; 170 171 $.post(SubmittalData.ajaxUrl, data, function(response) { 172 location.reload(); 173 }); 174 175 displayNotification( 176 'Switching to ' + $('#submittals-list option:selected').text() + ' submittal...', 177 submittalPageContainer, 178 false 179 ); 180 }); 181 182 $('#add-submittal').click(function(event) { 183 event.preventDefault(); 184 185 let data = { 186 'action': 'create_submittal', 187 'title': $('#submittal-title').val() 188 }; 189 190 $.post(SubmittalData.ajaxUrl, data, function(response) { 191 location.reload(); 192 }).fail(function(response) { 193 hideNotification(); 194 displayNotification( 195 response.responseJSON.data || 'Something went wrong', 196 submittalPageContainer, 197 5000, 198 'error' 199 ); 200 }); 201 202 displayNotification( 203 'New submittal ' + data.title + ' is creating...', 204 submittalPageContainer, 205 false 206 ); 207 }); 208 209 $('#remove-submittal').click(function(event) { 210 event.preventDefault(); 211 $(this).prop('disabled', true); 212 213 let data = { 214 'action': 'remove_submittal' 215 }; 216 217 $.post(SubmittalData.ajaxUrl, data, function(response) { 218 location.reload(); 219 }); 220 }); 221});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.