dolibarr  16.0.5
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 
24 if (!defined('NOREQUIRESOC')) {
25  define('NOREQUIRESOC', '1');
26 }
27 if (!defined('NOCSRFCHECK')) {
28  define('NOCSRFCHECK', 1);
29 }
30 if (!defined('NOTOKENRENEWAL')) {
31  define('NOTOKENRENEWAL', 1);
32 }
33 if (!defined('NOLOGIN')) {
34  define('NOLOGIN', 1);
35 }
36 if (!defined('NOREQUIREMENU')) {
37  define('NOREQUIREMENU', 1);
38 }
39 if (!defined('NOREQUIREHTML')) {
40  define('NOREQUIREHTML', 1);
41 }
42 if (!defined('NOREQUIREAJAX')) {
43  define('NOREQUIREAJAX', '1');
44 }
45 
46 session_cache_limiter('public');
47 
48 require_once '../../main.inc.php';
49 
50 
51 /*
52  * View
53  */
54 
55 // Define javascript type
56 top_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.
58 if (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)
68 print "\n/* JS CODE TO ENABLE Tooltips on all object with class classfortooltip */\n";
69 print "jQuery(document).ready(function () {\n";
70 
71 if (empty($conf->dol_no_mouse_hover)) {
72  print 'jQuery(".classfortooltip").tooltip({
73  show: { collision: "flipfit", effect:"toggle", delay:50, duration: 20 },
74  hide: { delay: 250, duration: 20 },
75  tooltipClass: "mytooltip",
76  content: function () {
77  console.log("Return title for popup");
78  return $(this).prop("title"); /* To force to get title as is */
79  }
80  });'."\n";
81 }
82 
83 print '
84 jQuery(".classfortooltiponclicktext").dialog({
85  closeOnEscape: true, classes: { "ui-dialog": "highlight" },
86  maxHeight: window.innerHeight-60, width: '.($conf->browser->layout == 'phone' ? max($_SESSION['dol_screenwidth'] - 20, 320) : 700).',
87  modal: true,
88  autoOpen: false
89  }).css("z-index: 5000");
90 jQuery(".classfortooltiponclick").click(function () {
91  console.log("We click on tooltip for element with dolid="+$(this).attr(\'dolid\'));
92  if ($(this).attr(\'dolid\')) {
93  obj=$("#idfortooltiponclick_"+$(this).attr(\'dolid\')); /* obj is a div component */
94  obj.dialog("open");
95  return false;
96  }
97 });'."\n";
98 
99 print "});\n";
100 
101 
102 // Wrapper to manage dropdown
103 if (!defined('JS_JQUERY_DISABLE_DROPDOWN')) {
104  print "\n/* JS CODE TO ENABLE dropdown (hamburger, linkto, ...) */\n";
105  print ' jQuery(document).ready(function () {
106  var lastopendropdown = null;
107 
108  // Click onto the link "link to" or "hamburger", toggle dropdown
109  $(document).on(\'click\', \'.dropdown dt a\', function () {
110  console.log("toggle dropdown dt a");
111 
112  //$(this).parent().parent().find(\'dd ul\').slideToggle(\'fast\');
113  $(this).parent().parent().find(\'dd ul\').toggleClass("open");
114 
115  if ($(this).parent().parent().find(\'dd ul\').hasClass("open")) {
116  lastopendropdown = $(this).parent().parent().find(\'dd ul\');
117  //console.log(lastopendropdown);
118  } else {
119  // We closed the dropdown for hamburger selectfields
120  if ($("input:hidden[name=formfilteraction]").val() == "listafterchangingselectedfields") {
121  console.log("resubmit the form saved into lastopendropdown after clicking on hamburger");
122  //$(".dropdown dt a").parents(\'form:first\').submit();
123  //$(".dropdown dt a").closest("form").submit();
124  lastopendropdown.closest("form").submit();
125  }
126  }
127 
128  // Note: Did not find a way to get exact height (value is update at exit) so i calculate a generic from nb of lines
129  heigthofcontent = 21 * $(this).parent().parent().find(\'dd div ul li\').length;
130  if (heigthofcontent > 300) heigthofcontent = 300; // limited by max-height on css .dropdown dd ul
131  posbottom = $(this).parent().parent().find(\'dd\').offset().top + heigthofcontent + 8;
132  var scrollBottom = $(window).scrollTop() + $(window).height();
133  diffoutsidebottom = (posbottom - scrollBottom);
134  console.log("heigthofcontent="+heigthofcontent+", diffoutsidebottom (posbottom="+posbottom+" - scrollBottom="+scrollBottom+") = "+diffoutsidebottom);
135  if (diffoutsidebottom > 0)
136  {
137  pix = "-"+(diffoutsidebottom+8)+"px";
138  console.log("We reposition top by "+pix);
139  $(this).parent().parent().find(\'dd\').css("top", pix);
140  }
141  });
142 
143  // Click on a link into the popup "link to" or other dropdown that ask to close drop down on element click, so close dropdown
144  $(".dropdowncloseonclick").on(\'click\', function () {
145  console.log("Link has class dropdowncloseonclick, so we close/hide the popup ul");
146  //$(this).parent().parent().hide(); // $(this).parent().parent() is ul
147  $(this).parent().parent().removeClass("open"); // $(this).parent().parent() is ul
148  });
149 
150  // Click outside of any dropdown
151  $(document).bind(\'click\', function (e) {
152  var $clicked = $(e.target); // This is element we click on
153  if (!$clicked.parents().hasClass("dropdown")) {
154  //console.log("close dropdown dd ul - we click outside");
155  //$(".dropdown dd ul").hide();
156  $(".dropdown dd ul").removeClass("open");
157 
158  if ($("input:hidden[name=formfilteraction]").val() == "listafterchangingselectedfields") {
159  console.log("resubmit form saved into lastopendropdown after clicking outside of dropdown and having change selectlist from selectlist field of hamburger dropdown");
160  //$(".dropdown dt a").parents(\'form:first\').submit();
161  //$(".dropdown dt a").closest("form").submit();
162  lastopendropdown.closest("form").submit();
163  }
164  }
165  });
166  });
167  ';
168 }
169 
170 // Wrapper to manage document_preview
171 if ($conf->browser->layout != 'phone') {
172  print "\n/* JS CODE TO ENABLE document_preview */\n"; // Function document_preview is into header
173  print ' jQuery(document).ready(function () {
174  jQuery(".documentpreview").click(function () {
175  console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
176  document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), \''.dol_escape_js($langs->transnoentities("Preview")).'\');
177  return false;
178  });
179  });'."\n";
180 }
181 
182 // Code to manage reposition
183 print "\n/* JS CODE TO ENABLE reposition management (does not work if a redirect is done after action of submission) */\n";
184 print '
185  jQuery(document).ready(function() {
186  /* If page_y set, we set scollbar with it */
187  page_y=getParameterByName(\'page_y\', 0); /* search in GET parameter */
188  if (page_y == 0) page_y = jQuery("#page_y").text(); /* search in POST parameter that is filed at bottom of page */
189  if (page_y > 0)
190  {
191  console.log("page_y found is "+page_y);
192  $(\'html, body\').scrollTop(page_y);
193  }
194 
195  /* Set handler to add page_y param on output (click on href links or submit button) */
196  jQuery(".reposition").click(function() {
197  var page_y = $(document).scrollTop();
198 
199  if (page_y > 0)
200  {
201  if (this.href)
202  {
203  console.log("We click on tag with .reposition class. this.ref was "+this.href);
204  var hrefarray = this.href.split("#", 2);
205  hrefarray[0]=hrefarray[0].replace(/&page_y=(\d+)/, \'\'); /* remove page_y param if already present */
206  this.href=hrefarray[0]+\'&page_y=\'+page_y;
207  console.log("We click on tag with .reposition class. this.ref is now "+this.href);
208  }
209  else
210  {
211  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);
212  jQuery("input[type=hidden][name=page_y]").val(page_y);
213  }
214  }
215  });
216  });'."\n";
217 
218 // Code to manage Copy To Clipboard click
219 print "\n/* JS CODE TO ENABLE ClipBoard copy paste */\n";
220 print '
221  jQuery(document).ready(function() {
222  jQuery(\'.clipboardCPShowOnHover\').hover(
223  function() {
224  console.log("We hover a value with a copy paste feature");
225  $(this).children(".clipboardCPButton, .clipboardCPText").show();
226  },
227  function() {
228  console.log("We hover out the value with a copy paste feature");
229  $(this).children(".clipboardCPButton, .clipboardCPText").hide();
230  }
231  );
232 
233  jQuery(\'.clipboardCPValue, .clipboardCPButton, .clipboardCPValueToPrint\').click(function() {
234  console.log("We click on a clipboardCPButton or clipboardCPValueToPrint class and we want to copy content of clipboardCPValue class");
235 
236  if (window.getSelection) {
237  jqobj=$(this).parent().children(".clipboardCPValue");
238  console.log(jqobj.html());
239 
240  selection = window.getSelection(); /* get the object used for selection */
241  selection.removeAllRanges(); /* clear current selection */
242 
243  /* We select the value to print using the parentNode.firstChild */
244  /* We should use the class clipboardCPValue but it may have several element with copy/paste so class to select is not enough */
245  range = document.createRange();
246  range.selectNodeContents(this.parentNode.firstChild);
247  selection.addRange(range); /* make the new selection with the value to copy */
248 
249  /* copy selection into clipboard */
250  var succeed;
251  try {
252  console.log("We set the style display to unset for the span so the copy will work");
253  jqobj.css("display", "unset"); /* Because copy does not work on "block" object */
254 
255  succeed = document.execCommand(\'copy\');
256 
257  console.log("We set the style display back to inline-block");
258  jqobj.css("display", "inline-block");
259  } catch(e) {
260  succeed = false;
261  }
262 
263  /* Remove the selection to avoid to see the hidden field to copy selected */
264  window.getSelection().removeAllRanges();
265  }
266 
267  /* Show message */
268  /* TODO Show message into a top left corner or center of screen */
269  var lastchild = this.parentNode.lastChild; /* .parentNode is clipboardCP and last child is clipboardCPText */
270  var tmp = lastchild.innerHTML
271  if (succeed) {
272  lastchild.innerHTML = \'<div class="clipboardCPTextDivInside opacitymedium">'.dol_escape_js($langs->trans('CopiedToClipboard')).'</div>\';
273  } else {
274  lastchild.innerHTML = \'<div class="clipboardCPTextDivInside opacitymedium">'.dol_escape_js($langs->trans('Error')).'</div>\';
275  }
276  setTimeout(() => { lastchild.innerHTML = tmp; }, 1000);
277  });
278  });'."\n";
279 
280 // Code to manage clicktodial
281 print "\n/* JS CODE TO ENABLE clicktodial call of an URL */\n";
282 print '
283  jQuery(document).ready(function() {
284  jQuery(".cssforclicktodial").click(function() {
285  event.preventDefault();
286  console.log("We click on a cssforclicktodial class with url="+this.href);
287  $.ajax({
288  url: this.href,
289  type: \'GET\',
290  data: { token: \''.newToken().'\' }
291  }).done(function(xhr, textStatus, errorThrown) {
292  /* do nothing */
293  }).fail(function(xhr, textStatus, errorThrown) {
294  alert("Error: "+textStatus);
295  });
296  return false;
297  });
298  });'."\n";
299 
300 
301 // Code to manage the confirm dialog box
302 print "\n/* JS CODE TO ENABLE DIALOG CONFIRM POPUP ON ACTION BUTTON */\n";
303 print '
304  jQuery(document).ready(function() {
305  $(document).on("click", \'.butActionConfirm\', function(event) {
306  event.preventDefault();
307 
308  // I don\'t use jquery $(this).data(\'confirm-url\'); to get $(this).attr(\'data-confirm-url\'); because .data() can doesn\'t work with ajax
309  var confirmUrl = $(this).attr(\'data-confirm-url\');
310  var confirmTitle = $(this).attr(\'data-confirm-title\');
311  var confirmContent = $(this).attr(\'data-confirm-content\');
312  var confirmActionBtnLabel = $(this).attr(\'data-confirm-action-btn-label\');
313  var confirmCancelBtnLabel = $(this).attr(\'data-confirm-cancel-btn-label\');
314  var confirmModal = $(this).attr(\'data-confirm-modal\');
315  if(confirmModal == undefined){ confirmModal = false; }
316 
317  var confirmId = \'confirm-dialog-box\';
318  if($(this).attr(\'id\') != undefined){ var confirmId = confirmId + "-" + $(this).attr(\'id\'); }
319  if($("#" + confirmId) != undefined) { $(\'#\' + confirmId).remove(); }
320 
321  // Create modal box
322 
323  var $confirmBox = $(\'<div/>\', {
324  id: confirmId,
325  title: confirmTitle
326  }).appendTo(\'body\');
327 
328  $confirmBox.dialog({
329  autoOpen: true,
330  modal: confirmModal,
331  //width: Math.min($( window ).width() - 50, 1700),
332  width: \'auto\',
333  dialogClass: \'confirm-dialog-box\',
334  buttons: [
335  {
336  text: confirmActionBtnLabel,
337  "class": \'ui-state-information\',
338  click: function () {
339  window.location.replace(confirmUrl);
340  }
341  },
342  {
343  text: confirmCancelBtnLabel,
344  "class": \'ui-state-information\',
345  click: function () {
346  $(this).dialog("close");
347  }
348  }
349  ],
350  close: function( event, ui ) {
351  $(\'#\'+confirmBox).remove();
352  },
353  open: function( event, ui ) {
354  $confirmBox.html(confirmContent);
355  }
356  });
357  });
358  });
359 '."\n";
getParameterByName
getParameterByName(name, valueifnotfound)
Definition: lib_head.js.php:1071
fail
if(empty($user->rights->takepos->run) &&!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) if((getDolGlobalString('TAKEPOS_PHONE_BASIC_LAYOUT')==1 && $conf->browser->layout=='phone')||defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) fail($message)
Abort invoice creationg with a given error message.
Definition: invoice.php:111
top_httphead
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1407
dol_escape_js
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
Definition: functions.lib.php:1423