// jQuery(document).ready(function($) { // // Function to handle the close button click // function setupCloseButton() { // $('#close-popup').on('click', function() { // $('#edit-schedule-popup').fadeOut(); // }); // } // // Function to handle the form submission // function setupFormSubmission() { // $('#edit-schedule-form').on('submit', function(e) { // e.preventDefault(); // Prevent the default form submission // var postData = $(this).serialize(); // Serialize the form data // // Send the form data to the server for saving // $.ajax({ // type: 'POST', // url: my_ajax_object.ajax_url, // data: postData + '&action=update_schedule_post_data', // Include the action to update post data // success: function(response) { // if (response.success) { // alert('Post updated successfully!'); // $('#edit-schedule-popup').fadeOut(); // Close the popup // location.reload(); // Optional: reload the page to see changes // } else { // alert('Error updating the post.'); // } // }, // error: function() { // alert('An error occurred while saving the data.'); // } // }); // }); // } // // Function to handle opening the popup and filling the form with AJAX data // $('.edit-post-button').on('click', function() { // var postId = $(this).data('post-id'); // Get the post ID from the button // // Fetch the post data via AJAX // $.ajax({ // type: 'GET', // url: my_ajax_object.ajax_url, // data: { // action: 'get_schedule_post_data', // post_id: postId // }, // success: function(response) { // if (response.success) { // // Populate the form fields with the post data // $('#last_name').val(response.data.last_name).trigger('change'); // $('#gender').val(response.data.gender).trigger('change'); // $('#played_age_range').val(response.data.played_age_range).trigger('change'); // $('#introduction_video').val(response.data.introduction_video).trigger('change'); // $('#showreel').val(response.data.showreel).trigger('change'); // $('#email').val(response.data.email).trigger('change'); // $('#phone_number').val(response.data.phone_number).trigger('change'); // $('#date_of_birth').val(response.data.date_of_birth).trigger('change'); // $('#place_of_birth').val(response.data.place_of_birth).trigger('change'); // $('#location').val(response.data.location).trigger('change'); // $('#height').val(response.data.height).trigger('change'); // $('#eye__color').val(response.data.eye__color).trigger('change'); // $('#hair_color').val(response.data.hair_color).trigger('change'); // $('#hair_length').val(response.data.hair_length).trigger('change'); // $('#beard_type').val(response.data.beard_type).trigger('change'); // $('#languages_spoken').val(response.data.languages_spoken).trigger('change'); // $('#accent').val(response.data.accent).trigger('change'); // $('#athletic_skills').val(response.data.athletic_skills).trigger('change'); // $('#musical_instrument').val(response.data.musical_instrument).trigger('change'); // $('#performance_skill').val(response.data.performance_skill).trigger('change'); // $('#dance_style').val(response.data.dance_style).trigger('change'); // $('#race_ethnicity').val(response.data.race_ethnicity).trigger('change'); // $('#available_voluntarily_except_for_ads').val(response.data.available_voluntarily_except_for_ads).trigger('change'); // $('#availability').val(response.data.availability).trigger('change'); // // Show the popup // $('#edit-schedule-popup').fadeIn(); // $('.popup-modal').css('display', 'flex'); // // Now, setup event listeners for the close button and form submission (since they're now part of the DOM) // setupCloseButton(); // setupFormSubmission(); // } // } // }); // }); // // Mutation Observer to observe changes in the DOM and apply event listeners // const observer = new MutationObserver(function(mutations) { // mutations.forEach(function(mutation) { // mutation.addedNodes.forEach(function(node) { // // If the popup form has been added, apply event listeners // if ($(node).is('#edit-schedule-popup')) { // setupCloseButton(); // setupFormSubmission(); // } // }); // }); // }); // // Observe changes in the body (or any parent element) to detect when the popup is added // observer.observe(document.body, { // childList: true, // subtree: true // }); // });