NEW Use an ajax call for the clicktodial feature instead of href link.

This commit is contained in:
Laurent Destailleur 2021-08-04 20:07:12 +02:00
parent 0de10cea39
commit 76038e692d
4 changed files with 122 additions and 89 deletions

View File

@ -102,8 +102,7 @@ print "});\n";
// Wrapper to manage dropdown // Wrapper to manage dropdown
if (!defined('JS_JQUERY_DISABLE_DROPDOWN')) { if (!defined('JS_JQUERY_DISABLE_DROPDOWN')) {
print "\n/* JS CODE TO ENABLE dropdown (hamburger, linkto, ...) */\n"; print "\n/* JS CODE TO ENABLE dropdown (hamburger, linkto, ...) */\n";
print ' print ' jQuery(document).ready(function () {
jQuery(document).ready(function () {
var lastopendropdown = null; var lastopendropdown = null;
// Click onto the link "link to" or "hamburger", toggle dropdown // 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 // Wrapper to manage document_preview
if ($conf->browser->layout != 'phone') { if ($conf->browser->layout != 'phone') {
print "\n/* JS CODE TO ENABLE document_preview */\n"; // Function document_preview is into header print "\n/* JS CODE TO ENABLE document_preview */\n"; // Function document_preview is into header
print ' print ' jQuery(document).ready(function () {
jQuery(document).ready(function () {
jQuery(".documentpreview").click(function () { jQuery(".documentpreview").click(function () {
console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\')); 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")).'\'); document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), \''.dol_escape_js($langs->transnoentities("Preview")).'\');
return false; return false;
}); });
}); });'."\n";
' . "\n";
} }
// Code to manage reposition // 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 "\n/* JS CODE TO ENABLE reposition management (does not work if a redirect is done after action of submission) */\n";
print ' print '
jQuery(document).ready(function() { jQuery(document).ready(function() {
/* If page_y set, we set scollbar with it */ /* If page_y set, we set scollbar with it */
page_y=getParameterByName(\'page_y\', 0); /* search in GET parameter */ 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 */ 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"; // Code to manage Copy To Clipboard click
print 'jQuery(\'.clipboardCPShowOnHover\').hover( print "\n/* JS CODE TO ENABLE ClipBoard copy paste */\n";
function() { print '
console.log("We hover a value with a copy paste feature"); jQuery(document).ready(function() {
$(this).children(".clipboardCPButton, .clipboardCPText").show(); jQuery(\'.clipboardCPShowOnHover\').hover(
}, function() {
function() { console.log("We hover a value with a copy paste feature");
console.log("We hover out the value with a copy paste feature"); $(this).children(".clipboardCPButton, .clipboardCPText").show();
$(this).children(".clipboardCPButton, .clipboardCPText").hide(); },
} function() {
);'; console.log("We hover out the value with a copy paste feature");
print 'jQuery(\'.clipboardCPButton, .clipboardCPValueToPrint\').click(function() { $(this).children(".clipboardCPButton, .clipboardCPText").hide();
/* console.log(this.parentNode); */ }
console.log("We click on a clipboardCPButton or clipboardCPValueToPrint class"); );
if (window.getSelection) {
selection = window.getSelection();
range = document.createRange(); jQuery(\'.clipboardCPButton, .clipboardCPValueToPrint\').click(function() {
range.selectNodeContents(this.parentNode.firstChild); /* console.log(this.parentNode); */
console.log("We click on a clipboardCPButton or clipboardCPValueToPrint class");
if (window.getSelection) {
selection = window.getSelection();
selection.removeAllRanges(); range = document.createRange();
selection.addRange( range ); range.selectNodeContents(this.parentNode.firstChild);
}
document.execCommand( \'copy\' );
window.getSelection().removeAllRanges();
/* Show message */ selection.removeAllRanges();
var lastchild = this.parentNode.lastChild; selection.addRange( range );
var tmp = lastchild.innerHTML }
lastchild.innerHTML = \''.dol_escape_js($langs->trans('CopiedToClipboard')).'\'; document.execCommand( \'copy\' );
setTimeout(() => { lastchild.innerHTML = tmp; }, 1000); window.getSelection().removeAllRanges();
})'."\n";
/* 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 "\n/* JS CODE TO ENABLE DIALOG CONFIRM POPUP ON ACTION BUTTON */\n";
print '$( document ).ready(function() { print '
$(document).on("click", \'.butActionConfirm\', function(event) { jQuery(document).ready(function() {
event.preventDefault(); $(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 // 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 confirmUrl = $(this).attr(\'data-confirm-url\');
var confirmTitle = $(this).attr(\'data-confirm-title\'); var confirmTitle = $(this).attr(\'data-confirm-title\');
var confirmContent = $(this).attr(\'data-confirm-content\'); var confirmContent = $(this).attr(\'data-confirm-content\');
var confirmActionBtnLabel = $(this).attr(\'data-confirm-action-btn-label\'); var confirmActionBtnLabel = $(this).attr(\'data-confirm-action-btn-label\');
var confirmCancelBtnLabel = $(this).attr(\'data-confirm-cancel-btn-label\'); var confirmCancelBtnLabel = $(this).attr(\'data-confirm-cancel-btn-label\');
var confirmModal = $(this).attr(\'data-confirm-modal\'); var confirmModal = $(this).attr(\'data-confirm-modal\');
if(confirmModal == undefined){ confirmModal = false; } if(confirmModal == undefined){ confirmModal = false; }
var confirmId = \'confirm-dialog-box\'; var confirmId = \'confirm-dialog-box\';
if($(this).attr(\'id\') != undefined){ var confirmId = confirmId + "-" + $(this).attr(\'id\'); } if($(this).attr(\'id\') != undefined){ var confirmId = confirmId + "-" + $(this).attr(\'id\'); }
if($("#" + confirmId) != undefined) { $(\'#\' + confirmId).remove(); } if($("#" + confirmId) != undefined) { $(\'#\' + confirmId).remove(); }
// Create modal box // Create modal box
var $confirmBox = $(\'<div/>\', { var $confirmBox = $(\'<div/>\', {
id: confirmId, id: confirmId,
title: confirmTitle title: confirmTitle
}).appendTo(\'body\'); }).appendTo(\'body\');
$confirmBox.dialog({ $confirmBox.dialog({
autoOpen: true, autoOpen: true,
modal: confirmModal, modal: confirmModal,
//width: Math.min($( window ).width() - 50, 1700), //width: Math.min($( window ).width() - 50, 1700),
width: \'auto\', width: \'auto\',
dialogClass: \'confirm-dialog-box\', dialogClass: \'confirm-dialog-box\',
buttons: [ buttons: [
{ {
text: confirmActionBtnLabel, text: confirmActionBtnLabel,
"class": \'ui-state-information\', "class": \'ui-state-information\',
click: function () { click: function () {
window.location.replace(confirmUrl); window.location.replace(confirmUrl);
} }
},
{
text: confirmCancelBtnLabel,
"class": \'ui-state-information\',
click: function () {
$(this).dialog("close");
}
}
],
close: function( event, ui ) {
$(\'#\'+confirmBox).remove();
}, },
{ open: function( event, ui ) {
text: confirmCancelBtnLabel, $confirmBox.html(confirmContent);
"class": \'ui-state-information\',
click: function () {
$(this).dialog("close");
} }
} });
],
close: function( event, ui ) {
$(\'#\'+confirmBox).remove();
},
open: function( event, ui ) {
$confirmBox.html(confirmContent);
}
}); });
}); });
});
'."\n"; '."\n";

View File

@ -123,6 +123,7 @@ function versioncompare($versionarray1, $versionarray2)
* Return version PHP * Return version PHP
* *
* @return array Tableau de version (vermajeur,vermineur,autre) * @return array Tableau de version (vermajeur,vermineur,autre)
* @see versioncompare()
*/ */
function versionphparray() function versionphparray()
{ {
@ -133,6 +134,7 @@ function versionphparray()
* Return version Dolibarr * Return version Dolibarr
* *
* @return array Tableau de version (vermajeur,vermineur,autre) * @return array Tableau de version (vermajeur,vermineur,autre)
* @see versioncompare()
*/ */
function versiondolibarrarray() function versiondolibarrarray()
{ {

View File

@ -3054,11 +3054,18 @@ function dol_print_phone($phone, $countrycode = '', $cid = 0, $socid = 0, $addli
'__PASS__'=>$clicktodial_password); '__PASS__'=>$clicktodial_password);
$url = make_substitutions($url, $substitarray); $url = make_substitutions($url, $substitarray);
$newphonesav = $newphone; $newphonesav = $newphone;
$newphone = '<a href="'.$url.'"'; if (empty($conf->global->CLICKTODIAL_DO_NOT_USE_AJAX_CALL)) {
if (!empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) { // Default and recommended: New method using ajax without submiting a page making a javascript history.go(-1) back
$newphone .= ' target="_blank"'; $newphone = '<a href="'.$url.'" class="cssforclicktodial"'; // Call of ajax is handled by the lib_foot.js.php on class 'cssforclicktodial'
$newphone .= '>'.$newphonesav.'</a>';
} else {
// Old method
$newphone = '<a href="'.$url.'"';
if (!empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) {
$newphone .= ' target="_blank"';
}
$newphone .= '>'.$newphonesav.'</a>';
} }
$newphone .= '>'.$newphonesav.'</a>';
} }
//if (($cid || $socid) && ! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create) //if (($cid || $socid) && ! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)

View File

@ -1876,7 +1876,7 @@ function version_os($option = '')
* Return PHP version * Return PHP version
* *
* @return string PHP version * @return string PHP version
* @see versionphparray() * @see versionphparray(), versioncompare()
*/ */
function version_php() function version_php()
{ {
@ -1887,7 +1887,7 @@ function version_php()
* Return Dolibarr version * Return Dolibarr version
* *
* @return string Dolibarr version * @return string Dolibarr version
* @see versiondolibarrarray() * @see versiondolibarrarray(), versioncompare()
*/ */
function version_dolibarr() function version_dolibarr()
{ {