mirror of https://github.com/itflow-org/itflow
[FEATURE] Added AI Rewording Functionality to Create Ticket, Ticket Reply, Create Document and Edit Document, more to come
This commit is contained in:
parent
48ba4445bf
commit
ddb8061404
|
|
@ -15,10 +15,20 @@
|
|||
<input type="text" class="form-control" name="name" placeholder="Name" required autofocus>
|
||||
</div>
|
||||
|
||||
<?php if($config_ai_enable) { ?>
|
||||
<div class="form-group">
|
||||
<textarea class="form-control tinymceai" id="textInput" name="content"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<button id="rewordButton" class="btn btn-primary" type="button"><i class="fas fa-fw fa-robot mr-2"></i>Reword</button>
|
||||
<button id="undoButton" class="btn btn-secondary" type="button" style="display:none;"><i class="fas fa-fw fa-redo-alt mr-2"></i>Undo</button>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="form-group">
|
||||
<textarea class="form-control tinymce" name="content"></textarea>
|
||||
</div>
|
||||
|
||||
<?php } ?>
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
|
|
@ -59,4 +69,4 @@
|
|||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -18,9 +18,21 @@
|
|||
<input type="text" class="form-control" name="name" value="<?php echo $document_name; ?>" placeholder="Name" required>
|
||||
</div>
|
||||
|
||||
<?php if($config_ai_enable) { ?>
|
||||
<div class="form-group">
|
||||
<textarea class="form-control tinymceai" id="textInput" name="content"><?php echo $document_content; ?></textarea>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<button id="rewordButton" class="btn btn-primary" type="button"><i class="fas fa-fw fa-robot mr-2"></i>Reword</button>
|
||||
<button id="undoButton" class="btn btn-secondary" type="button" style="display:none;"><i class="fas fa-fw fa-redo-alt mr-2"></i>Undo</button>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="form-group">
|
||||
<textarea class="form-control tinymce" name="content"><?php echo $document_content; ?></textarea>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
|
|
|
|||
|
|
@ -33,4 +33,4 @@ document.getElementById('rewordButton').addEventListener('click', function() {
|
|||
rewordButton.disabled = false;
|
||||
rewordButton.innerText = 'Reword'; // Reset button text
|
||||
});
|
||||
});
|
||||
});
|
||||
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',
|
||||
|
|
|
|||
16
ticket.php
16
ticket.php
|
|
@ -303,7 +303,21 @@ if (isset($_GET['ticket_id'])) {
|
|||
<input type="hidden" name="ticket_id" id="ticket_id" value="<?php echo $ticket_id; ?>">
|
||||
<input type="hidden" name="client_id" id="client_id" value="<?php echo $client_id; ?>">
|
||||
<div class="form-group">
|
||||
<textarea class="form-control tinymce" name="ticket_reply" placeholder="Type a response"></textarea>
|
||||
<?php if($config_ai_enable) { ?>
|
||||
<div class="form-group">
|
||||
<textarea class="form-control tinymceai" id="textInput" name="ticket_reply" placeholder="Type a response"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<button id="rewordButton" class="btn btn-primary" type="button"><i class="fas fa-fw fa-robot mr-2"></i>Reword</button>
|
||||
<button id="undoButton" class="btn btn-secondary" type="button" style="display:none;"><i class="fas fa-fw fa-redo-alt mr-2"></i>Undo</button>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="form-group">
|
||||
<textarea class="form-control tinymce" name="ticket_reply" placeholder="Type a response"></textarea>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="col-md-2">
|
||||
|
|
|
|||
|
|
@ -44,9 +44,20 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<?php if($config_ai_enable) { ?>
|
||||
<div class="form-group">
|
||||
<textarea class="form-control tinymceai" id="textInput" name="details"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<button id="rewordButton" class="btn btn-primary" type="button"><i class="fas fa-fw fa-robot mr-2"></i>Reword</button>
|
||||
<button id="undoButton" class="btn btn-secondary" type="button" style="display:none;"><i class="fas fa-fw fa-redo-alt mr-2"></i>Undo</button>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="form-group">
|
||||
<textarea class="form-control tinymce" rows="5" name="details"></textarea>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (empty($_GET['client_id'])) { ?>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue