mirror of
https://github.com/itflow-org/itflow
synced 2026-02-28 02:44:53 +00:00
[FEATURE] Added AI Rewording Functionality to Create Ticket, Ticket Reply, Create Document and Edit Document, more to come
This commit is contained in:
61
js/app.js
61
js/app.js
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user