From 5a4086d6792399bc30ef906b3629a91dd05392a6 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 22:16:16 -0300 Subject: [PATCH 01/11] Improvements to "Copy to Clipboard" wrapper --- js/clipboard.js | 54 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/js/clipboard.js b/js/clipboard.js index 503e17eb741..f9d3475b8a0 100644 --- a/js/clipboard.js +++ b/js/clipboard.js @@ -35,28 +35,49 @@ $(function() { // set a function to track drag hover event $(document).on("click", ".copy_to_clipboard_wrapper", function(event) { + var succeed; // find the good element var target = $(event.target); - if (target.attr('class') == 'copy_to_clipboard_wrapper') { - target = target.find('*'); + // click on 'copy button' + if (target.hasClass('input-group-text') || target.is('input')) { + target = target.parent('.copy_to_clipboard_wrapper').find('input'); + + // copy text + succeed = copyTextToClipboard(target.val()); + } else { + if (target.attr('class') == 'copy_to_clipboard_wrapper') { + target = target.find('*'); + } + + // copy text + target.select(); + try { + succeed = document.execCommand("copy"); + } catch (e) { + succeed = false; + } + target.blur(); } - // copy text - target.select(); - var succeed; - try { - succeed = document.execCommand("copy"); - } catch (e) { - succeed = false; + // get copy icon + if (target.attr('class') == 'copy_to_clipboard_wrapper') { + icon = target; + } else { + icon = target.parent('.copy_to_clipboard_wrapper').find('i.copy_to_clipboard_wrapper'); + if (!icon.length) { + icon = target.parent('.copy_to_clipboard_wrapper'); + } } - target.blur(); // indicate success if (succeed) { $('.copy_to_clipboard_wrapper.copied').removeClass('copied'); - target.parent('.copy_to_clipboard_wrapper').addClass('copied'); + icon.addClass('copied'); + setTimeout(function(){ + icon.removeClass('copied'); + }, 1000); } else { - target.parent('.copy_to_clipboard_wrapper').addClass('copyfail'); + icon.addClass('copyfail'); } }); }); @@ -78,8 +99,15 @@ function copyTextToClipboard (text) { // Select and copy text to clipboard textarea.select(); - document.execCommand('copy'); + var succeed; + try { + succeed = document.execCommand('copy'); + } catch (e) { + succeed = false; + } // Remove textarea document.body.removeChild(textarea); + + return succeed; } From a4c44e2b6b417c255f5451370637f2aaad2efcff Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 22:28:19 -0300 Subject: [PATCH 02/11] Update User.php --- src/User.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/User.php b/src/User.php index e2ed37fd448..a35c3572a5c 100644 --- a/src/User.php +++ b/src/User.php @@ -3044,12 +3044,13 @@ public function showForm($ID, array $options = []) echo __("API token"); echo ""; if (!empty($this->fields["api_token"])) { - echo "
"; - echo Html::input('_api_token', [ - 'value' => $this->fields["api_token"], - 'style' => 'width:90%' - ]); - echo "
"; + echo "
"; + echo Html::input('_api_token', [ + 'value' => $this->fields["api_token"], + 'style' => 'width:90%' + ]); + echo ""; + echo "
"; echo "(" . sprintf( __('generated on %s'), Html::convDateTime($this->fields["api_token_date"]) From fe168f5b3c955cadf56ffae87c46d271840b7dd0 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 22:35:24 -0300 Subject: [PATCH 03/11] Update User.php --- src/User.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/User.php b/src/User.php index a35c3572a5c..e5fe716dce6 100644 --- a/src/User.php +++ b/src/User.php @@ -3044,13 +3044,13 @@ public function showForm($ID, array $options = []) echo __("API token"); echo ""; if (!empty($this->fields["api_token"])) { - echo "
"; - echo Html::input('_api_token', [ - 'value' => $this->fields["api_token"], - 'style' => 'width:90%' - ]); - echo ""; - echo "
"; + echo "
"; + echo Html::input('_api_token', [ + 'value' => $this->fields["api_token"], + 'style' => 'width:90%' + ]); + echo ""; + echo "
"; echo "(" . sprintf( __('generated on %s'), Html::convDateTime($this->fields["api_token_date"]) From 2f79db142a99c61e50a7b580c80bd3aacbb730b2 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 22:37:15 -0300 Subject: [PATCH 04/11] Update Grid.php --- src/Dashboard/Grid.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Dashboard/Grid.php b/src/Dashboard/Grid.php index f5ebc155dfb..6b3565b0404 100644 --- a/src/Dashboard/Grid.php +++ b/src/Dashboard/Grid.php @@ -800,18 +800,20 @@ public function displayEmbedForm() echo "
"; echo "
"; echo __("Direct link"); - echo "
"; + echo "
"; echo Html::input('direct_link', [ 'value' => $embed_url, ]); + echo ""; echo "

"; $iframe = ""; echo __("Iframe"); - echo "
"; + echo "
"; echo Html::input('iframe_code', [ 'value' => $iframe, ]); + echo ""; echo "
"; echo "

"; From 82d4c944da6317f5fa83cfe8c307b6b02b733f69 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 22:39:24 -0300 Subject: [PATCH 05/11] Update _styles.scss --- css/legacy/includes/_styles.scss | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/css/legacy/includes/_styles.scss b/css/legacy/includes/_styles.scss index 2a1292ad9f9..8f73660c5e6 100644 --- a/css/legacy/includes/_styles.scss +++ b/css/legacy/includes/_styles.scss @@ -1099,6 +1099,7 @@ .copy_to_clipboard_wrapper { display: flex; align-items: center; + font-style: normal; input[type=text] { padding-right: 18px !important; @@ -1134,6 +1135,20 @@ } } + .input-group.copy_to_clipboard_wrapper { + &:after { + content: none; + } + + & i.copy_to_clipboard_wrapper:after { + left: 0; + } + + & i.copy_to_clipboard_wrapper:before { + content: none; + } + } + /* ################--------------- Log history filters ---------------#################### */ tr.log_history_filter_row { From 0fde554f8359bee98c9c4ef253399968ce96f998 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 22:53:56 -0300 Subject: [PATCH 06/11] Fix tests --- js/clipboard.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/clipboard.js b/js/clipboard.js index f9d3475b8a0..96f9aa30f7e 100644 --- a/js/clipboard.js +++ b/js/clipboard.js @@ -60,6 +60,7 @@ $(function() { } // get copy icon + var icon; if (target.attr('class') == 'copy_to_clipboard_wrapper') { icon = target; } else { From 96a9b5242fcba2085c7f22d71a9cd79e85175899 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Thu, 30 Jan 2025 09:41:33 -0300 Subject: [PATCH 07/11] Update clipboard.js --- js/clipboard.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/js/clipboard.js b/js/clipboard.js index 96f9aa30f7e..e7995a9ea2a 100644 --- a/js/clipboard.js +++ b/js/clipboard.js @@ -38,6 +38,12 @@ $(function() { var succeed; // find the good element var target = $(event.target); + + // click on other button + if (target.hasClass('input-group-text') && !target.hasClass('copy_to_clipboard_wrapper')) { + return false; + } + // click on 'copy button' if (target.hasClass('input-group-text') || target.is('input')) { target = target.parent('.copy_to_clipboard_wrapper').find('input'); From 39d45ea0d9479c3da2f5d2f0d458382e60d783ba Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Thu, 30 Jan 2025 11:36:30 -0300 Subject: [PATCH 08/11] Refactor _styles.scss --- css/legacy/includes/_styles.scss | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/css/legacy/includes/_styles.scss b/css/legacy/includes/_styles.scss index 8f73660c5e6..dd54aee201f 100644 --- a/css/legacy/includes/_styles.scss +++ b/css/legacy/includes/_styles.scss @@ -1099,7 +1099,6 @@ .copy_to_clipboard_wrapper { display: flex; align-items: center; - font-style: normal; input[type=text] { padding-right: 18px !important; @@ -1140,12 +1139,16 @@ content: none; } - & i.copy_to_clipboard_wrapper:after { - left: 0; - } - - & i.copy_to_clipboard_wrapper:before { - content: none; + i.copy_to_clipboard_wrapper { + font-style: normal; + + &:after { + left: 0; + } + + &:before { + content: none; + } } } From f219f4144ebf5f495ca7bfc0d699a90578ef577f Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Thu, 30 Jan 2025 11:56:24 -0300 Subject: [PATCH 09/11] Add copy wrapper input group to 'My settings' page --- src/User.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/User.php b/src/User.php index e5fe716dce6..902a321ee0f 100644 --- a/src/User.php +++ b/src/User.php @@ -3439,11 +3439,12 @@ public function showMyForm($target, $ID) echo __("API token"); echo ""; if (!empty($this->fields["api_token"])) { - echo "
"; + echo "
"; echo Html::input('_api_token', [ 'value' => $this->fields["api_token"], 'style' => 'width:90%' ]); + echo ""; echo "
"; echo "(" . sprintf( __('generated on %s'), From 3e78a5bdfe247ba5cf5dc93fdf01c0176f5402d8 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Thu, 30 Jan 2025 15:04:15 -0300 Subject: [PATCH 10/11] Add "Copy to clipboard" on App Token (GLPI General > API tab) --- templates/pages/setup/apiclient.html.twig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/pages/setup/apiclient.html.twig b/templates/pages/setup/apiclient.html.twig index 6ce13f734f0..15052091f9b 100644 --- a/templates/pages/setup/apiclient.html.twig +++ b/templates/pages/setup/apiclient.html.twig @@ -84,7 +84,8 @@ item.fields['app_token'], __('%1$s (%2$s)')|format(__('Application token'), 'app_token'), { - 'add_field_html': reset_btn + 'input_class': 'input-group copy_to_clipboard_wrapper calendar-title col-xxl-7', + 'add_field_html': '' ~ reset_btn } ) }} From 043fab64898cd0eba633f1af7bc63f0a58852666 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Thu, 30 Jan 2025 15:43:35 -0300 Subject: [PATCH 11/11] Update apiclient.html.twig --- templates/pages/setup/apiclient.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/pages/setup/apiclient.html.twig b/templates/pages/setup/apiclient.html.twig index 15052091f9b..5887303ed15 100644 --- a/templates/pages/setup/apiclient.html.twig +++ b/templates/pages/setup/apiclient.html.twig @@ -84,7 +84,7 @@ item.fields['app_token'], __('%1$s (%2$s)')|format(__('Application token'), 'app_token'), { - 'input_class': 'input-group copy_to_clipboard_wrapper calendar-title col-xxl-7', + 'input_class': 'input-group copy_to_clipboard_wrapper col', 'add_field_html': '' ~ reset_btn } ) }}