dolibarr 25.0.0-alpha
lib_foot.js.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 * or see https://www.gnu.org/
19 */
20
26if (!defined('NOREQUIRESOC')) {
27 define('NOREQUIRESOC', '1');
28}
29if (!defined('NOCSRFCHECK')) {
30 define('NOCSRFCHECK', 1);
31}
32if (!defined('NOTOKENRENEWAL')) {
33 define('NOTOKENRENEWAL', 1);
34}
35if (!defined('NOLOGIN')) {
36 define('NOLOGIN', 1);
37}
38if (!defined('NOREQUIREMENU')) {
39 define('NOREQUIREMENU', 1);
40}
41if (!defined('NOREQUIREHTML')) {
42 define('NOREQUIREHTML', 1);
43}
44if (!defined('NOREQUIREAJAX')) {
45 define('NOREQUIREAJAX', '1');
46}
47
48session_cache_limiter('public');
49
50require_once '../../main.inc.php';
57/*
58 * View
59 */
60
61// Define javascript type
62top_httphead('text/javascript; charset=UTF-8');
63// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
64header('Cache-Control: max-age=10800, public, must-revalidate');
65
66
67$jsConst = [
68 'DOL_URL_ROOT' => DOL_URL_ROOT,
69 'classfortooltiponclicktextWidth' => ($conf->browser->layout == 'phone' ? max((empty($_SESSION['dol_screenwidth']) ? 0 : $_SESSION['dol_screenwidth']) - 20, 320) : 700),
70 'dol_no_mouse_hover' => !empty($conf->dol_no_mouse_hover)
71];
72
73
74include __DIR__ . '/lib_initTooltips.js';
75
76?>
77
78// Wrapper to show tooltips (html or onclick popup)
79/* JS CODE TO ENABLE Tooltips on all object with class classfortooltip */
80jQuery(function() {
81
82 const footerConst = <?php print json_encode($jsConst); ?>;
83
84
85 if(!footerConst.dol_no_mouse_hover) {
86 // --------------------------------
87 // Initial page load
88 // --------------------------------
89 initTooltips(document.body); // initialize all tooltips on page load
90 initAjaxTooltips(document.body, footerConst.DOL_URL_ROOT); // initialize all AJAX tooltips on page load
91
92
93 // --------------------------------
94 // Dynamic reload via Dolibarr hook
95 // --------------------------------
96 if (typeof Dolibarr !== "undefined" && Dolibarr.on) {
97 // Because Dolibarr context isn't in all Dolibarr page and lib_foot.js.php can be loaded everywhere
98 // it useful to check Dolibarr context is loaded before but we are already in a jQuery(function() so event Dolibarr:Ready can't be used here
99 Dolibarr.on('initNewContent', ({targets}) => {
100 targets.forEach(container => {
101 initTooltips(container);
102 initAjaxTooltips(container, footerConst.DOL_URL_ROOT);
103 })
104 });
105 };
106 }
107
108 // --------------------------------
109 // Initial page load
110 // --------------------------------
111 jQuery(function() {
112 initTooltipDialogs(document.body);
113 });
114
115 // --------------------------------
116 // Dynamic reload via Dolibarr hook
117 // --------------------------------
118
119 if (typeof Dolibarr !== "undefined" && Dolibarr.on) {
120 // Because Dolibarr context isn't in all Dolibarr page and lib_foot.js.php can be loaded everywhere
121 // it useful to check Dolibarr context is loaded before but we are already in a jQuery(function() so event Dolibarr:Ready can't be used here
122 Dolibarr.on('initNewContent', ({ targets }) => {
123 targets.forEach(container => initTooltipDialogs(container, footerConst.classfortooltiponclicktextWidth));
124 });
125 };
126
127});
128
129
130<?php
131// Wrapper to manage dropdown
132if (!defined('JS_JQUERY_DISABLE_DROPDOWN')) {
133 print "\n/* JS CODE TO ENABLE dropdown (hamburger, linkto, ...) */\n";
134 print ' jQuery(document).ready(function () {
135 var lastopendropdown = null;
136
137 // Click onto the link "link to" or "hamburger", toggle dropdown
138 $(document).on(\'click\', \'.dropdown dt a\', function () {
139 console.log("toggle dropdown dt a");
140
141 //$(this).parent().parent().find(\'dd ul\').slideToggle(\'fast\');
142 $(".ulselectedfields").removeClass("open");
143 $(this).parent().parent().find(\'dd ul\').toggleClass("open");
144
145 if ($(this).parent().parent().find(\'dd ul\').hasClass("open")) {
146 lastopendropdown = $(this).parent().parent().find(\'dd ul\');
147 //console.log(lastopendropdown);
148 } else {
149 // We closed the dropdown for hamburger selectfields
150 if ($("input:hidden[name=formfilteraction]").val() == "listafterchangingselectedfields") {
151 console.log("resubmit the form saved into lastopendropdown after clicking on hamburger");
152 //$(".dropdown dt a").parents(\'form:first\').submit();
153 //$(".dropdown dt a").closest("form").submit();
154 lastopendropdown.closest("form").submit();
155 }
156 }
157
158 // Note: Did not find a way to get exact height (value is update at exit) so i calculate a generic from nb of lines
159 heigthofcontent = 21 * $(this).parent().parent().find(\'dd div ul li\').length;
160 if (heigthofcontent > 300) heigthofcontent = 300; // limited by max-height on css .dropdown dd ul
161 posbottom = $(this).parent().parent().find(\'dd\').offset().top + heigthofcontent + 8;
162 var scrollBottom = $(window).scrollTop() + $(window).height();
163 diffoutsidebottom = (posbottom - scrollBottom);
164 console.log("heigthofcontent="+heigthofcontent+", diffoutsidebottom (posbottom="+posbottom+" - scrollBottom="+scrollBottom+") = "+diffoutsidebottom);
165 if (diffoutsidebottom > 0)
166 {
167 pix = "-"+(diffoutsidebottom+8)+"px";
168 console.log("We reposition top by "+pix);
169 $(this).parent().parent().find(\'dd\').css("top", pix);
170 }
171 });
172
173 // Click on a link into the popup "link to" or other dropdown that ask to close drop down on element click, so close dropdown
174 $(".dropdowncloseonclick").on(\'click\', function () {
175 console.log("Link has class dropdowncloseonclick, so we close/hide the popup ul");
176 //$(this).parent().parent().hide(); // $(this).parent().parent() is ul
177 $(this).parent().parent().removeClass("open"); // $(this).parent().parent() is ul
178 });
179
180 // Click outside of any dropdown
181 $(document).bind(\'click\', function (e) {
182 var $clicked = $(e.target); // This is element we click on
183 if (!$clicked.parents().hasClass("dropdown")) {
184 //console.log("close dropdown dd ul - we click outside");
185 //$(".dropdown dd ul").hide();
186 $(".dropdown dd ul").removeClass("open");
187
188 if ($("input:hidden[name=formfilteraction]").val() == "listafterchangingselectedfields") {
189 console.log("resubmit form saved into lastopendropdown after clicking outside of dropdown and having change selectlist from selectlist field of hamburger dropdown");
190 //$(".dropdown dt a").parents(\'form:first\').submit();
191 //$(".dropdown dt a").closest("form").submit();
192 lastopendropdown.closest("form").submit();
193 }
194 }
195 });
196 });
197 ';
198}
199
200// Wrapper to manage document_preview
201if ($conf->browser->layout != 'phone') {
202 print "\n/* JS CODE TO ENABLE document_preview */\n"; // Function document_preview is into header
203 print ' jQuery(document).ready(function () {
204 // Click on the preview picto
205 jQuery(".documentpreview").click(function () {
206 console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
207 var titledocpreview = $(this).attr(\'data-title\');
208 if (titledocpreview == undefined || titledocpreview == "") {
209 titledocpreview = \''.dol_escape_js($langs->transnoentities("Preview")).'\'
210 }
211 document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), titledocpreview);
212 return false;
213 });
214 });'."\n";
215}
216
217// Code to manage reposition
218print "\n/* JS CODE TO ENABLE reposition management (does not work if a redirect is done after action of submission) */\n";
219print '
220 jQuery(document).ready(function() {
221 /* If page_y set, we set scrollbar with it */
222 page_y = getParameterByName("page_y", 0); /* search in GET parameter */
223 if (page_y == 0) page_y = jQuery("#page_y").text(); /* search in POST parameter that is filed at bottom of page */
224 if (page_y > 0) {
225 console.log("page_y found is "+page_y);
226 jQuery("html, body").scrollTop(page_y);
227 }
228
229 /* Set handler to add page_y param on output (click on href links or submit button) */
230 jQuery(".reposition").click(function(event) {
231 var page_y = jQuery(document).scrollTop();
232 if (page_y > 0) {
233 if (this.href) {
234 console.log("We click on tag with .reposition class. this.ref was "+this.href);
235 var url = new URL(this.href, window.location.origin);
236 url.searchParams.delete("page_y"); /* remove page_y param if already present */
237 url.searchParams.set("page_y", page_y);
238 this.href = url.toString();
239 console.log("We click on tag with .reposition class. this.ref is now "+this.href);
240 } else {
241 console.log("We click on tag with .reposition class but element is not an <a> html tag, so we try to update input form field with name=page_y with value "+page_y);
242 jQuery("input[type=hidden][name=page_y]").val(page_y);
243 }
244 }
245 });
246 });
247' . "\n";
248
249// Code to disable submit buttons once form is submitted
250print "\n/* JS CODE TO DISABLE buttons with class disableonsubmit once form is submitted, to avoid duplicate submissions */\n";
251print '
252 jQuery(document).ready(function() {
253 jQuery(document).on("submit", "form", function(event) {
254 if (event.isDefaultPrevented() || (this.target && this.target != "_self")) {
255 return;
256 }
257 var $buttons = jQuery(this).find(".disableonsubmit");
258 if ($buttons.length == 0) {
259 return;
260 }
261 /* Flag is set synchronously, so a second very fast click is blocked even before buttons are disabled */
262 if (jQuery(this).data("dolsubmitted")) {
263 console.log("Form already submitted, we discard this new submission");
264 event.preventDefault();
265 return;
266 }
267 jQuery(this).data("dolsubmitted", true);
268 /* Disable after a timeout so the clicked button is still included into the submitted data */
269 setTimeout(function() { $buttons.prop("disabled", true); }, 0);
270 });
271 /* Enable buttons again if page is restored from browser cache (back button) */
272 jQuery(window).on("pageshow", function(event) {
273 if (event.originalEvent && event.originalEvent.persisted) {
274 jQuery("form").removeData("dolsubmitted");
275 jQuery(".disableonsubmit").prop("disabled", false);
276 }
277 });
278 });
279' . "\n";
280
281// Code to manage Copy To Clipboard click
282print "\n/* JS CODE TO ENABLE ClipBoard copy paste */\n";
283// Suppress because dol_escape_js is wrapped in '' @phan-suppress-next-line FunctionMissingSingleQuoteWrapping
284print '
285 jQuery(document).ready(function() {
286 jQuery(\'.clipboardCPShowOnHover\').hover(
287 function() {
288 console.log("We hover a value with a copy paste feature");
289 $(this).children(".clipboardCPButton, .clipboardCPText").css("display", "inline-block"); /* better than .show() because the show set the display to "inline" */
290 },
291 function() {
292 console.log("We hover out the value with a copy paste feature");
293 $(this).children(".clipboardCPButton, .clipboardCPText").hide();
294 }
295 );
296
297 jQuery(\'.clipboardCPValue, .clipboardCPButton, .clipboardCPValueToPrint\').click(function() {
298 console.log("We click on a clipboardCPButton or clipboardCPValueToPrint class and we want to copy content of clipboardCPValue class");
299
300 if (window.getSelection) {
301 jqobj=$(this).parent().children(".clipboardCPValue");
302 console.log(jqobj.html());
303
304 selection = window.getSelection(); /* get the object used for selection */
305 selection.removeAllRanges(); /* clear current selection */
306
307 /* We select the value to print using the parentNode.firstChild */
308 /* We should use the class clipboardCPValue but it may have several element with copy/paste so class to select is not enough */
309 range = document.createRange();
310 range.selectNodeContents(this.parentNode.firstChild);
311 selection.addRange(range); /* make the new selection with the value to copy */
312
313 /* copy selection into clipboard */
314 var succeed;
315 try {
316 console.log("We set the style display to unset for the span so the copy will work");
317 jqobj.css("display", "unset"); /* Because copy does not work on "block" object */
318
319 succeed = document.execCommand(\'copy\');
320
321 console.log("We set the style display back to inline-block");
322 jqobj.css("display", "inline-block"); /* better than .show() because the show set the display to "inline" */
323 } catch(e) {
324 succeed = false;
325 }
326
327 /* Remove the selection to avoid to see the hidden field to copy selected */
328 window.getSelection().removeAllRanges();
329 }
330
331 /* Show result - message */
332 var lastparent = $(this).parent(); /* .parent is clipboardCP */
333 var lastchild = this.parentNode.lastChild; /* .parentNode is clipboardCP and last child is clipboardCPText */
334 var tmp = lastchild.innerHTML
335 if (succeed) {
336 $(this).parent().children(".clipboardCPButton").hide();
337 $(this).parent().children(".clipboardCPTick").css("display", "inline-block"); /* better than .show() because the show set the display to "inline" */
338 //lastchild.innerHTML = \'<div class="clipboardCPTextDivInside opacitymedium">'.dolPrintHTML($langs->trans('CopiedToClipboard')).'</div>\';
339 } else {
340 lastchild.innerHTML = \'<div class="clipboardCPTextDivInside opacitymedium">'.dolPrintHTML($langs->trans('Error')).'</div>\';
341 }
342 setTimeout(() => { lastchild.innerHTML = tmp; lastparent.children(".clipboardCPTick").hide(); }, 2000);
343 });
344 });'."\n";
345
346// Code to manage clicktodial
347print "\n/* JS CODE TO ENABLE clicktodial call of an URL */\n";
348print '
349 jQuery(document).ready(function() {
350 jQuery(".cssforclicktodial").click(function() {
351 event.preventDefault();
352 var currenttoken = jQuery("meta[name=anti-csrf-currenttoken]").attr("content");
353 console.log("We click on a cssforclicktodial class with href="+this.href);
354 $.ajax({
355 url: this.href,
356 type: \'GET\',
357 data: { token: currenttoken }
358 }).done(function(xhr, textStatus, errorThrown) {
359 /* do nothing */
360 }).fail(function(xhr, textStatus, errorThrown) {
361 alert("Error: "+textStatus);
362 });
363 return false;
364 });
365 });'."\n";
366
367
368// Code to manage the confirm dialog box
369print "\n/* JS CODE TO ENABLE DIALOG CONFIRM POPUP ON ACTION BUTTON */\n";
370print '
371 jQuery(document).ready(function() {
372 $(document).on("click", \'.butActionConfirm\', function(event) {
373 event.preventDefault();
374
375 // I don\'t use jquery $(this).data(\'confirm-url\'); to get $(this).attr(\'data-confirm-url\'); because .data() can doesn\'t work with ajax
376 var confirmUrl = $(this).attr(\'data-confirm-url\');
377 var confirmTitle = $(this).attr(\'data-confirm-title\');
378 var confirmContent = $(this).attr(\'data-confirm-content\');
379 var confirmActionBtnLabel = $(this).attr(\'data-confirm-action-btn-label\');
380 var confirmCancelBtnLabel = $(this).attr(\'data-confirm-cancel-btn-label\');
381 var confirmModal = $(this).attr(\'data-confirm-modal\');
382 if(confirmModal == undefined){ confirmModal = false; }
383
384 var confirmId = \'confirm-dialog-box\';
385 if($(this).attr(\'id\') != undefined){ var confirmId = confirmId + "-" + $(this).attr(\'id\'); }
386 if($("#" + confirmId) != undefined) { $(\'#\' + confirmId).remove(); }
387
388 // Create modal box
389
390 var $confirmBox = $(\'<div/>\', {
391 id: confirmId,
392 title: confirmTitle
393 }).appendTo(\'body\');
394
395 $confirmBox.dialog({
396 autoOpen: true,
397 modal: confirmModal,
398 //width: Math.min($( window ).width() - 50, 1700),
399 width: \'auto\',
400 dialogClass: \'confirm-dialog-box\',
401 buttons: [
402 {
403 text: confirmActionBtnLabel,
404 "class": \'ui-state-information\',
405 click: function () {
406 window.location.replace(confirmUrl);
407 }
408 },
409 {
410 text: confirmCancelBtnLabel,
411 "class": \'ui-state-information\',
412 click: function () {
413 $(this).dialog("close");
414 }
415 }
416 ],
417 close: function( event, ui ) {
418 $(\'#\'+confirmBox).remove();
419 },
420 open: function( event, ui ) {
421 $confirmBox.html(confirmContent);
422 }
423 });
424 });
425 });
426'."\n";
427
428
429// JS CODE USED by form::getSearchFilterToolInput
430include __DIR__ . '/lib_foot_search_tool.js';
431include __DIR__ . '/lib_tooltip-freeze-by-alt-keypress.js';
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.