[FEATURE] Added AI Rewording Functionality to Create Ticket, Ticket Reply, Create Document and Edit Document, more to come

This commit is contained in:
johnnyq
2024-02-11 00:13:10 -05:00
parent 48ba4445bf
commit ddb8061404
6 changed files with 112 additions and 4 deletions

View File

@@ -42,6 +42,67 @@ tinymce.init({
plugins: 'link image lists table code codesample fullscreen autoresize',
});
// Initialize TinyMCE AI
tinymce.init({
selector: '.tinymceai',
browser_spellcheck: true,
contextmenu: false,
resize: true,
min_height: 300,
max_height: 600,
promotion: false,
branding: false,
menubar: false,
statusbar: false,
toolbar: [
'styles bold italic forecolor bullist numlist alignleft aligncenter alignright alignjustify outdent indent table code fullscreen'
],
mobile: {
menubar: false,
toolbar: 'bold italic styles'
},
plugins: 'link image lists table code codesample fullscreen autoresize',
setup: function(editor) {
var previousContent = ''; // Initialize previousContent outside the event listener
document.getElementById('rewordButton').addEventListener('click', function() {
var content = editor.getContent();
previousContent = content; // Store the current content before rewording
var rewordButton = document.getElementById('rewordButton');
var undoButton = document.getElementById('undoButton');
// Disable the Reword button and show loading state
rewordButton.disabled = true;
rewordButton.innerText = 'Processing...';
fetch('post.php?ai_reword', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ text: content }),
})
.then(response => response.json())
.then(data => {
editor.setContent(data.rewordedText || 'Error: Could not reword the text.');
rewordButton.disabled = false;
rewordButton.innerText = 'Reword'; // Reset button text
undoButton.style.display = 'inline'; // Show the Undo button
})
.catch(error => {
console.error('Error:', error);
rewordButton.disabled = false;
rewordButton.innerText = 'Reword'; // Reset button text
});
// Setup the Undo button click event only once, not every time the reword button is clicked
undoButton.onclick = function() {
editor.setContent(previousContent);
this.style.display = 'none'; // Hide the Undo button again
};
});
}
});
// Initialize TinyMCE
tinymce.init({
selector: '.tinymcePreview',