From 939ae7c3a7f8baf61039a77d5a60d10e90daf065 Mon Sep 17 00:00:00 2001
From: wyu <kknd09321@nate.com>
Date: 화, 28 12월 2021 15:54:26 +0900
Subject: [PATCH] API 토큰 복사 버튼 오류 수정

---
 src/main/webapp/i18n/ko/global.json                   |    1 +
 src/main/webapp/scripts/app/api/apiAuth.controller.js |   38 ++++++++++++++++++++++++++++++--------
 2 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/src/main/webapp/i18n/ko/global.json b/src/main/webapp/i18n/ko/global.json
index 4fc527d..661618c 100644
--- a/src/main/webapp/i18n/ko/global.json
+++ b/src/main/webapp/i18n/ko/global.json
@@ -904,6 +904,7 @@
         "useIssueStatus" : "�궗�슜 媛��뒫�븳 �씠�뒋 �긽�깭",
         "successToApiTokenRemove" : "API �넗�겙 �궘�젣 �꽦怨�",
         "successToApiTokenCopy" : "API �넗�겙 蹂듭궗 �꽦怨�",
+        "failedToApiTokenCopy" : "API �넗�겙 蹂듭궗 �떎�뙣",
         "ApiTokenCopy" : "�넗�겙 蹂듭궗",
         "successToApiTokenAdd" : "API �넗�겙 �깮�꽦 �꽦怨�",
         "successToApiIssueDefault" : "湲곕낯媛� �꽕�젙 �셿猷�",
diff --git a/src/main/webapp/scripts/app/api/apiAuth.controller.js b/src/main/webapp/scripts/app/api/apiAuth.controller.js
index eda67ae..e7cb211 100644
--- a/src/main/webapp/scripts/app/api/apiAuth.controller.js
+++ b/src/main/webapp/scripts/app/api/apiAuth.controller.js
@@ -75,15 +75,37 @@
                     });
                 }
 
+                // navigator.clipboard �뒗 釉뚮씪�슦�� 蹂댁븞�씠�굹 �솢�꽦�솕 �뿬遺��뿉 �뵲�씪 �궗�슜�씠 �븞�맆�븣媛� �엳�쓬
+                function copyToClipboard(textToCopy) {
+                    // navigator clipboard api needs a secure context (https)
+                    if (navigator.clipboard && window.isSecureContext) {
+                        // navigator clipboard api method'
+                        return navigator.clipboard.writeText(textToCopy);
+                    } else {
+                        // text area method
+                        let textArea = document.createElement("textarea");
+                        textArea.value = textToCopy;
+                        // make the textarea out of viewport
+                        textArea.style.position = "fixed";
+                        textArea.style.left = "-999999px";
+                        textArea.style.top = "-999999px";
+                        document.body.appendChild(textArea);
+                        textArea.focus();
+                        textArea.select();
+                        return new Promise((res, rej) => {
+                            // here the magic happens
+                            document.execCommand('copy') ? res() : rej();
+                            textArea.remove();
+                        });
+                    }
+                }
+
                 function copyToken() {
-                    var copyText = document.getElementById("apiApplicationForm2");
-
-                    copyText.select();
-                    copyText.setSelectionRange(0, 99999);
-
-                    navigator.clipboard.writeText(copyText.value);
-
-                    SweetAlert.swal($filter("translate")("api.successToApiTokenCopy")); // "api �넗�겙 �깮�꽦 �꽦怨�"
+                    copyToClipboard($scope.vm.form.token)
+                        .then(() =>
+                            SweetAlert.swal($filter("translate")("api.successToApiTokenCopy"))
+                        )
+                        .catch(() => SweetAlert.error($filter("translate")("api.failedToApiTokenCopy")))
                 }
 
                 function find() {

--
Gitblit v1.8.0