From 76038e692dad59196d9b8e4789a836c57c9dce4b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 4 Aug 2021 20:07:12 +0200 Subject: [PATCH] NEW Use an ajax call for the clicktodial feature instead of href link. --- htdocs/core/js/lib_foot.js.php | 190 ++++++++++++++++------------- htdocs/core/lib/admin.lib.php | 2 + htdocs/core/lib/functions.lib.php | 15 ++- htdocs/core/lib/functions2.lib.php | 4 +- 4 files changed, 122 insertions(+), 89 deletions(-) diff --git a/htdocs/core/js/lib_foot.js.php b/htdocs/core/js/lib_foot.js.php index 00f161a31ef..74a7f543bfc 100644 --- a/htdocs/core/js/lib_foot.js.php +++ b/htdocs/core/js/lib_foot.js.php @@ -102,8 +102,7 @@ print "});\n"; // Wrapper to manage dropdown if (!defined('JS_JQUERY_DISABLE_DROPDOWN')) { print "\n/* JS CODE TO ENABLE dropdown (hamburger, linkto, ...) */\n"; - print ' - jQuery(document).ready(function () { + print ' jQuery(document).ready(function () { var lastopendropdown = null; // Click onto the link "link to" or "hamburger", toggle dropdown @@ -171,21 +170,19 @@ if (!defined('JS_JQUERY_DISABLE_DROPDOWN')) { // Wrapper to manage document_preview if ($conf->browser->layout != 'phone') { print "\n/* JS CODE TO ENABLE document_preview */\n"; // Function document_preview is into header - print ' - jQuery(document).ready(function () { + print ' jQuery(document).ready(function () { jQuery(".documentpreview").click(function () { console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\')); document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), \''.dol_escape_js($langs->transnoentities("Preview")).'\'); return false; }); - }); - ' . "\n"; + });'."\n"; } // Code to manage reposition print "\n/* JS CODE TO ENABLE reposition management (does not work if a redirect is done after action of submission) */\n"; print ' - jQuery(document).ready(function() { + jQuery(document).ready(function() { /* If page_y set, we set scollbar with it */ page_y=getParameterByName(\'page_y\', 0); /* search in GET parameter */ if (page_y == 0) page_y = jQuery("#page_y").text(); /* search in POST parameter that is filed at bottom of page */ @@ -216,96 +213,123 @@ print ' } } }); - });'."\n"; + });'."\n"; -print "\n/* JS CODE TO ENABLE ClipBoard copy paste*/\n"; -print 'jQuery(\'.clipboardCPShowOnHover\').hover( - function() { - console.log("We hover a value with a copy paste feature"); - $(this).children(".clipboardCPButton, .clipboardCPText").show(); - }, - function() { - console.log("We hover out the value with a copy paste feature"); - $(this).children(".clipboardCPButton, .clipboardCPText").hide(); - } - );'; -print 'jQuery(\'.clipboardCPButton, .clipboardCPValueToPrint\').click(function() { - /* console.log(this.parentNode); */ - console.log("We click on a clipboardCPButton or clipboardCPValueToPrint class"); - if (window.getSelection) { - selection = window.getSelection(); +// Code to manage Copy To Clipboard click +print "\n/* JS CODE TO ENABLE ClipBoard copy paste */\n"; +print ' + jQuery(document).ready(function() { + jQuery(\'.clipboardCPShowOnHover\').hover( + function() { + console.log("We hover a value with a copy paste feature"); + $(this).children(".clipboardCPButton, .clipboardCPText").show(); + }, + function() { + console.log("We hover out the value with a copy paste feature"); + $(this).children(".clipboardCPButton, .clipboardCPText").hide(); + } + ); - range = document.createRange(); - range.selectNodeContents(this.parentNode.firstChild); + jQuery(\'.clipboardCPButton, .clipboardCPValueToPrint\').click(function() { + /* console.log(this.parentNode); */ + console.log("We click on a clipboardCPButton or clipboardCPValueToPrint class"); + if (window.getSelection) { + selection = window.getSelection(); - selection.removeAllRanges(); - selection.addRange( range ); - } - document.execCommand( \'copy\' ); - window.getSelection().removeAllRanges(); + range = document.createRange(); + range.selectNodeContents(this.parentNode.firstChild); - /* Show message */ - var lastchild = this.parentNode.lastChild; - var tmp = lastchild.innerHTML - lastchild.innerHTML = \''.dol_escape_js($langs->trans('CopiedToClipboard')).'\'; - setTimeout(() => { lastchild.innerHTML = tmp; }, 1000); - })'."\n"; + selection.removeAllRanges(); + selection.addRange( range ); + } + document.execCommand( \'copy\' ); + window.getSelection().removeAllRanges(); + + /* Show message */ + var lastchild = this.parentNode.lastChild; + var tmp = lastchild.innerHTML + lastchild.innerHTML = \''.dol_escape_js($langs->trans('CopiedToClipboard')).'\'; + setTimeout(() => { lastchild.innerHTML = tmp; }, 1000); + }); + });'."\n"; + +// Code to manage clicktodial +print "\n/* JS CODE TO ENABLE clicktodial call of an URL */\n"; +print ' + jQuery(document).ready(function() { + jQuery(".cssforclicktodial").click(function() { + event.preventDefault(); + console.log("We click on a cssforclicktodial class with url="+this.href); + $.ajax({ + url: this.href, + type: \'GET\', + data: { token: \''.newToken().'\' } + }).done(function(xhr, textStatus, errorThrown) { + /* do nothing */ + }).fail(function(xhr, textStatus, errorThrown) { + alert("Error: "+textStatus); + }); + return false; + }); + });'."\n"; +// Code to manage the confirm dialog box print "\n/* JS CODE TO ENABLE DIALOG CONFIRM POPUP ON ACTION BUTTON */\n"; -print '$( document ).ready(function() { - $(document).on("click", \'.butActionConfirm\', function(event) { - event.preventDefault(); +print ' + jQuery(document).ready(function() { + $(document).on("click", \'.butActionConfirm\', function(event) { + event.preventDefault(); - // I don\'t use jquery $(this).data(\'confirm-url\'); to get $(this).attr(\'data-confirm-url\'); because .data() can doesn\'t work with ajax - var confirmUrl = $(this).attr(\'data-confirm-url\'); - var confirmTitle = $(this).attr(\'data-confirm-title\'); - var confirmContent = $(this).attr(\'data-confirm-content\'); - var confirmActionBtnLabel = $(this).attr(\'data-confirm-action-btn-label\'); - var confirmCancelBtnLabel = $(this).attr(\'data-confirm-cancel-btn-label\'); - var confirmModal = $(this).attr(\'data-confirm-modal\'); - if(confirmModal == undefined){ confirmModal = false; } + // I don\'t use jquery $(this).data(\'confirm-url\'); to get $(this).attr(\'data-confirm-url\'); because .data() can doesn\'t work with ajax + var confirmUrl = $(this).attr(\'data-confirm-url\'); + var confirmTitle = $(this).attr(\'data-confirm-title\'); + var confirmContent = $(this).attr(\'data-confirm-content\'); + var confirmActionBtnLabel = $(this).attr(\'data-confirm-action-btn-label\'); + var confirmCancelBtnLabel = $(this).attr(\'data-confirm-cancel-btn-label\'); + var confirmModal = $(this).attr(\'data-confirm-modal\'); + if(confirmModal == undefined){ confirmModal = false; } - var confirmId = \'confirm-dialog-box\'; - if($(this).attr(\'id\') != undefined){ var confirmId = confirmId + "-" + $(this).attr(\'id\'); } - if($("#" + confirmId) != undefined) { $(\'#\' + confirmId).remove(); } + var confirmId = \'confirm-dialog-box\'; + if($(this).attr(\'id\') != undefined){ var confirmId = confirmId + "-" + $(this).attr(\'id\'); } + if($("#" + confirmId) != undefined) { $(\'#\' + confirmId).remove(); } - // Create modal box + // Create modal box - var $confirmBox = $(\'
\', { - id: confirmId, - title: confirmTitle - }).appendTo(\'body\'); + var $confirmBox = $(\'
\', { + id: confirmId, + title: confirmTitle + }).appendTo(\'body\'); - $confirmBox.dialog({ - autoOpen: true, - modal: confirmModal, - //width: Math.min($( window ).width() - 50, 1700), - width: \'auto\', - dialogClass: \'confirm-dialog-box\', - buttons: [ - { - text: confirmActionBtnLabel, - "class": \'ui-state-information\', - click: function () { - window.location.replace(confirmUrl); - } + $confirmBox.dialog({ + autoOpen: true, + modal: confirmModal, + //width: Math.min($( window ).width() - 50, 1700), + width: \'auto\', + dialogClass: \'confirm-dialog-box\', + buttons: [ + { + text: confirmActionBtnLabel, + "class": \'ui-state-information\', + click: function () { + window.location.replace(confirmUrl); + } + }, + { + text: confirmCancelBtnLabel, + "class": \'ui-state-information\', + click: function () { + $(this).dialog("close"); + } + } + ], + close: function( event, ui ) { + $(\'#\'+confirmBox).remove(); }, - { - text: confirmCancelBtnLabel, - "class": \'ui-state-information\', - click: function () { - $(this).dialog("close"); + open: function( event, ui ) { + $confirmBox.html(confirmContent); } - } - ], - close: function( event, ui ) { - $(\'#\'+confirmBox).remove(); - }, - open: function( event, ui ) { - $confirmBox.html(confirmContent); - } + }); }); }); -}); '."\n"; diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index ae260171a0b..683b92fb8d9 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -123,6 +123,7 @@ function versioncompare($versionarray1, $versionarray2) * Return version PHP * * @return array Tableau de version (vermajeur,vermineur,autre) + * @see versioncompare() */ function versionphparray() { @@ -133,6 +134,7 @@ function versionphparray() * Return version Dolibarr * * @return array Tableau de version (vermajeur,vermineur,autre) + * @see versioncompare() */ function versiondolibarrarray() { diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 62f4006c1de..899b3b0ffda 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3054,11 +3054,18 @@ function dol_print_phone($phone, $countrycode = '', $cid = 0, $socid = 0, $addli '__PASS__'=>$clicktodial_password); $url = make_substitutions($url, $substitarray); $newphonesav = $newphone; - $newphone = 'global->CLICKTODIAL_FORCENEWTARGET)) { - $newphone .= ' target="_blank"'; + if (empty($conf->global->CLICKTODIAL_DO_NOT_USE_AJAX_CALL)) { + // Default and recommended: New method using ajax without submiting a page making a javascript history.go(-1) back + $newphone = ''; + } else { + // Old method + $newphone = 'global->CLICKTODIAL_FORCENEWTARGET)) { + $newphone .= ' target="_blank"'; + } + $newphone .= '>'.$newphonesav.''; } - $newphone .= '>'.$newphonesav.''; } //if (($cid || $socid) && ! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create) diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 0035688c66f..d79f688391d 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -1876,7 +1876,7 @@ function version_os($option = '') * Return PHP version * * @return string PHP version - * @see versionphparray() + * @see versionphparray(), versioncompare() */ function version_php() { @@ -1887,7 +1887,7 @@ function version_php() * Return Dolibarr version * * @return string Dolibarr version - * @see versiondolibarrarray() + * @see versiondolibarrarray(), versioncompare() */ function version_dolibarr() {