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