1jQuery(document).ready(function($) { 2/* Company */ 3$("#openModalBtn").on('click',function(e){ 4 e.preventDefault(); 5 $("#companyModal").fadeIn(); 6}); 7/* Work area */ 8$("#openModalBtn2").on('click',function(e){ 9 e.preventDefault(); 10 $("#workModal").fadeIn(); 11}); 12 13 14/* Close Modal */ 15 $('#closeModalBtn').click(function() { 16 $('#companyModal').fadeOut(); // Hide the modal 17 $('#company-form')[0].reset(); // Reset the form fields 18 $('#form-message').html(''); // Clear any messages 19 }); 20 21 $('#closeModalBtn2').click(function() { 22 $('#workModal').fadeOut(); // Hide the modal 23 $('#work-form')[0].reset(); // Reset the form fields 24 $('#form-message2').html(''); // Clear any messages 25 }); 26 27/* end close modal */ 28 29 /* Handle the Company form submission via AJAX */ 30 $('#company-form').submit(function(e) { 31 e.preventDefault(); // Prevent normal form submission 32 33 var companyName = $('#company_name').val(); // Get the company name 34 var companyDescription = $('#company_description').val(); // Get the optional description 35 var formMessage = $('#form-message'); 36 37 // Check if company name is empty 38 if (companyName === "") { 39 formMessage.html('<p style="color: red;">Please enter a company name.</p>'); 40 return; 41 } 42 43 /* Clear any previous messages */ 44 formMessage.html(''); 45 46 // Send the data via AJAX to admin-ajax.php 47 $.ajax({ 48 url: companyAjax.ajax_url, 49 method: 'POST', 50 data: { 51 action: 'add_company_term', // Action hook to handle the request 52 nonce: companyAjax.nonce, // Security nonce 53 company_name: companyName, // Company name to add 54 company_description: companyDescription // Description (optional) 55 }, 56 success: function(response) { 57 if (response.success) { 58 // Show success message 59 formMessage.html('<p style="color: green;">Company added successfully!</p>'); 60 61 // Refresh the checkbox list (by fetching new terms) 62 fetch_company_terms(); 63 64 // Close the modal after successful submission 65 $('#companyModal').fadeOut(); 66 67 // Reset the form fields when the modal is closed 68 $('#company-form')[0].reset(); 69 $('#form-message').html(''); // Clear any messages 70 } else { 71 // Show error message 72 formMessage.html('<p style="color: red;">' + response.data + '</p>'); 73 } 74 }, 75 error: function() { 76 formMessage.html('<p style="color: red;">An error occurred. Please try again.</p>'); 77 } 78 }); 79 }); /* end company submission */ 80 81 /* Handle the Work Area form submission via AJAX */ 82 $('#work-form').submit(function(e) { 83 e.preventDefault(); // Prevent normal form submission 84 85 var workName = $('#work_name').val(); // Get the work area name 86 var workDescription = $('#work_description').val(); // Get the optional description 87 var formMessage2 = $('#form-message2'); 88 89 // Check if company name is empty 90 if (workName === "") { 91 formMessage2.html('<p style="color: red;">Please enter a Work Area/Craft/Role name.</p>'); 92 return; 93 } 94 95 /* Clear any previous messages */ 96 formMessage2.html(''); 97 98 // Send the data via AJAX to admin-ajax.php 99 $.ajax({ 100 url: workAjax.ajax_url, 101 method: 'POST', 102 data: { 103 action: 'add_work_area_craft_role_term', // Action hook to handle the request 104 nonce: workAjax.nonce, // Security nonce 105 work_name: workName, // Company name to add 106 work_description: workDescription // Description (optional) 107 }, 108 success: function(response) { 109 if (response.success) { 110 // Show success message 111 formMessage2.html('<p style="color: green;">Work Area/Craft/Role added successfully!</p>'); 112 113 // Refresh the checkbox list (by fetching new terms) 114 fetch_work_area_craft_role_terms(); 115 116 // Close the modal after successful submission 117 $('#workModal').fadeOut(); 118 119 // Reset the form fields when the modal is closed 120 $('#work-form')[0].reset(); 121 $('#form-message2').html(''); // Clear any messages 122 } else { 123 // Show error message 124 formMessage2.html('<p style="color: red;">' + response.data + '</p>'); 125 } 126 }, 127 error: function() { 128 formMessage2.html('<p style="color: red;">An error occurred. Please try again.</p>'); 129 } 130 }); 131 }); /* end work area submission */ 132 133 134 135 136 /* Function to fetch and refresh the list of company terms (checkboxes) */ 137 function fetch_company_terms() { 138 $.ajax({ 139 url: companyAjax.ajax_url, 140 method: 'GET', 141 data: { 142 action: 'get_company_terms' // Action hook to fetch the terms 143 }, 144 success: function(response) { 145 if (response.success) { 146 // Replace the checkbox list with the updated list 147 $('#company-checkboxes').html(response.data); 148 } 149 }, 150 error: function() { 151 alert("Error fetching terms."); 152 } 153 }); 154 } /* End */ 155 156 /* Function to fetch and refresh the list of work area terms (checkboxes) */ 157 function fetch_work_area_craft_role_terms() { 158 $.ajax({ 159 url: companyAjax.ajax_url, 160 method: 'GET', 161 data: { 162 action: 'get_work_area_craft_role_terms' // Action hook to fetch the terms 163 }, 164 success: function(response) { 165 if (response.success) { 166 // Replace the checkbox list with the updated list 167 $('#work').html(response.data); 168 } 169 }, 170 error: function() { 171 alert("Error fetching terms."); 172 } 173 }); 174 } /* End */ 175 176 177}); // end jquery
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.