1// Get the modal 2 3var modal = document.getElementById("SalesAgentModal"); 4 5// Get the button that opens the modal 6var btn = document.getElementById("myBtn"); 7 8jQuery( document ).ready( 9 function ($) { 10 var $loader = jQuery('<div class="wc-sales-agent-loader"></div>'); 11 12 if (document.getElementById('expiry_date')) { 13 // Get the current date 14 var currentDate = new Date().toISOString().split('T')[0]; 15 16 // Set the minimum date for the expiry_date input 17 document.getElementById('expiry_date').min = currentDate; 18 } 19 jQuery('.delete-coupon-btn').on('click', function(e) { 20 e.preventDefault(); 21 jQuery('#error_message').text(''); 22 var ajax_url = jQuery(this).data('ajax_url'); 23 jQuery('#coupon_message').text(''); 24 var coupon_id = jQuery(this).data('id'); 25 var nonce = jQuery('#agent_coupon_nonce').val(); 26 27 // Append loader to the table container 28 jQuery('#coupon_table_container').append($loader); 29 $loader.show(); 30 31 // Make the AJAX request 32 jQuery.ajax({ 33 url: ajax_url, 34 type: 'POST', 35 data: { 36 action: 'wc_agent_discount_endpoint_delete', 37 data: { 38 coupon_id: coupon_id, 39 nonce: nonce, 40 }, 41 }, 42 success: function(response) { 43 // Hide and remove the loader 44 $loader.hide().remove(); 45 46 // Handle the response from the server 47 if (response.success == false) { 48 // Display the error message to the user 49 jQuery("#coupon_discount").focus(); 50 jQuery("#coupon_discount").css("border-color", "red"); 51 jQuery('#error_message').text(response.data); 52 } else { 53 jQuery("#coupon_discount").css("border-color", ""); 54 jQuery('#error_message').hide(); 55 console.log(response.data); 56 jQuery('#coupon_message').text(response.data.message); 57 setTimeout(function() { 58 location.reload(); 59 }, 2000); 60 } 61 }, 62 error: function(xhr, status, error) { 63 // Hide and remove the loader 64 $loader.hide().remove(); 65 66 // Handle errors 67 var errorMessage = xhr.responseJSON.data; 68 // Display the error message to the user 69 jQuery('#error_message').text(errorMessage); 70 } 71 }); 72 }); 73 jQuery(document).on('click', '.update_coupon', function(e) { 74 e.preventDefault(); 75 jQuery('#error_message').text(''); 76 var ajax_url = jQuery(this).data('ajax_url'); 77 jQuery('#coupon_submission_form').append($loader); 78 $loader.show(); 79 80 var coupon_id = jQuery(this).data('id'); 81 var maxDiscountValue = parseInt(jQuery('#max_agent_discount').val()); // Get value from hidden field 82 83 // Prepare form data 84 var formData = { 85 coupon_id: coupon_id, 86 coupon_code: jQuery('#coupon_code').val(), 87 coupon_discount: jQuery('#coupon_discount').val(), 88 usage_limit: jQuery('#usage_limit').val(), 89 total_spending_min: jQuery('#total_spending_min').val(), 90 total_spending_max: jQuery('#total_spending_max').val(), 91 expiry_date: jQuery('#expiry_date').val(), 92 agent_max_discount: maxDiscountValue, 93 nonce: jQuery('#agent_coupon_create_nonce').val(), 94 }; 95 96 // Make the AJAX request 97 jQuery.ajax({ 98 url: ajax_url, 99 type: 'POST', 100 data: { 101 action: 'wc_agent_discount_endpoint_update', 102 data: formData 103 }, 104 success: function(response) { 105 $loader.hide().remove(); 106 // Handle the response from the server 107 if (response.success == false) { 108 // Display the error message to the user 109 jQuery("#coupon_discount").focus(); 110 jQuery("#coupon_discount").css("border-color", "red"); 111 jQuery('#error_message').text(response.data); 112 } else { 113 jQuery("#coupon_discount").css("border-color", ""); 114 jQuery('#error_message').hide(); 115 console.log(response.data); 116 jQuery('#coupon_created').text(response.data); 117 setTimeout(function() { 118 location.reload(); 119 }, 2000); 120 } 121 }, 122 error: function(xhr, status, error) { 123 $loader.hide().remove(); 124 // Handle errors 125 var errorMessage = xhr.responseJSON?.data || 'An error occurred.'; 126 jQuery('#error_message').text(errorMessage); 127 } 128 }); 129 }); 130 jQuery('.edit-coupon-btn').on('click', function(e) { 131 jQuery('#error_message').text(''); 132 var ajax_url = jQuery(this).data('ajax_url'); 133 e.preventDefault(); 134 jQuery('#coupon_table_container').append($loader); 135 $loader.show(); 136 137 jQuery('#coupon_created').text(''); 138 var coupon_id = jQuery(this).data('id'); 139 var nonce = jQuery( '#agent_coupon_nonce' ).val(); 140 // Make the AJAX request 141 jQuery.ajax({ 142 url: ajax_url, 143 type: 'POST', 144 data: { 145 action: 'wc_agent_discount_endpoint_edit', 146 data: { 147 coupon_id: coupon_id, 148 nonce: nonce, 149 }, 150 }, 151 success: function(response) { 152 $loader.hide().remove(); 153 // Handle the response from the server 154 if(response.success) { 155 // Refill the form fields with the returned data 156 jQuery('#submit_coupon').hide(); 157 if (jQuery('.update_coupon').length < 1) { 158 // If the button does not exist, create it 159 jQuery('#expiry_date').closest('.form-group').after('<button id="update_coupon" class="update_coupon" style="background-color: #7D3C98; color: white; padding: 8px 20px; border: none; border-radius: 4px; cursor: pointer; width: 27%;" onmouseover="this.style.backgroundColor=\'#B997DC\'" onmouseout="this.style.backgroundColor=\'#7C35C3\'" data-id="' + response.data.coupon_id + '"data-ajax_url="'+ response.data.ajax_url + '">Update</button>'); 160 } else { 161 // If the button exists, remove the existing button and create a new one 162 jQuery('.update_coupon').remove(); 163 jQuery('#expiry_date').closest('.form-group').after('<button id="update_coupon" class="update_coupon" style="background-color: #7D3C98; color: white; padding: 8px 20px; border: none; border-radius: 4px; cursor: pointer; width: 27%;" onmouseover="this.style.backgroundColor=\'#B997DC\'" onmouseout="this.style.backgroundColor=\'#7C35C3\'" data-id="' + response.data.coupon_id + '"data-ajax_url="'+ response.data.ajax_url + '">Update</button>'); 164 } 165 166 jQuery('#coupon_code').val(response.data.post_title); 167 jQuery('#coupon_discount').val(response.data.coupon_discount); 168 jQuery('#usage_limit').val(response.data.coupon_usage_limit); 169 jQuery('#total_spending_min').val(response.data.coupon_minimum_amount); 170 jQuery('#total_spending_max').val(response.data.coupon_maximum_amount); 171 jQuery('#expiry_date').val(response.data.coupon_expiry_date); 172 } else { 173 // Handle if the request was not successful 174 } 175 }, 176 error: function(xhr, status, error) { 177 $loader.hide().remove(); 178 // Handle errors 179 var errorMessage = xhr.responseJSON.data; 180 // Display the error message to the user 181 } 182 }); 183 }); 184 jQuery('#submit_coupon').on('click', function(e) { 185 jQuery('#error_message').text(''); 186 ajax_url= $(this).data('ajax_url'); 187 e.preventDefault(); 188 var maxDiscountMessage = $('#max_discount_message'); 189 jQuery('#coupon_submission_form').append($loader); 190 $loader.show();
191 var maxDiscountValue = parseInt(jQuery('#max_agent_discount').val()); // Get value from hidden field 192 // Validate the max discount value 193 194 console.log(maxDiscountValue); 195 var formData = { 196 coupon_code: jQuery('#coupon_code').val(), 197 coupon_discount: jQuery('#coupon_discount').val(), 198 usage_limit: jQuery('#usage_limit').val(), 199 total_spending_min: jQuery('#total_spending_min').val(), 200 total_spending_max: jQuery('#total_spending_max').val(), 201 expiry_date: jQuery('#expiry_date').val(), 202 agent_max_discount: maxDiscountValue, 203 nonce: jQuery( '#agent_coupon_create_nonce' ).val(), 204 }; 205 jQuery.ajax({ 206 url: ajax_url, 207 type: 'POST', 208 data: { 209 action: 'wc_agent_discount_endpoint', 210 data: formData, 211 }, 212 success: function(response) { 213 $loader.hide().remove(); 214 // Handle the response from the server 215 if(response.success == false){ 216 // Display the error message to the user 217 jQuery("#coupon_discount").focus(); 218 jQuery("#coupon_discount").css("border-color", "red"); 219 jQuery('#error_message').text(response.data); 220 }else{ 221 $("#coupon_discount").css("border-color", ""); 222 jQuery('#error_message').hide(); 223 console.log(response); 224 jQuery('#coupon_created').text(response); 225 setTimeout(function() { 226 location.reload(); 227 }, 2000); 228 } 229 }, 230 error: function(xhr, status, error) { 231 $loader.hide().remove(); 232 // Handle errors 233 var errorMessage = xhr.responseJSON.data; 234 // Display the error message to the user 235 jQuery('#error_message').text(errorMessage); 236 } 237 }); 238 }); 239// My account page String translation 240 $('.filter-actions').on('click', '.select2-selection__rendered', function(e) { 241 console.log(i18n_placeholder.search_placeholder); 242 $('.select2-results__option.select2-results__message').text(i18n_placeholder.search_placeholder); 243 }); 244 245// Modal close when window click. 246 $('.configure-setup').click(function() { 247 $("#SalesAgentModal").css('display','block'); 248 $('body').css('overflow', 'hidden'); 249 }); 250// Modal cose when close button click. 251 $(".close").click(function() { 252 $("#SalesAgentModal").css('display','none'); 253 }); 254 255 256// Click Payment option field are show. 257 $('.payment-opt:checked', function() { 258 var payment_option = $('.payment-opt:checked').val(); 259 $('.'+payment_option+'-info').show().nextAll().hide(); 260 $('.payment-info-submit').show(); 261 }); 262 263// When payment option click field are show. 264 $('.paypal-info').hide(); 265 $('.bank-info').hide(); 266 $('.payoneer-info').hide(); 267 268 $('.payment-opt').click(function() { 269 var payment_option = $(this).val(); 270 $('.payment-info').children().hide(); 271 $('.'+payment_option+'-info').show().nextAll().hide(); 272 $('.payment-info-submit').show(); 273 }); 274 //Clear cart on cart sharing menu 275 $('#cart-clear').click(function(e) { 276 e.preventDefault(); 277 278 $.ajax({ 279 url: ajax.ajax_url, 280 type: 'POST', 281 data: { 282 action: 'clear_cart', 283 nonce: ajax.nonce 284 }, 285 success: function(response) { 286 if (response.success) { 287 $('#cart_name').val(''); 288 alert('Cart has been cleared.'); 289 location.reload(); 290 } else { 291 alert('Failed to clear the cart. Please try again.'); 292 } 293 }, 294 error: function(xhr, status, error) { 295 console.error('AJAX Error:', error); 296 alert('An error occurred while trying to clear the cart.'); 297 } 298 }); 299 }); 300 // Cart name create on cart sharing menu 301 $('#cart-create').click(function(e) { 302 e.preventDefault() 303 304 305 306 var cartname = $(this).parent().find('#cart_name').val(); 307 308 if($('#cart_name').val() != '') { 309 jQuery.ajax({ 310 url: ajax.ajax_url, 311 type: "POST", 312 data: { 313 'action': 'create_agent_cart', 314 'cart_name': cartname 315 }, 316 success: function(reponse){ 317 console.log(reponse); 318 }, 319 error: function (errormessage) { 320 console.log(errormessage); 321 } 322 }); 323 $('.agent_dashboard_msg.user_cart_msg').removeClass('alert_cart_msg'); 324 $('.agent_dashboard_msg.user_cart_msg').addClass('woocommerce-message'); 325 $('.user_cart_msg p').text('Cart has been created'); 326 $('.user_cart_msg').show(); 327 $('.card_save_msg').hide(); 328 setTimeout(function() { 329 location.reload(); 330 }, 2000); 331 }else{ 332 $('.agent_dashboard_msg.user_cart_msg').addClass('alert_cart_msg'); 333 $('.agent_dashboard_msg.user_cart_msg').addClass('woocommerce-error'); 334 $('.agent_dashboard_msg.user_cart_msg').removeClass('woocommerce-message'); 335 $('.user_cart_msg p').text('Enter a Cart Name'); 336 $('.user_cart_msg').show(); 337 } 338 339 340 341 342 }); 343 344 jQuery(document).on( 'click', '.admin_agent_announcement .close', function (e) { 345 e.preventDefault(); 346 jQuery(this).parents('.admin_agent_announcement').css('display', 'none'); 347 $('body').css('overflow', 'scroll'); 348 }); 349 350 // Announcement Modal close 351 $('body').click(function(event) { 352 if ($(event.target).is('.admin_agent_announcement')) { 353 $(".admin_agent_announcement").hide(); 354 $('body').css('overflow', 'scroll'); 355 } 356 }); 357 358 // Announcement Modal Ajax pass 359 jQuery('.admin_announcement').click(function(e) { 360 e.preventDefault(); 361 var data = { 362 action: 'show_anouncement_by_id', 363 post_id: jQuery(this).data('id'), 364 announcement_nonce: ajax.nonce 365 }; 366 367 jQuery.ajax({ 368 url: ajax.ajax_url, 369 type: 'POST', 370 dataType: 'HTML', 371 data: data, 372 success: function ( response ) { 373 if ( response != '' ) { 374 jQuery('.admin_agent_announcement .modal
374-content').html( response ); 375 jQuery('.admin_agent_announcement').css('display','block'); 376 jQuery('.admin_announcement').next().remove(); 377 jQuery('body').css('overflow', 'hidden'); 378 } 379 } 380 381 }); 382 }); 383 384 385 386 387 388 $('.copy_action').click(function(e) { 389 e.preventDefault() 390 $(this).parent().siblings(".woocommerce-orders-table__cart_link").find('.cart_link').select(); 391 document.execCommand("copy"); 392 }); 393 394 395 $('.delete_action').click(function(e) { 396 e.preventDefault() 397 var user_card_id = $(this).attr('href'); 398 399 jQuery.ajax({ 400 url: ajax.ajax_url, 401 type: "POST", 402 data: { 403 'action': 'delete_agent_cart', 404 'cart_id': user_card_id 405 }, 406 success: function(reponse){ 407 location.reload(); 408 }, 409 error: function (errormessage) { 410 console.log(errormessage); 411 } 412 }); 413 414 }); 415 416 $( '.agent-order-view-popup' ).click( function(e) { 417 e.preventDefault(); 418 _this = jQuery(this); 419 _this.attr( 'disabled', true ); 420 _this.text('loading...'); 421 var order_id = $(this).data('id'), 422 ajax_url = $(this).data('ajax'), 423 nonce = $(this).data('token'); 424 $('body').css('overflow', 'hidden'); 425 jQuery.ajax({ 426 url: ajax_url, 427 type: "POST", 428 data: { 429 'action': 'agent_dashboard_view_details', 430 'order_id': order_id, 431 'nonce': nonce 432 }, 433 success: function(reponse){ 434 $( ".agent-order-detail-overlay" ).css({ 'visibility' : 'visible', 'opacity' : '1', 'z-index' : 99 }) 435 $('#agent-order-detail-popup').html(reponse); 436 _this.attr( 'disabled', false ); 437 _this.text('View'); 438 439 }, 440 error: function (errormessage) { 441 console.log(errormessage); 442 } 443 }); 444 445 }); 446 447 $( document ).on('click', '.close', function(e){ 448 e.preventDefault(); 449 $('body').css('overflow', 'auto'); 450 $( ".agent-order-detail-overlay" ).css({ 'visibility' : 'hidden', 'opacity' : '0', 'z-index' : 0 }); 451 }); 452 453 } 454);
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.