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,15 +170,13 @@ 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
@ -218,8 +215,11 @@ print '
}); });
});'."\n"; });'."\n";
// Code to manage Copy To Clipboard click
print "\n/* JS CODE TO ENABLE ClipBoard copy paste */\n"; print "\n/* JS CODE TO ENABLE ClipBoard copy paste */\n";
print 'jQuery(\'.clipboardCPShowOnHover\').hover( print '
jQuery(document).ready(function() {
jQuery(\'.clipboardCPShowOnHover\').hover(
function() { function() {
console.log("We hover a value with a copy paste feature"); console.log("We hover a value with a copy paste feature");
$(this).children(".clipboardCPButton, .clipboardCPText").show(); $(this).children(".clipboardCPButton, .clipboardCPText").show();
@ -228,8 +228,9 @@ print 'jQuery(\'.clipboardCPShowOnHover\').hover(
console.log("We hover out the value with a copy paste feature"); console.log("We hover out the value with a copy paste feature");
$(this).children(".clipboardCPButton, .clipboardCPText").hide(); $(this).children(".clipboardCPButton, .clipboardCPText").hide();
} }
);'; );
print 'jQuery(\'.clipboardCPButton, .clipboardCPValueToPrint\').click(function() {
jQuery(\'.clipboardCPButton, .clipboardCPValueToPrint\').click(function() {
/* console.log(this.parentNode); */ /* console.log(this.parentNode); */
console.log("We click on a clipboardCPButton or clipboardCPValueToPrint class"); console.log("We click on a clipboardCPButton or clipboardCPValueToPrint class");
if (window.getSelection) { if (window.getSelection) {
@ -249,11 +250,34 @@ print 'jQuery(\'.clipboardCPButton, .clipboardCPValueToPrint\').click(function()
var tmp = lastchild.innerHTML var tmp = lastchild.innerHTML
lastchild.innerHTML = \''.dol_escape_js($langs->trans('CopiedToClipboard')).'\'; lastchild.innerHTML = \''.dol_escape_js($langs->trans('CopiedToClipboard')).'\';
setTimeout(() => { lastchild.innerHTML = tmp; }, 1000); setTimeout(() => { lastchild.innerHTML = tmp; }, 1000);
})'."\n"; });
});'."\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 '
jQuery(document).ready(function() {
$(document).on("click", \'.butActionConfirm\', function(event) { $(document).on("click", \'.butActionConfirm\', function(event) {
event.preventDefault(); event.preventDefault();

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,12 +3054,19 @@ 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;
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 = '<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.'"'; $newphone = '<a href="'.$url.'"';
if (!empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) { if (!empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) {
$newphone .= ' target="_blank"'; $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)
if (!empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create) { if (!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()
{ {