diff --git a/htdocs/ai/ajax/generate_content.php b/htdocs/ai/ajax/generate_content.php index 371e039c173..bbc03fe15e8 100644 --- a/htdocs/ai/ajax/generate_content.php +++ b/htdocs/ai/ajax/generate_content.php @@ -79,7 +79,7 @@ $function = empty($jsonData['function']) ? 'textgeneration' : $jsonData['functio $instructions = dol_string_nohtmltag($jsonData['instructions'], 1, 'UTF-8'); $format = empty($jsonData['format']) ? '' : $jsonData['format']; // Can be '' for text, 'html', ... -if ($function == 'texttranslation') { +if ($function == 'texttranslation' && $format == "html") { $instructions = $jsonData['instructions']; } else { $instructions = dol_string_nohtmltag($jsonData['instructions'], 1, 'UTF-8'); @@ -100,7 +100,7 @@ if (is_null($generatedContent) || (is_array($generatedContent) && $generatedCont print "Error API returned no answer"; } } else { - if ($function == 'textgenerationemail' || $function == 'textgenerationwebpage' || $function == "texttranslation") { + if ($function == 'textgenerationemail' || $function == 'textgenerationwebpage') { print dolPrintHTML($generatedContent); // Note that common HTML tags are NOT escaped (but a sanitization is done) } elseif ($function == 'imagegeneration') { // TODO @@ -110,6 +110,10 @@ if (is_null($generatedContent) || (is_array($generatedContent) && $generatedCont // TODO } else { // Default case 'textgeneration' - print dolPrintText($generatedContent); // Note that common HTML tags are NOT escaped (but a sanitization is done) + if ($format == "html") { + print dolPrintHTML($generatedContent); // Note that common HTML tags are NOT escaped (but a sanitization is done) + } else { + print dolPrintText($generatedContent); // Note that common HTML tags are NOT escaped (but a sanitization is done) + } } } diff --git a/htdocs/core/tpl/formlayoutai.tpl.php b/htdocs/core/tpl/formlayoutai.tpl.php index e07896ea525..0291c49d20b 100644 --- a/htdocs/core/tpl/formlayoutai.tpl.php +++ b/htdocs/core/tpl/formlayoutai.tpl.php @@ -105,6 +105,14 @@ if ($showlinktoai) { } } }); + $(document).on("click", function (event) { + aidropdown = $(".ai_dropdown'.$htmlname.'"); + aidropdownbutton = $("#linkforaiprompt'.$showlinktoai.'"); + if (!aidropdown.is(event.target) && !aidropdownbutton.is(event.target) && $(event.target).closest(aidropdown).length === 0 && $(event.target).closest(aidropdownbutton).length === 0 && aidropdown.is(":visible")) { + console.log("You clicked outside of ai_dropdown - we close it"); + $(".ai_dropdown'.$htmlname.'").hide(); + } + }); }); ';