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