jQuery(document).ready(function($) { const selectButton = $('#mxchat-select-all-transcripts'); let isSelected = false; selectButton.click(function() { isSelected = !isSelected; $(this).toggleClass('selected'); // Update button text const buttonText = $(this).find('.button-text'); buttonText.text(isSelected ? 'Deselect All' : 'Select All'); // Update checkboxes $('#mxchat-transcripts').find('input[type=checkbox]').prop('checked', isSelected); }); // Search functionality $('#mxchat-search-transcripts').on('input', function() { var searchTerm = $(this).val().toLowerCase(); $('.mxchat-session').each(function() { var sessionText = $(this).text().toLowerCase(); $(this).toggle(sessionText.includes(searchTerm)); }); }); // Load transcripts $.ajax({ url: ajaxurl, type: 'POST', data: { action: 'mxchat_fetch_chat_history' }, success: function(response) { $('#mxchat-transcripts').html(response); } }); // Your existing delete form submission code remains the same $('#mxchat-delete-form').submit(function(e) { e.preventDefault(); var checkedSessionIds = $('input[name="delete_session_ids[]"]:checked').map(function() { return $(this).val(); }).get(); $.ajax({ url: ajaxurl, type: 'POST', data: { action: 'mxchat_delete_chat_history', delete_session_ids: checkedSessionIds, security: $('#mxchat_delete_chat_nonce').val() }, success: function(response) { var jsonResponse = JSON.parse(response); if (jsonResponse.success) { alert("Success: " + jsonResponse.success); } else if (jsonResponse.error) { alert("Error: " + jsonResponse.error); } else { //console.log("Unexpected response format."); } location.reload(); }, error: function(xhr, status, error) { //console.error("AJAX Error: " + status + " - " + error); //console.log(xhr.responseText); } }); }); });