diff --git a/htdocs/core/js/lib_foot.js.php b/htdocs/core/js/lib_foot.js.php index 9f4e69dcadf..c277beefe70 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"; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 6d0df215220..989609ba65c 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -9239,3 +9239,14 @@ 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 + * @return string the string to print for the button + */ +function showValueWithCopyAndPasteButton($valuetoprint) +{ + $result = ''.$valuetoprint.''; + return $result; +} 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 9d145957040..0347efa7411 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -2423,8 +2423,11 @@ 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 showValueWithCopyAndPasteButton($object->code_client); + print ''; $tmpcheck = $object->check_codeclient(); if ($tmpcheck != 0 && $tmpcheck != -5) { print ' ('.$langs->trans("WrongCustomerCode").')'; @@ -2935,7 +2938,6 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; } } - // End of page llxFooter(); $db->close();