dolibarr 20.0.0
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 elemfortooltip.tooltip("option","content",response);
117 elemfortooltip.tooltip("open");
118 }
119 });
120 }, opendelay));
121 });
122 target.on("mouseout", function(event) {
123 console.log("mouse out of a .classforajaxtooltip");
124 event.stopImmediatePropagation();
125 clearTimeout(elemtostoretooltiptimer.data("openTimeoutId"));
126 target.tooltip("close");
127 });
128 ';
129}
130
131print '
132 jQuery(".classfortooltiponclicktext").dialog({
133 closeOnEscape: true, classes: { "ui-dialog": "highlight" },
134 maxHeight: window.innerHeight-60, width: '.($conf->browser->layout == 'phone' ? max((empty($_SESSION['dol_screenwidth']) ? 0 : $_SESSION['dol_screenwidth']) - 20, 320) : 700).',
135 modal: true,
136 autoOpen: false
137 }).css("z-index: 5000");
138 jQuery(".classfortooltiponclick").click(function () {
139 console.log("We click on tooltip for element with dolid="+$(this).attr(\'dolid\'));
140 if ($(this).attr(\'dolid\')) {
141 obj=$("#idfortooltiponclick_"+$(this).attr(\'dolid\')); /* obj is a div component */
142 obj.dialog("open");
143 return false;
144 }
145 });
146});
147';
148
149
150// Wrapper to manage dropdown
151if (!defined('JS_JQUERY_DISABLE_DROPDOWN')) {
152 print "\n/* JS CODE TO ENABLE dropdown (hamburger, linkto, ...) */\n";
153 print ' jQuery(document).ready(function () {
154 var lastopendropdown = null;
155
156 // Click onto the link "link to" or "hamburger", toggle dropdown
157 $(document).on(\'click\', \'.dropdown dt a\', function () {
158 console.log("toggle dropdown dt a");
159 setTimeout(() => { $(\'.inputsearch_dropdownselectedfields\').focus(); }, 200);
160
161 //$(this).parent().parent().find(\'dd ul\').slideToggle(\'fast\');
162 $(".ulselectedfields").removeClass("open");
163 $(this).parent().parent().find(\'dd ul\').toggleClass("open");
164
165 if ($(this).parent().parent().find(\'dd ul\').hasClass("open")) {
166 lastopendropdown = $(this).parent().parent().find(\'dd ul\');
167 //console.log(lastopendropdown);
168 } else {
169 // We closed the dropdown for hamburger selectfields
170 if ($("input:hidden[name=formfilteraction]").val() == "listafterchangingselectedfields") {
171 console.log("resubmit the form saved into lastopendropdown after clicking on hamburger");
172 //$(".dropdown dt a").parents(\'form:first\').submit();
173 //$(".dropdown dt a").closest("form").submit();
174 lastopendropdown.closest("form").submit();
175 }
176 }
177
178 // Note: Did not find a way to get exact height (value is update at exit) so i calculate a generic from nb of lines
179 heigthofcontent = 21 * $(this).parent().parent().find(\'dd div ul li\').length;
180 if (heigthofcontent > 300) heigthofcontent = 300; // limited by max-height on css .dropdown dd ul
181 posbottom = $(this).parent().parent().find(\'dd\').offset().top + heigthofcontent + 8;
182 var scrollBottom = $(window).scrollTop() + $(window).height();
183 diffoutsidebottom = (posbottom - scrollBottom);
184 console.log("heigthofcontent="+heigthofcontent+", diffoutsidebottom (posbottom="+posbottom+" - scrollBottom="+scrollBottom+") = "+diffoutsidebottom);
185 if (diffoutsidebottom > 0)
186 {
187 pix = "-"+(diffoutsidebottom+8)+"px";
188 console.log("We reposition top by "+pix);
189 $(this).parent().parent().find(\'dd\').css("top", pix);
190 }
191 });
192
193 // Click on a link into the popup "link to" or other dropdown that ask to close drop down on element click, so close dropdown
194 $(".dropdowncloseonclick").on(\'click\', function () {
195 console.log("Link has class dropdowncloseonclick, so we close/hide the popup ul");
196 //$(this).parent().parent().hide(); // $(this).parent().parent() is ul
197 $(this).parent().parent().removeClass("open"); // $(this).parent().parent() is ul
198 });
199
200 // Click outside of any dropdown
201 $(document).bind(\'click\', function (e) {
202 var $clicked = $(e.target); // This is element we click on
203 if (!$clicked.parents().hasClass("dropdown")) {
204 //console.log("close dropdown dd ul - we click outside");
205 //$(".dropdown dd ul").hide();
206 $(".dropdown dd ul").removeClass("open");
207
208 if ($("input:hidden[name=formfilteraction]").val() == "listafterchangingselectedfields") {
209 console.log("resubmit form saved into lastopendropdown after clicking outside of dropdown and having change selectlist from selectlist field of hamburger dropdown");
210 //$(".dropdown dt a").parents(\'form:first\').submit();
211 //$(".dropdown dt a").closest("form").submit();
212 lastopendropdown.closest("form").submit();
213 }
214 }
215 });
216 });
217 ';
218}
219
220// Wrapper to manage document_preview
221if ($conf->browser->layout != 'phone') {
222 print "\n/* JS CODE TO ENABLE document_preview */\n"; // Function document_preview is into header
223 print ' jQuery(document).ready(function () {
224 jQuery(".documentpreview").click(function () {
225 console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
226 document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), \''.dol_escape_js($langs->transnoentities("Preview")).'\');
227 return false;
228 });
229 });'."\n";
230}
231
232// Code to manage reposition
233print "\n/* JS CODE TO ENABLE reposition management (does not work if a redirect is done after action of submission) */\n";
234print '
235 jQuery(document).ready(function() {
236 /* If page_y set, we set scrollbar with it */
237 page_y=getParameterByName(\'page_y\', 0); /* search in GET parameter */
238 if (page_y == 0) page_y = jQuery("#page_y").text(); /* search in POST parameter that is filed at bottom of page */
239 if (page_y > 0)
240 {
241 console.log("page_y found is "+page_y);
242 $(\'html, body\').scrollTop(page_y);
243 }
244
245 /* Set handler to add page_y param on output (click on href links or submit button) */
246 jQuery(".reposition").click(function() {
247 var page_y = $(document).scrollTop();
248
249 if (page_y > 0)
250 {
251 if (this.href)
252 {
253 console.log("We click on tag with .reposition class. this.ref was "+this.href);
254 var hrefarray = this.href.split("#", 2);
255 hrefarray[0]=hrefarray[0].replace(/&page_y=(\d+)/, \'\'); /* remove page_y param if already present */
256 this.href=hrefarray[0]+\'&page_y=\'+page_y;
257 console.log("We click on tag with .reposition class. this.ref is now "+this.href);
258 }
259 else
260 {
261 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);
262 jQuery("input[type=hidden][name=page_y]").val(page_y);
263 }
264 }
265 });
266 });'."\n";
267
268// Code to manage Copy To Clipboard click
269print "\n/* JS CODE TO ENABLE ClipBoard copy paste */\n";
270print '
271 jQuery(document).ready(function() {
272 jQuery(\'.clipboardCPShowOnHover\').hover(
273 function() {
274 console.log("We hover a value with a copy paste feature");
275 $(this).children(".clipboardCPButton, .clipboardCPText").show();
276 },
277 function() {
278 console.log("We hover out the value with a copy paste feature");
279 $(this).children(".clipboardCPButton, .clipboardCPText").hide();
280 }
281 );
282
283 jQuery(\'.clipboardCPValue, .clipboardCPButton, .clipboardCPValueToPrint\').click(function() {
284 console.log("We click on a clipboardCPButton or clipboardCPValueToPrint class and we want to copy content of clipboardCPValue class");
285
286 if (window.getSelection) {
287 jqobj=$(this).parent().children(".clipboardCPValue");
288 console.log(jqobj.html());
289
290 selection = window.getSelection(); /* get the object used for selection */
291 selection.removeAllRanges(); /* clear current selection */
292
293 /* We select the value to print using the parentNode.firstChild */
294 /* We should use the class clipboardCPValue but it may have several element with copy/paste so class to select is not enough */
295 range = document.createRange();
296 range.selectNodeContents(this.parentNode.firstChild);
297 selection.addRange(range); /* make the new selection with the value to copy */
298
299 /* copy selection into clipboard */
300 var succeed;
301 try {
302 console.log("We set the style display to unset for the span so the copy will work");
303 jqobj.css("display", "unset"); /* Because copy does not work on "block" object */
304
305 succeed = document.execCommand(\'copy\');
306
307 console.log("We set the style display back to inline-block");
308 jqobj.css("display", "inline-block");
309 } catch(e) {
310 succeed = false;
311 }
312
313 /* Remove the selection to avoid to see the hidden field to copy selected */
314 window.getSelection().removeAllRanges();
315 }
316
317 /* Show message */
318 /* TODO Show message into a top left corner or center of screen */
319 var lastchild = this.parentNode.lastChild; /* .parentNode is clipboardCP and last child is clipboardCPText */
320 var tmp = lastchild.innerHTML
321 if (succeed) {
322 lastchild.innerHTML = \'<div class="clipboardCPTextDivInside opacitymedium">'.dol_escape_js($langs->trans('CopiedToClipboard')).'</div>\';
323 } else {
324 lastchild.innerHTML = \'<div class="clipboardCPTextDivInside opacitymedium">'.dol_escape_js($langs->trans('Error')).'</div>\';
325 }
326 setTimeout(() => { lastchild.innerHTML = tmp; }, 1000);
327 });
328 });'."\n";
329
330// Code to manage clicktodial
331print "\n/* JS CODE TO ENABLE clicktodial call of an URL */\n";
332print '
333 jQuery(document).ready(function() {
334 jQuery(".cssforclicktodial").click(function() {
335 event.preventDefault();
336 var currenttoken = jQuery("meta[name=anti-csrf-currenttoken]").attr("content");
337 console.log("We click on a cssforclicktodial class with href="+this.href);
338 $.ajax({
339 url: this.href,
340 type: \'GET\',
341 data: { token: currenttoken }
342 }).done(function(xhr, textStatus, errorThrown) {
343 /* do nothing */
344 }).fail(function(xhr, textStatus, errorThrown) {
345 alert("Error: "+textStatus);
346 });
347 return false;
348 });
349 });'."\n";
350
351
352// Code to manage the confirm dialog box
353print "\n/* JS CODE TO ENABLE DIALOG CONFIRM POPUP ON ACTION BUTTON */\n";
354print '
355 jQuery(document).ready(function() {
356 $(document).on("click", \'.butActionConfirm\', function(event) {
357 event.preventDefault();
358
359 // I don\'t use jquery $(this).data(\'confirm-url\'); to get $(this).attr(\'data-confirm-url\'); because .data() can doesn\'t work with ajax
360 var confirmUrl = $(this).attr(\'data-confirm-url\');
361 var confirmTitle = $(this).attr(\'data-confirm-title\');
362 var confirmContent = $(this).attr(\'data-confirm-content\');
363 var confirmActionBtnLabel = $(this).attr(\'data-confirm-action-btn-label\');
364 var confirmCancelBtnLabel = $(this).attr(\'data-confirm-cancel-btn-label\');
365 var confirmModal = $(this).attr(\'data-confirm-modal\');
366 if(confirmModal == undefined){ confirmModal = false; }
367
368 var confirmId = \'confirm-dialog-box\';
369 if($(this).attr(\'id\') != undefined){ var confirmId = confirmId + "-" + $(this).attr(\'id\'); }
370 if($("#" + confirmId) != undefined) { $(\'#\' + confirmId).remove(); }
371
372 // Create modal box
373
374 var $confirmBox = $(\'<div/>\', {
375 id: confirmId,
376 title: confirmTitle
377 }).appendTo(\'body\');
378
379 $confirmBox.dialog({
380 autoOpen: true,
381 modal: confirmModal,
382 //width: Math.min($( window ).width() - 50, 1700),
383 width: \'auto\',
384 dialogClass: \'confirm-dialog-box\',
385 buttons: [
386 {
387 text: confirmActionBtnLabel,
388 "class": \'ui-state-information\',
389 click: function () {
390 window.location.replace(confirmUrl);
391 }
392 },
393 {
394 text: confirmCancelBtnLabel,
395 "class": \'ui-state-information\',
396 click: function () {
397 $(this).dialog("close");
398 }
399 }
400 ],
401 close: function( event, ui ) {
402 $(\'#\'+confirmBox).remove();
403 },
404 open: function( event, ui ) {
405 $confirmBox.html(confirmContent);
406 }
407 });
408 });
409 });
410'."\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.