From cd4225aee06fd8ec085a19d354eaa901acd2fd89 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Thu, 21 Jan 2021 09:45:09 +0100 Subject: [PATCH 01/12] Fix #16027 New Feature copy Code Client --- htdocs/societe/card.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 0d8a92c1cf3..342ee1b8ee3 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -2423,8 +2423,29 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) if ($object->client) { print ''; - print $langs->trans('CustomerCode').''; - print $object->code_client; + print $langs->trans('CustomerCode').''; + print ""; + print ''; + print $object->code_client .''; $tmpcheck = $object->check_codeclient(); if ($tmpcheck != 0 && $tmpcheck != -5) { print ' ('.$langs->trans("WrongCustomerCode").')'; From b2809e4ee25c671171b878eaa3abfc8f1d717181 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Thu, 21 Jan 2021 09:54:26 +0100 Subject: [PATCH 02/12] add trans to copied to clipboard text --- htdocs/langs/en_US/companies.lang | 1 + htdocs/societe/card.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/langs/en_US/companies.lang b/htdocs/langs/en_US/companies.lang index 99bed13179f..e0381d6fdef 100644 --- a/htdocs/langs/en_US/companies.lang +++ b/htdocs/langs/en_US/companies.lang @@ -467,3 +467,4 @@ RestOfEurope=Rest of Europe (EEC) OutOfEurope=Out of Europe (EEC) CurrentOutstandingBillLate=Current outstanding bill late BecarefullChangeThirdpartyBeforeAddProductToInvoice=Be carefull, depending on your product price settings, you should change thirdparty before adding product to POS. +CopiedToClipboard = Copied to clipboard \ No newline at end of file diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 342ee1b8ee3..75771f3d419 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -2438,10 +2438,10 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) selection.addRange( range ); } - + document.execCommand( 'copy' ); window.getSelection().removeAllRanges(); - document.getElementById( \"clipboardChar\" ).innerHTML = 'Copied to clipboard!'; + document.getElementById( \"clipboardChar\" ).innerHTML = '".$langs->trans("CopiedToClipboard")."'; } "; print ''; From 5e67e11eb3aa7e8afe04f9e2775c42c241a5d4b8 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Thu, 21 Jan 2021 17:15:32 +0100 Subject: [PATCH 03/12] update societe/card.php clipboard copy in fonction --- htdocs/societe/card.php | 68 ++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 75771f3d419..511bde61bcf 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -2408,7 +2408,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) if (!empty($conf->fournisseur->enabled) || !empty($conf->supplier_proposal->enabled)) { print ''.$langs->trans('Supplier').''; - print yn($object->fournisseur); + print showValueWithCopyAndPasteButton(yn($object->fournisseur),'supplier',$langs); print ''; } @@ -2423,29 +2423,11 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) if ($object->client) { print ''; - print $langs->trans('CustomerCode').''; - print ""; - print ''; - print $object->code_client .''; + print $langs->trans('CustomerCode'); + print ''; + print ''; + print showValueWithCopyAndPasteButton($object->code_client, 'code_client',$langs); + print ''; $tmpcheck = $object->check_codeclient(); if ($tmpcheck != 0 && $tmpcheck != -5) { print ' ('.$langs->trans("WrongCustomerCode").')'; @@ -2957,7 +2939,43 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; } } - +/** + * @param string $valuetoprint the value to print + * @param string $spanid unique id for a span + * @param Translate $langs the $langs variable + * @return string the string to print for the button + */ +function showValueWithCopyAndPasteButton($valuetoprint,$spanid,$langs){ + $stringtoprint= ''; + $stringtoprint.= $valuetoprint .' '; + $stringtoprint.= ''; + $stringtoprint.=''; + $stringtoprint.=""; + return $stringtoprint; +} // End of page llxFooter(); $db->close(); + From 006fbb18588b11bdcb0bb50edfc2d5a8c68c4312 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 21 Jan 2021 16:16:14 +0000 Subject: [PATCH 04/12] Fixing style errors. --- htdocs/societe/card.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 511bde61bcf..567cd8483ba 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -2408,7 +2408,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) if (!empty($conf->fournisseur->enabled) || !empty($conf->supplier_proposal->enabled)) { print ''.$langs->trans('Supplier').''; - print showValueWithCopyAndPasteButton(yn($object->fournisseur),'supplier',$langs); + print showValueWithCopyAndPasteButton(yn($object->fournisseur), 'supplier', $langs); print ''; } @@ -2426,7 +2426,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print $langs->trans('CustomerCode'); print ''; print ''; - print showValueWithCopyAndPasteButton($object->code_client, 'code_client',$langs); + print showValueWithCopyAndPasteButton($object->code_client, 'code_client', $langs); print ''; $tmpcheck = $object->check_codeclient(); if ($tmpcheck != 0 && $tmpcheck != -5) { @@ -2945,7 +2945,8 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) * @param Translate $langs the $langs variable * @return string the string to print for the button */ -function showValueWithCopyAndPasteButton($valuetoprint,$spanid,$langs){ +function showValueWithCopyAndPasteButton($valuetoprint, $spanid, $langs) +{ $stringtoprint= ''; $stringtoprint.= $valuetoprint .' '; $stringtoprint.= ''; @@ -2978,4 +2979,3 @@ function showValueWithCopyAndPasteButton($valuetoprint,$spanid,$langs){ // End of page llxFooter(); $db->close(); - From 59d2d021514c66c6b09a0ad3a894255854b5b069 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Thu, 21 Jan 2021 17:17:10 +0100 Subject: [PATCH 05/12] removing my tests --- htdocs/societe/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 511bde61bcf..bc4aaf3e864 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -2408,7 +2408,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) if (!empty($conf->fournisseur->enabled) || !empty($conf->supplier_proposal->enabled)) { print ''.$langs->trans('Supplier').''; - print showValueWithCopyAndPasteButton(yn($object->fournisseur),'supplier',$langs); + print yn($object->fournisseur); print ''; } From 64d08544b29323dc86b19303fe21a4cddac0aa1b Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Fri, 22 Jan 2021 09:09:46 +0100 Subject: [PATCH 06/12] move of function showValueWithCopyPasteButton in function.lib.php --- htdocs/core/lib/functions.lib.php | 39 +++++++++++++++++++++++++++++++ htdocs/societe/card.php | 37 ----------------------------- 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index c146f1f9a47..dcdff379cc0 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -9231,3 +9231,42 @@ function readfileLowMemory($fullpath_original_file_osencoded, $method = -1) fclose($handle2); } } + +/** + * Create a button to copy $valuetoprint in the clipboard + * @param string $valuetoprint the value to print + * @param string $spanid unique id for a span + * @param Translate $langs the $langs variable + * @return string the string to print for the button + */ +function showValueWithCopyAndPasteButton($valuetoprint, $spanid, $langs) +{ + $stringtoprint= ''; + $stringtoprint.= $valuetoprint .' '; + $stringtoprint.= ''; + $stringtoprint.=''; + $stringtoprint.=""; + return $stringtoprint; +} \ No newline at end of file diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index b25b7bf73b8..0014e4b8ebe 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -2939,43 +2939,6 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; } } -/** - * @param string $valuetoprint the value to print - * @param string $spanid unique id for a span - * @param Translate $langs the $langs variable - * @return string the string to print for the button - */ -function showValueWithCopyAndPasteButton($valuetoprint, $spanid, $langs) -{ - $stringtoprint= ''; - $stringtoprint.= $valuetoprint .' '; - $stringtoprint.= ''; - $stringtoprint.=''; - $stringtoprint.=""; - return $stringtoprint; -} // End of page llxFooter(); $db->close(); From 76ce77f7ba93867aa7fd61116be88769dc17837a Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Fri, 22 Jan 2021 09:13:04 +0100 Subject: [PATCH 07/12] stickler-ci edit --- htdocs/core/lib/functions.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index dcdff379cc0..d8a1614cfdc 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -9269,4 +9269,4 @@ function showValueWithCopyAndPasteButton($valuetoprint, $spanid, $langs) } "; return $stringtoprint; -} \ No newline at end of file +} From 5a95cc16aa6edd8c219b2b74c2f104bc87546677 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Fri, 22 Jan 2021 16:58:47 +0100 Subject: [PATCH 08/12] update clipboardcopypaste with jquery --- htdocs/core/js/lib_foot.js.php | 22 +++++++++++++++++++++ htdocs/core/lib/functions.lib.php | 33 ++++--------------------------- htdocs/societe/card.php | 2 +- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/htdocs/core/js/lib_foot.js.php b/htdocs/core/js/lib_foot.js.php index 9f4e69dcadf..66a57502bb1 100644 --- a/htdocs/core/js/lib_foot.js.php +++ b/htdocs/core/js/lib_foot.js.php @@ -210,3 +210,25 @@ print ' } }); });'."\n"; + +print "\n/* JS CODE TO ENABLE ClipBoard copy paste*/\n"; +print 'jQuery(\'.clipboardCopyPaste\').click(function() { + console.log(this.firstChild.innerText); + if ( window.getSelection ) { + + selection = window.getSelection(); + + range = document.createRange(); + range.selectNodeContents( this.firstChild ); + + selection.removeAllRanges(); + selection.addRange( range ); + + } + document.execCommand( \'copy\' ); + window.getSelection().removeAllRanges(); + var lastchild = this.lastChild + var tmp =lastchild.innerHTML + lastchild.innerHTML = \''.dol_escape_js($langs->trans('CopiedToClipboard')).'\'; + setTimeout(() => { lastchild.innerHTML = tmp; }, 1000); + })'."\n"; \ No newline at end of file diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index d8a1614cfdc..d90e70a1e0c 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -9239,34 +9239,9 @@ function readfileLowMemory($fullpath_original_file_osencoded, $method = -1) * @param Translate $langs the $langs variable * @return string the string to print for the button */ -function showValueWithCopyAndPasteButton($valuetoprint, $spanid, $langs) +function showValueWithCopyAndPasteButton($valuetoprint) { - $stringtoprint= ''; - $stringtoprint.= $valuetoprint .' '; - $stringtoprint.= ''; - $stringtoprint.=''; - $stringtoprint.=""; - return $stringtoprint; + return ''.dol_escape_js($valuetoprint).' + '; + } diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 0014e4b8ebe..caf3b62bd02 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -2426,7 +2426,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print $langs->trans('CustomerCode'); print ''; print ''; - print showValueWithCopyAndPasteButton($object->code_client, 'code_client', $langs); + print showValueWithCopyAndPasteButton($object->code_client); print ''; $tmpcheck = $object->check_codeclient(); if ($tmpcheck != 0 && $tmpcheck != -5) { From 3de89be6911088382ea1dd0d128967c029641e69 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 22 Jan 2021 15:59:31 +0000 Subject: [PATCH 09/12] Fixing style errors. --- htdocs/core/js/lib_foot.js.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/js/lib_foot.js.php b/htdocs/core/js/lib_foot.js.php index 66a57502bb1..c277beefe70 100644 --- a/htdocs/core/js/lib_foot.js.php +++ b/htdocs/core/js/lib_foot.js.php @@ -231,4 +231,4 @@ print 'jQuery(\'.clipboardCopyPaste\').click(function() { var tmp =lastchild.innerHTML lastchild.innerHTML = \''.dol_escape_js($langs->trans('CopiedToClipboard')).'\'; setTimeout(() => { lastchild.innerHTML = tmp; }, 1000); - })'."\n"; \ No newline at end of file + })'."\n"; From 7685dee5f662b8a7c1afe4fe8f5ca4c962e6abe4 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Fri, 22 Jan 2021 16:59:34 +0100 Subject: [PATCH 10/12] style changes --- htdocs/core/js/lib_foot.js.php | 2 +- htdocs/core/lib/functions.lib.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/js/lib_foot.js.php b/htdocs/core/js/lib_foot.js.php index 66a57502bb1..c277beefe70 100644 --- a/htdocs/core/js/lib_foot.js.php +++ b/htdocs/core/js/lib_foot.js.php @@ -231,4 +231,4 @@ print 'jQuery(\'.clipboardCopyPaste\').click(function() { var tmp =lastchild.innerHTML lastchild.innerHTML = \''.dol_escape_js($langs->trans('CopiedToClipboard')).'\'; setTimeout(() => { lastchild.innerHTML = tmp; }, 1000); - })'."\n"; \ No newline at end of file + })'."\n"; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index d90e70a1e0c..daa6d660f9f 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -9243,5 +9243,5 @@ function showValueWithCopyAndPasteButton($valuetoprint) { return ''.dol_escape_js($valuetoprint).' '; - + } From cfcd51f291b5fe5054898cbfab5ba7836db778c7 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Fri, 22 Jan 2021 17:03:39 +0100 Subject: [PATCH 11/12] style errors update --- htdocs/core/lib/functions.lib.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index daa6d660f9f..181e6b4c448 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -9235,13 +9235,10 @@ function readfileLowMemory($fullpath_original_file_osencoded, $method = -1) /** * Create a button to copy $valuetoprint in the clipboard * @param string $valuetoprint the value to print - * @param string $spanid unique id for a span - * @param Translate $langs the $langs variable * @return string the string to print for the button */ function showValueWithCopyAndPasteButton($valuetoprint) { return ''.dol_escape_js($valuetoprint).' '; - } From 4d5cda20e73a6e8e0ebe9c87bdbbbee9a4990c72 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 28 Jan 2021 11:15:11 +0100 Subject: [PATCH 12/12] Update functions.lib.php --- htdocs/core/lib/functions.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 181e6b4c448..9d888c56cc0 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -9239,6 +9239,6 @@ function readfileLowMemory($fullpath_original_file_osencoded, $method = -1) */ function showValueWithCopyAndPasteButton($valuetoprint) { - return ''.dol_escape_js($valuetoprint).' - '; + $result = ''.$valuetoprint.''; + return $result; }