1jQuery(document).ready(function ($) { 2 $('.select2-multiple').select2(); 3 4$('input[type="file"]').on('change', function() { 5 const maxSize = parseInt($(this).data('maxSize')); 6 const file = this.files[0]; 7 8 if (file) { 9 if (file.size > maxSize) { 10 alert('File size exceeds the maximum allowed size'); 11 $(this).val(''); 12 } 13 } 14}); 15 16 $('#apply_on_forms').on('change', function() { 17 var selectedValue = $(this).val(); 18 var rolesRow = $('.user-roles-forms'); 19 20 if (selectedValue === 'specific_roles') { 21 rolesRow.show(); 22 } else { 23 rolesRow.hide(); 24 } 25}); 26 27 28$('#apply_on_forms').trigger('change'); 29 30$(".add-to-quote-button").on("click", function () { 31 let productId = $(this).data("product-id"); 32 let ruleId = $(this).data("rule-id"); 33 let variationId = $('input[name="variation_id"]').val(); 34 35 $(this).addClass("loading").prop("disabled", true); 36 37 $.ajax({ 38 url: localizedData.ajaxUrl, 39 type: "POST", 40 data: { 41 action: "add_to_quote", 42 product_id: productId, 43 variation_id: variationId, 44 rule_id: ruleId, 45 }, 46 success: function (response) { 47 $(".add-to-quote-button") 48 .removeClass("loading") 49 .prop("disabled", false); 50 window.location.reload(); 51 }, 52 error: function () { 53 $(".add-to-quote-button") 54 .removeClass("loading") 55 .prop("disabled", false); 56 window.location.reload(); 57 }, 58 }); 59}); 60 61 62 function updateSubtotals() { 63 $(".quote-item").each(function () { 64 const $row = $(this); 65 const quantity = parseFloat($row.find(".product-quantity input").val()) || 1; 66 const offeredPrice = parseFloat($row.find(".product-offered-price input").val()) || 0; 67 const subtotal = offeredPrice > 0 ? offeredPrice * quantity : 0; 68 }); 69} 70 71$(".product-quantity input, .product-offered-price input").on("input", function () { 72 updateSubtotals(); 73}); 74 75updateSubtotals(); 76 77$(".ext-update-quote").on("click", function (e) { 78 e.preventDefault(); 79 const quoteItems = []; 80 81 $(".quote-item").each(function () { 82 const $row = $(this); 83 const productId = $row.data('product-id'); 84 const variationId = $row.data('variation-id'); 85 const quantity = parseFloat($row.find(".product-quantity input").val()) || 1; 86 const offeredPrice = parseFloat($row.find(".product-offered-price input").val()) || 0; 87 88 quoteItems.push({ 89 product_id: productId, 90 variation_id:variationId, 91 quantity: quantity, 92 offered_price: offeredPrice 93 }); 94 }); 95 96 $(this).addClass("loading").prop("disabled", true); 97 98 $.ajax({ 99 url: localizedData.ajaxUrl, 100 type: "POST", 101 data: { 102 action: "update_quote", 103 quote_items: quoteItems 104 }, 105 success: function (response) { 106 // console.log(response); 107 $(".ext-update-quote") 108 .removeClass("loading") 109 .prop("disabled", false); 110 window.location.reload(); 111 }, 112 error: function () { 113 $(".ext-update-quote") 114 .removeClass("loading") 115 .prop("disabled", false); 116 window.location.reload();x 117 } 118 }); 119}); 120}); 121 122 123jQuery(document).ready(function($) { 124 125 $('.woocommerce-button.button.view.ext_raq').on('click', function(e) { 126 e.preventDefault(); 127 var quoteId = $(this).data('quote-id'); 128 $('#quote-id-display').text('Quote ID: ' + quoteId); 129 $('#quote-popup').fadeIn(); 130 }); 131 132 $('.close-popup').on('click', function() { 133 $('#quote-popup').fadeOut(); 134 }); 135 136 $(window).on('click', function(e) { 137 if ($(e.target).is('#quote-popup')) { 138 $('#quote-popup').fadeOut(); 139 } 140 }); 141 142 $('.woocommerce-button.button.view.ext_raq').on('click', function(e) { 143 e.preventDefault(); 144 var quoteId = $(this).data('quote-id'); 145 $.ajax({ 146 url: localizedData.ajaxUrl, 147 type: 'POST', 148 data: { 149 action: 'get_quote_details', 150 quote_id: quoteId, 151 }, 152 success: function(response) { 153 if (response.success) { 154 window.quote_fields = response.data.quote_fields; 155 populatePopup(response.data.quote); 156 $('#quote-popup').fadeIn(); 157 } 158 } 159 }); 160 161 }); 162 163 function populatePopup(quote) { 164 const currencySymbol = jQuery('.quote-products-table').data('currency'); 165 166 jQuery('.quote-title').text('Quote Request #' + quote.id); 167 jQuery('.quote-products-table tbody').empty(); 168 jQuery('.custom-fields-table tbody').empty(); 169 170 let total = 0;
171 quote.items.forEach(function(item) { 172 const subtotal = (parseFloat(item.offered_price) || 0) * item.quantity; 173 total += subtotal; 174 175 jQuery('.quote-products-table tbody').append(` 176 <tr> 177 <td>${item.product_id}</td> 178 <td>${item.quantity}</td> 179 <td>${currencySymbol}${(parseFloat(item.product_price) || 0)}</td> 180 <td>${currencySymbol}${(parseFloat(item.offered_price) || 0)}</td> 181 <td>${currencySymbol}${formatPrice(subtotal)}</td> 182 </tr> 183 `); 184 }); 185 186 jQuery('.quote-total').text(currencySymbol + formatPrice(total)); 187 188 if (quote.custom_fields) { 189 Object.entries(quote.custom_fields).forEach(([field_name, value]) => { 190 const matchingField = quote_fields.find(field => field.field_name === field_name); 191 let fieldLabel = matchingField ? matchingField.title : formatFieldLabel(field_name); 192 if (field_name.includes('attachment_id')) { 193 fieldLabel = 'Attachment ID'; 194 } 195 196 jQuery('.custom-fields-table tbody').append(` 197 <tr> 198 <th>${fieldLabel}</th> 199 <td>${value}</td> 200 </tr> 201 `); 202 }); 203 } 204 } 205 206 207 function formatPrice(price) { 208 return parseFloat(price).toFixed(2); 209 } 210 211 function formatFieldLabel(key) { 212 return key.replace('field_', '').replace(/_/g, ' ').replace(/(\w+)/g, 213 function(_, word) { 214 return word.charAt(0).toUpperCase() + word.slice(1); 215 } 216 ); 217 } 218 219 $('.close-popup').on('click', function() { 220 $('#quote-popup').fadeOut(); 221 }); 222 223 $(window).on('click', function(e) { 224 if ($(e.target).is('#quote-popup')) { 225 $('#quote-popup').fadeOut(); 226 } 227 }); 228 229 230 231 $('.convert-order').on('click', function (e) { 232 e.preventDefault(); 233 const quoteId = $(this).closest('tr').find('td:first').text().replace('#', ''); 234 $.ajax({ 235 url: localizedData.ajaxUrl, 236 type: 'POST', 237 data: { 238 action: 'convert_quote_to_order_front', 239 quote_id: quoteId 240 }, 241 success: function (response) { 242 if (response.success) { 243 window.location.href = response.data.redirect; 244 } else { 245 alert('Failed to convert quote. Please try again.'); 246 } 247 } 248 }); 249}); 250 251 252// $('.variations_form').on('show_variation', function(event, variation) { 253// $('.add-to-quote-button').removeClass('disabled').prop('disabled', false); 254// }); 255 256// $('.variations_form').on('hide_variation', function() { 257// $('.add-to-quote-button').addClass('disabled').prop('disabled', true); 258// }); 259 260 261$('.variations_form').on('show_variation', function(event, variation) { 262 $('.woocommerce-variation-add-to-cart, .add-to-quote-button').removeClass('disabled').prop('disabled', false); 263}); 264 265$('.variations_form').on('hide_variation', function() { 266 $('.woocommerce-variation-add-to-cart, .add-to-quote-button').addClass('disabled').prop('disabled', true); 267}); 268 269 270 271 272$('.add-to-quote-button').each(function() { 273 const hoverBg = $(this).attr('data-hover-background'); 274 const hoverColor = $(this).attr('data-hover-color'); 275 276 $(this).css('--hover-bg', hoverBg); 277 $(this).css('--hover-color', hoverColor); 278}); 279 280}); 281
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.