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