| 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 |
}); |
| 24 |
}); |
| 25 |
|
| 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 |
}); |
| 37 |
|
| 38 |
// Your existing delete form submission code remains the same |
| 39 |
$('#mxchat-delete-form').submit(function(e) { |
| 40 |
e.preventDefault(); |
| 41 |
var checkedSessionIds = $('input[name="delete_session_ids[]"]:checked').map(function() { |
| 42 |
return $(this).val(); |
| 43 |
}).get(); |
| 44 |
$.ajax({ |
| 45 |
url: ajaxurl, |
| 46 |
type: 'POST', |
| 47 |
data: { |
| 48 |
action: 'mxchat_delete_chat_history', |
| 49 |
delete_session_ids: checkedSessionIds, |
| 50 |
security: $('#mxchat_delete_chat_nonce').val() |
| 51 |
}, |
| 52 |
success: function(response) { |
| 53 |
var jsonResponse = JSON.parse(response); |
| 54 |
if (jsonResponse.success) { |
| 55 |
alert("Success: " + jsonResponse.success); |
| 56 |
} else if (jsonResponse.error) { |
| 57 |
alert("Error: " + jsonResponse.error); |
| 58 |
} else { |
| 59 |
//console.log("Unexpected response format."); |
| 60 |
} |
| 61 |
location.reload(); |
| 62 |
}, |
| 63 |
error: function(xhr, status, error) { |
| 64 |
//console.error("AJAX Error: " + status + " - " + error); |
| 65 |
//console.log(xhr.responseText); |
| 66 |
} |
| 67 |
}); |
| 68 |
}); |
| 69 |
}); |
| 70 |
|