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