dolibarr 21.0.0-beta
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 *
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 * or see https://www.gnu.org/
18 */
19
25if (!defined('NOREQUIRESOC')) {
26 define('NOREQUIRESOC', '1');
27}
28if (!defined('NOCSRFCHECK')) {
29 define('NOCSRFCHECK', 1);
30}
31if (!defined('NOTOKENRENEWAL')) {
32 define('NOTOKENRENEWAL', 1);
33}
34if (!defined('NOLOGIN')) {
35 define('NOLOGIN', 1);
36}
37if (!defined('NOREQUIREMENU')) {
38 define('NOREQUIREMENU', 1);
39}
40if (!defined('NOREQUIREHTML')) {
41 define('NOREQUIREHTML', 1);
42}
43if (!defined('NOREQUIREAJAX')) {
44 define('NOREQUIREAJAX', '1');
45}
46
47session_cache_limiter('public');
48
49require_once '../../main.inc.php';
58/*
59 * View
60 */
61
62// Define javascript type
63top_httphead('text/javascript; charset=UTF-8');
64// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
65if (empty($dolibarr_nocache)) {
66 header('Cache-Control: max-age=10800, public, must-revalidate');
67} else {
68 header('Cache-Control: no-cache');
69}
70
71//var_dump($conf);
72
73
74// Wrapper to show tooltips (html or onclick popup)
75print "\n/* JS CODE TO ENABLE Tooltips on all object with class classfortooltip */
76jQuery(document).ready(function () {\n";
77
78if (empty($conf->dol_no_mouse_hover)) {
79 print '
80 /* for standard tooltip */
81 jQuery(".classfortooltip").tooltip({
82 tooltipClass: "mytooltip",
83 show: { collision: "flipfit", effect:"toggle", delay:50, duration: 20 },
84 hide: { delay: 250, duration: 20 },
85 content: function () {
86 console.log("Return title for popup");
87 return $(this).prop("title"); /* To force to get title as is */
88 }
89 });
90
91 var opendelay = 100;
92 var elemtostoretooltiptimer = jQuery("#dialogforpopup");
93 var currenttoken = jQuery("meta[name=anti-csrf-currenttoken]").attr("content");
94
95 /* for ajax tooltip */
96 target = jQuery(".classforajaxtooltip");
97 target.tooltip({
98 tooltipClass: "mytooltip",
99 show: { collision: "flipfit", effect:"toggle", delay: 0, duration: 20 },
100 hide: { delay: 250, duration: 20 }
101 });
102
103 target.off("mouseover mouseout");
104 target.on("mouseover", function(event) {
105 console.log("we will create timer for ajax call");
106 event.stopImmediatePropagation();
107 clearTimeout(elemtostoretooltiptimer.data("openTimeoutId"));
108
109 var params = JSON.parse($(this).attr("data-params"));
110 params.token = currenttoken;
111 var elemfortooltip = $(this);
112
113 elemtostoretooltiptimer.data("openTimeoutId", setTimeout(function() {
114 target.tooltip("close");
115 $.ajax({
116 url:"'. DOL_URL_ROOT.'/core/ajax/ajaxtooltip.php",
117 type: "post",
118 async: true,
119 data: params,
120 success: function(response){
121 // Setting content option
122 console.log("ajax success");
123 if (elemfortooltip.is(":hover")) {
124 elemfortooltip.tooltip("option","content",response);
125 elemfortooltip.tooltip("open");
126 }
127 }
128 });
129 }, opendelay));
130 });
131 target.on("mouseout", function(event) {
132 console.log("mouse out of a .classforajaxtooltip");
133 event.stopImmediatePropagation();
134 clearTimeout(elemtostoretooltiptimer.data("openTimeoutId"));
135 target.tooltip("close");
136 });
137 ';
138}
139
140print '
141 jQuery(".classfortooltiponclicktext").dialog({
142 closeOnEscape: true, classes: { "ui-dialog": "highlight" },
143 maxHeight: window.innerHeight-60, width: '.($conf->browser->layout == 'phone' ? max((empty($_SESSION['dol_screenwidth']) ? 0 : $_SESSION['dol_screenwidth']) - 20, 320) : 700).',
144 modal: true,
145 autoOpen: false
146 }).css("z-index: 5000");
147 jQuery(".classfortooltiponclick").click(function () {
148 console.log("We click on tooltip for element with dolid="+$(this).attr(\'dolid\'));
149 if ($(this).attr(\'dolid\')) {
150 obj=$("#idfortooltiponclick_"+$(this).attr(\'dolid\')); /* obj is a div component */
151 obj.dialog("open");
152 return false;
153 }
154 });
155});
156';
157
158
159// Wrapper to manage dropdown
160if (!defined('JS_JQUERY_DISABLE_DROPDOWN')) {
161 print "\n/* JS CODE TO ENABLE dropdown (hamburger, linkto, ...) */\n";
162 print ' jQuery(document).ready(function () {
163 var lastopendropdown = null;
164
165 // Click onto the link "link to" or "hamburger", toggle dropdown
166 $(document).on(\'click\', \'.dropdown dt a\', function () {
167 console.log("toggle dropdown dt a");
168 setTimeout(() => { $(\'.inputsearch_dropdownselectedfields\').focus(); }, 200);
169
170 //$(this).parent().parent().find(\'dd ul\').slideToggle(\'fast\');
171 $(".ulselectedfields").removeClass("open");
172 $(this).parent().parent().find(\'dd ul\').toggleClass("open");
173
174 if ($(this).parent().parent().find(\'dd ul\').hasClass("open")) {
175 lastopendropdown = $(this).parent().parent().find(\'dd ul\');
176 //console.log(lastopendropdown);
177 } else {
178 // We closed the dropdown for hamburger selectfields
179 if ($("input:hidden[name=formfilteraction]").val() == "listafterchangingselectedfields") {
180 console.log("resubmit the form saved into lastopendropdown after clicking on hamburger");
181 //$(".dropdown dt a").parents(\'form:first\').submit();
182 //$(".dropdown dt a").closest("form").submit();
183 lastopendropdown.closest("form").submit();
184 }
185 }
186
187 // Note: Did not find a way to get exact height (value is update at exit) so i calculate a generic from nb of lines
188 heigthofcontent = 21 * $(this).parent().parent().find(\'dd div ul li\').length;
189 if (heigthofcontent > 300) heigthofcontent = 300; // limited by max-height on css .dropdown dd ul
190 posbottom = $(this).parent().parent().find(\'dd\').offset().top + heigthofcontent + 8;
191 var scrollBottom = $(window).scrollTop() + $(window).height();
192 diffoutsidebottom = (posbottom - scrollBottom);
193 console.log("heigthofcontent="+heigthofcontent+", diffoutsidebottom (posbottom="+posbottom+" - scrollBottom="+scrollBottom+") = "+diffoutsidebottom);
194 if (diffoutsidebottom > 0)
195 {
196 pix = "-"+(diffoutsidebottom+8)+"px";
197 console.log("We reposition top by "+pix);
198 $(this).parent().parent().find(\'dd\').css("top", pix);
199 }
200 });
201
202 // Click on a link into the popup "link to" or other dropdown that ask to close drop down on element click, so close dropdown
203 $(".dropdowncloseonclick").on(\'click\', function () {
204 console.log("Link has class dropdowncloseonclick, so we close/hide the popup ul");
205 //$(this).parent().parent().hide(); // $(this).parent().parent() is ul
206 $(this).parent().parent().removeClass("open"); // $(this).parent().parent() is ul
207 });
208
209 // Click outside of any dropdown
210 $(document).bind(\'click\', function (e) {
211 var $clicked = $(e.target); // This is element we click on
212 if (!$clicked.parents().hasClass("dropdown")) {
213 //console.log("close dropdown dd ul - we click outside");
214 //$(".dropdown dd ul").hide();
215 $(".dropdown dd ul").removeClass("open");
216
217 if ($("input:hidden[name=formfilteraction]").val() == "listafterchangingselectedfields") {
218 console.log("resubmit form saved into lastopendropdown after clicking outside of dropdown and having change selectlist from selectlist field of hamburger dropdown");
219 //$(".dropdown dt a").parents(\'form:first\').submit();
220 //$(".dropdown dt a").closest("form").submit();
221 lastopendropdown.closest("form").submit();
222 }
223 }
224 });
225 });
226 ';
227}
228
229// Wrapper to manage document_preview
230if ($conf->browser->layout != 'phone') {
231 print "\n/* JS CODE TO ENABLE document_preview */\n"; // Function document_preview is into header
232 print ' jQuery(document).ready(function () {
233 // Click on the preview picto
234 jQuery(".documentpreview").click(function () {
235 console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
236 document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), \''.dol_escape_js($langs->transnoentities("Preview")).'\');
237 return false;
238 });
239 });'."\n";
240}
241
242// Code to manage reposition
243print "\n/* JS CODE TO ENABLE reposition management (does not work if a redirect is done after action of submission) */\n";
244print '
245 jQuery(document).ready(function() {
246 /* If page_y set, we set scrollbar with it */
247 page_y = getParameterByName("page_y", 0); /* search in GET parameter */
248 if (page_y == 0) page_y = jQuery("#page_y").text(); /* search in POST parameter that is filed at bottom of page */
249 if (page_y > 0) {
250 console.log("page_y found is "+page_y);
251 jQuery("html, body").scrollTop(page_y);
252 }
253
254 /* Set handler to add page_y param on output (click on href links or submit button) */
255 jQuery(".reposition").click(function(event) {
256 var page_y = jQuery(document).scrollTop();
257 if (page_y > 0) {
258 if (this.href) {
259 console.log("We click on tag with .reposition class. this.ref was "+this.href);
260 var url = new URL(this.href, window.location.origin);
261 url.searchParams.delete("page_y"); /* remove page_y param if already present */
262 url.searchParams.set("page_y", page_y);
263 this.href = url.toString();
264 console.log("We click on tag with .reposition class. this.ref is now "+this.href);
265 } else {
266 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);
267 jQuery("input[type=hidden][name=page_y]").val(page_y);
268 }
269 }
270 });
271 });
272' . "\n";
273
274// Code to manage Copy To Clipboard click
275print "\n/* JS CODE TO ENABLE ClipBoard copy paste */\n";
276print '
277 jQuery(document).ready(function() {
278 jQuery(\'.clipboardCPShowOnHover\').hover(
279 function() {
280 console.log("We hover a value with a copy paste feature");
281 $(this).children(".clipboardCPButton, .clipboardCPText").css("display", "inline-block"); /* better than .show() because the show set the display to "inline" */
282 },
283 function() {
284 console.log("We hover out the value with a copy paste feature");
285 $(this).children(".clipboardCPButton, .clipboardCPText").hide();
286 }
287 );
288
289 jQuery(\'.clipboardCPValue, .clipboardCPButton, .clipboardCPValueToPrint\').click(function() {
290 console.log("We click on a clipboardCPButton or clipboardCPValueToPrint class and we want to copy content of clipboardCPValue class");
291
292 if (window.getSelection) {
293 jqobj=$(this).parent().children(".clipboardCPValue");
294 console.log(jqobj.html());
295
296 selection = window.getSelection(); /* get the object used for selection */
297 selection.removeAllRanges(); /* clear current selection */
298
299 /* We select the value to print using the parentNode.firstChild */
300 /* We should use the class clipboardCPValue but it may have several element with copy/paste so class to select is not enough */
301 range = document.createRange();
302 range.selectNodeContents(this.parentNode.firstChild);
303 selection.addRange(range); /* make the new selection with the value to copy */
304
305 /* copy selection into clipboard */
306 var succeed;
307 try {
308 console.log("We set the style display to unset for the span so the copy will work");
309 jqobj.css("display", "unset"); /* Because copy does not work on "block" object */
310
311 succeed = document.execCommand(\'copy\');
312
313 console.log("We set the style display back to inline-block");
314 jqobj.css("display", "inline-block"); /* better than .show() because the show set the display to "inline" */
315 } catch(e) {
316 succeed = false;
317 }
318
319 /* Remove the selection to avoid to see the hidden field to copy selected */
320 window.getSelection().removeAllRanges();
321 }
322
323 /* Show result - message */
324 var lastparent = $(this).parent(); /* .parent is clipboardCP */
325 var lastchild = this.parentNode.lastChild; /* .parentNode is clipboardCP and last child is clipboardCPText */
326 var tmp = lastchild.innerHTML
327 if (succeed) {
328 $(this).parent().children(".clipboardCPButton").hide();
329 $(this).parent().children(".clipboardCPTick").css("display", "inline-block"); /* better than .show() because the show set the display to "inline" */
330 //lastchild.innerHTML = \'<div class="clipboardCPTextDivInside opacitymedium">'.dol_escape_js($langs->trans('CopiedToClipboard')).'</div>\';
331 } else {
332 lastchild.innerHTML = \'<div class="clipboardCPTextDivInside opacitymedium">'.dol_escape_js($langs->trans('Error')).'</div>\';
333 }
334 setTimeout(() => { lastchild.innerHTML = tmp; lastparent.children(".clipboardCPTick").hide(); }, 2000);
335 });
336 });'."\n";
337
338// Code to manage clicktodial
339print "\n/* JS CODE TO ENABLE clicktodial call of an URL */\n";
340print '
341 jQuery(document).ready(function() {
342 jQuery(".cssforclicktodial").click(function() {
343 event.preventDefault();
344 var currenttoken = jQuery("meta[name=anti-csrf-currenttoken]").attr("content");
345 console.log("We click on a cssforclicktodial class with href="+this.href);
346 $.ajax({
347 url: this.href,
348 type: \'GET\',
349 data: { token: currenttoken }
350 }).done(function(xhr, textStatus, errorThrown) {
351 /* do nothing */
352 }).fail(function(xhr, textStatus, errorThrown) {
353 alert("Error: "+textStatus);
354 });
355 return false;
356 });
357 });'."\n";
358
359
360// Code to manage the confirm dialog box
361print "\n/* JS CODE TO ENABLE DIALOG CONFIRM POPUP ON ACTION BUTTON */\n";
362print '
363 jQuery(document).ready(function() {
364 $(document).on("click", \'.butActionConfirm\', function(event) {
365 event.preventDefault();
366
367 // I don\'t use jquery $(this).data(\'confirm-url\'); to get $(this).attr(\'data-confirm-url\'); because .data() can doesn\'t work with ajax
368 var confirmUrl = $(this).attr(\'data-confirm-url\');
369 var confirmTitle = $(this).attr(\'data-confirm-title\');
370 var confirmContent = $(this).attr(\'data-confirm-content\');
371 var confirmActionBtnLabel = $(this).attr(\'data-confirm-action-btn-label\');
372 var confirmCancelBtnLabel = $(this).attr(\'data-confirm-cancel-btn-label\');
373 var confirmModal = $(this).attr(\'data-confirm-modal\');
374 if(confirmModal == undefined){ confirmModal = false; }
375
376 var confirmId = \'confirm-dialog-box\';
377 if($(this).attr(\'id\') != undefined){ var confirmId = confirmId + "-" + $(this).attr(\'id\'); }
378 if($("#" + confirmId) != undefined) { $(\'#\' + confirmId).remove(); }
379
380 // Create modal box
381
382 var $confirmBox = $(\'<div/>\', {
383 id: confirmId,
384 title: confirmTitle
385 }).appendTo(\'body\');
386
387 $confirmBox.dialog({
388 autoOpen: true,
389 modal: confirmModal,
390 //width: Math.min($( window ).width() - 50, 1700),
391 width: \'auto\',
392 dialogClass: \'confirm-dialog-box\',
393 buttons: [
394 {
395 text: confirmActionBtnLabel,
396 "class": \'ui-state-information\',
397 click: function () {
398 window.location.replace(confirmUrl);
399 }
400 },
401 {
402 text: confirmCancelBtnLabel,
403 "class": \'ui-state-information\',
404 click: function () {
405 $(this).dialog("close");
406 }
407 }
408 ],
409 close: function( event, ui ) {
410 $(\'#\'+confirmBox).remove();
411 },
412 open: function( event, ui ) {
413 $confirmBox.html(confirmContent);
414 }
415 });
416 });
417 });
418'."\n";
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79