| @@ -1,43 +1,24 @@ | ||
| 1 | - jQuery(document).ready(function($) { | |
| 2 | - const selectButton = $('#mxchat-select-all-transcripts'); | |
| 3 | - let isSelected = false; | |
| 4 | - | |
| 5 | - selectButton.click(function() { | |
| 6 | - isSelected = !isSelected; | |
| 7 | - $(this).toggleClass('selected'); | |
| 8 | - | |
| 9 | - // Update button text | |
| 10 | - const buttonText = $(this).find('.button-text'); | |
| 11 | - buttonText.text(isSelected ? 'Deselect All' : 'Select All'); | |
| 12 | - | |
| 13 | - // Update checkboxes | |
| 14 | - $('#mxchat-transcripts').find('input[type=checkbox]').prop('checked', isSelected); | |
| 15 | - }); | |
| 16 | - | |
| 17 | - // Search functionality | |
| 18 | - $('#mxchat-search-transcripts').on('input', function() { | |
| 19 | - var searchTerm = $(this).val().toLowerCase(); | |
| 20 | - $('.mxchat-session').each(function() { | |
| 21 | - var sessionText = $(this).text().toLowerCase(); | |
| 22 | - $(this).toggle(sessionText.includes(searchTerm)); | |
| 23 | - }); | |
| 1 | +jQuery(document).ready(function($) { | |
| 2 | + $('#mxchat-select-all-transcripts').click(function() { | |
| 3 | + var checkedStatus = this.checked; | |
| 4 | + $('#mxchat-transcripts').find('input[type=checkbox]').each(function() { | |
| 5 | + $(this).prop('checked', checkedStatus); | |
| 24 | 6 | }); |
| 7 | + }); | |
| 25 | 8 | |
| 26 | - // Load transcripts | |
| 27 | - $.ajax({ | |
| 28 | - url: ajaxurl, | |
| 29 | - type: 'POST', | |
| 30 | - data: { | |
| 31 | - action: 'mxchat_fetch_chat_history' | |
| 32 | - }, | |
| 33 | - success: function(response) { | |
| 34 | - $('#mxchat-transcripts').html(response); | |
| 35 | - } | |
| 36 | - }); | |
| 9 | + $.ajax({ | |
| 10 | + url: ajaxurl, | |
| 11 | + type: 'POST', | |
| 12 | + data: { | |
| 13 | + action: 'mxchat_fetch_chat_history' | |
| 14 | + }, | |
| 15 | + success: function(response) { | |
| 16 | + $('#mxchat-transcripts').html(response); | |
| 17 | + } | |
| 18 | + }); | |
| 37 | 19 | |
| 38 | - // Your existing delete form submission code remains the same | |
| 39 | - $('#mxchat-delete-form').submit(function(e) { | |
| 20 | + $('#mxchat-delete-form').submit(function(e) { | |
| 40 | 21 | e.preventDefault(); |
| 41 | 22 | var checkedSessionIds = $('input[name="delete_session_ids[]"]:checked').map(function() { |
| 42 | 23 | return $(this).val(); |
| 43 | 24 | }).get(); |
| @@ -65,41 +46,5 @@ | ||
| 65 | 46 | //console.log(xhr.responseText); |
| 66 | 47 | } |
| 67 | 48 | }); |
| 68 | 49 | }); |
| 69 | - | |
| 70 | - | |
| 71 | - | |
| 72 | - | |
| 73 | - // Export functionality | |
| 74 | - $('#mxchat-export-transcripts').on('click', function() { | |
| 75 | - var $button = $(this); | |
| 76 | - $button.prop('disabled', true).addClass('loading'); | |
| 77 | - | |
| 78 | - // Create a form and submit it (this way handles large datasets better than AJAX) | |
| 79 | - var $form = $('<form>', { | |
| 80 | - 'method': 'post', | |
| 81 | - 'action': ajaxurl | |
| 82 | - }); | |
| 83 | - | |
| 84 | - $form.append($('<input>', { | |
| 85 | - 'type': 'hidden', | |
| 86 | - 'name': 'action', | |
| 87 | - 'value': 'mxchat_export_transcripts' | |
| 88 | - })); | |
| 89 | - | |
| 90 | - $form.append($('<input>', { | |
| 91 | - 'type': 'hidden', | |
| 92 | - 'name': 'security', | |
| 93 | - 'value': mxchatAdmin.export_nonce | |
| 94 | - })); | |
| 95 | - | |
| 96 | - $form.appendTo('body').submit(); | |
| 97 | - | |
| 98 | - // Re-enable the button after a short delay | |
| 99 | - setTimeout(function() { | |
| 100 | - $button.prop('disabled', false).removeClass('loading'); | |
| 101 | - }, 2000); | |
| 102 | - }); | |
| 103 | - | |
| 104 | - | |
| 105 | 50 | }); |