Feature: Allow AI to Generate Document Templates with a prompt example Generate AD Structure Documentation, File Share etc

This commit is contained in:
johnnyq
2024-12-10 15:47:12 -05:00
parent 1e05c7d524
commit bb6a1c3cc7
3 changed files with 100 additions and 0 deletions

View File

@@ -135,3 +135,36 @@
<?php include "admin_document_template_add_modal.php"; ?>
<?php include "footer.php"; ?>
<script>
$(document).ready(function(){
$('#generateAIContent').on('click', function(){
var prompt = $('#aiPrompt').val().trim();
if(prompt === '') {
alert('Please enter a prompt.');
return;
}
$('#generateAIContent').prop('disabled', true).html('<i class="fa fa-spinner fa-spin"></i> Generating...');
$.ajax({
url: 'post.php?ai_create_document_template', // The PHP script that calls the OpenAI API
method: 'POST',
data: { prompt: prompt },
dataType: 'html',
success: function(response) {
// Assuming you have exactly one TinyMCE instance on the page
// and it's targeting the .tinymce textarea:
tinymce.activeEditor.setContent(response);
},
error: function() {
alert('Error generating content. Please try again.');
},
complete: function() {
$('#generateAIContent').prop('disabled', false).html('<i class="fa fa-fw fa-magic mr-1"></i>Generate with AI');
}
});
});
});
</script>