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 " | ";
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
}
) }}
|