dolibarr 21.0.0-alpha
formlayoutai.tpl.php
1<?php
2/* Copyright (C) 2024 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * Need to have the following variables defined:
19 * $conf
20 * $formmail
21 * $formwebsite (optional)
22 * $showlinktolayout='emailing', 'email', 'websitepage', ...
23 * $showlinktolayoutlabel='...'
24 * $showlinktoai ('' or 'textgeneration', 'textgenerationemail', 'textgenerationwebpage', ...)
25 * $showlinktoailabel='...'
26 * $htmlname
27 */
28
29// Protection to avoid direct call of template
30if (empty($conf) || !is_object($conf)) {
31 print "Error, template page can't be called as URL";
32 exit(1);
33}
34
35if (empty($htmlname)) {
36 print 'Parameter htmlname not defined.';
37 exit(1);
38}
39
40?>
41<!-- BEGIN PHP TEMPLATE formlayoutai.tpl.php -->
42<?php
43
44'
45@phan-var-force ?FormWebSite $formwebsite
46@phan-var-force ?FormMail $formmail
47@phan-var-force string $showlinktolayout
48@phan-var-force string $showlinktolayoutlabel
49';
50
51if (!isset($out)) {
52 $out = '';
53}
54// Add link to add layout
55if ($showlinktolayout) {
56 $out .= '<a href="#" id="linkforlayouttemplates" class="notasortlink inline-block alink marginrightonly">';
57 $out .= img_picto($showlinktolayoutlabel, 'layout', 'class="paddingrightonly"');
58 $out .= $showlinktolayoutlabel.'...';
59 $out .= '</a> &nbsp; &nbsp; ';
60
61 $out .= '<script>
62 $(document).ready(function() {
63 $("#linkforlayouttemplates").click(function() {
64 console.log("We click on linkforlayouttemplates");
65 event.preventDefault();
66 jQuery("#template-selector").toggle();
67 jQuery("#ai_input'.$htmlname.'").hide();
68 jQuery("#pageContent").show(); // May exists for website page only
69 });
70 });
71 </script>
72 ';
73}
74// Add link to add AI content
75if ($showlinktoai) {
76 $out .= '<a href="#" id="linkforaiprompt'.$showlinktoai.'" class="notasortlink inline-block alink marginrightonly">';
77 $out .= img_picto($showlinktoailabel, 'ai', 'class="paddingrightonly"');
78 $out .= $showlinktoailabel.'...';
79 $out .= '</a>';
80
81 $out .= '<script>
82 $(document).ready(function() {
83 $("#linkforaiprompt'.$showlinktoai.'").click(function() {
84 console.log("formlayoutai.tpl: We click on linkforaiprompt'.$showlinktoai.', we toggle #ai_input'.$showlinktoai.'");
85 event.preventDefault();
86 jQuery("#ai_input'.$htmlname.'").toggle();
87 jQuery("#template-selector").hide();
88 jQuery(".email-layout-container").hide();
89 if (!jQuery("#ai_input'.$htmlname.'").is(":hidden")) {
90 console.log("Set focus on input field #ai_instructions'.$htmlname.'");
91 jQuery("#ai_instructions'.$htmlname.'").focus();
92 if (!jQuery("pageContent").is(":hidden")) { // May exists for website page only
93 jQuery("#pageContent").show();
94 }
95 }
96 });
97 });
98 </script>
99 ';
100}
101if ($showlinktolayout) {
102 if (!empty($formwebsite) && is_object($formwebsite)) {
103 $out .= $formwebsite->getContentPageTemplate($htmlname);
104 } else {
105 $out .= $formmail->getModelEmailTemplate($htmlname, $showlinktolayout);
106 }
107} else {
108 $out .= '<!-- No link to the layout feature, $formmail->withlayout must be set to a string use case, module WYSIWYG must be enabled and MAIN_EMAIL_USE_LAYOUT must be set -->';
109}
110if ($showlinktoai) {
111 $out .= $formmail->getSectionForAIPrompt($showlinktoai, $formmail->withaiprompt, $htmlname);
112} else {
113 $out .= '<!-- No link to the AI feature, $formmail->withaiprompt must be set to the ai feature and module ai must be enabled -->';
114}
115
116?>
117<!-- END PHP TEMPLATE commonfields_edit.tpl.php -->
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)