33 * Functions for admin interface interactions
44 */
55
6+ import { copyToClipboard } from './utils.js' ;
7+
68/**
79 * Copy client secret to clipboard
810 */
911function copySecret ( ) {
10- const secretElement = document . getElementById ( 'clientSecret' ) ;
12+ var secretElement = document . getElementById ( 'clientSecret' ) ;
1113 if ( ! secretElement ) {
1214 console . error ( 'Secret element not found' ) ;
1315 return ;
1416 }
15-
16- const secret = secretElement . textContent ;
17-
18- // Use modern clipboard API if available
19- if ( navigator . clipboard && navigator . clipboard . writeText ) {
20- navigator . clipboard . writeText ( secret )
21- . then ( function ( ) {
22- showNotification ( 'Client secret copied to clipboard!' , 'success' ) ;
23- } )
24- . catch ( function ( err ) {
25- console . error ( 'Failed to copy:' , err ) ;
26- fallbackCopySecret ( secret ) ;
27- } ) ;
28- } else {
29- // Fallback for older browsers
30- fallbackCopySecret ( secret ) ;
31- }
32- }
33-
34- /**
35- * Fallback method to copy text for older browsers
36- */
37- function fallbackCopySecret ( text ) {
38- const textarea = document . createElement ( 'textarea' ) ;
39- textarea . value = text ;
40- textarea . style . position = 'fixed' ;
41- textarea . style . opacity = '0' ;
42- document . body . appendChild ( textarea ) ;
43- textarea . select ( ) ;
44-
45- try {
46- const successful = document . execCommand ( 'copy' ) ;
47- if ( successful ) {
48- showNotification ( 'Client secret copied to clipboard!' , 'success' ) ;
49- } else {
50- showNotification ( 'Failed to copy secret' , 'error' ) ;
51- }
52- } catch ( err ) {
53- console . error ( 'Failed to copy:' , err ) ;
54- showNotification ( 'Failed to copy secret' , 'error' ) ;
55- }
56-
57- document . body . removeChild ( textarea ) ;
58- }
59-
60- /**
61- * Show notification (uses utils.js if available)
62- */
63- function showNotification ( message , type ) {
64- // Try to use the notification function from utils.js
65- if ( typeof window . showNotification === 'function' ) {
66- window . showNotification ( message , type ) ;
67- return ;
68- }
69-
70- // Fallback to alert if utils.js is not loaded
71- alert ( message ) ;
17+ copyToClipboard ( secretElement . textContent ) ;
7218}
7319
7420/**
7521 * Toggle client description in table
7622 */
7723function toggleDescription ( button ) {
78- const cell = button . closest ( '.client-name-cell' ) ;
24+ var cell = button . closest ( '.client-name-cell' ) ;
7925 if ( ! cell ) return ;
8026
81- const description = cell . querySelector ( '.client-description' ) ;
82- const icon = button . querySelector ( '.toggle-icon' ) ;
83-
27+ var description = cell . querySelector ( '.client-description' ) ;
8428 if ( ! description ) return ;
8529
8630 if ( description . style . display === 'none' || ! description . style . display ) {
87- // Show description
8831 description . style . display = 'block' ;
8932 button . classList . add ( 'expanded' ) ;
9033
91- // Animate height
9234 description . style . maxHeight = '0' ;
9335 description . style . overflow = 'hidden' ;
9436 description . style . transition = 'max-height 0.3s ease-out' ;
9537
96- // Trigger reflow
9738 description . offsetHeight ;
9839
9940 description . style . maxHeight = description . scrollHeight + 'px' ;
10041 } else {
101- // Hide description
10242 description . style . maxHeight = '0' ;
10343 button . classList . remove ( 'expanded' ) ;
10444
@@ -108,42 +48,18 @@ function toggleDescription(button) {
10848 }
10949}
11050
111- /**
112- * Confirm delete action
113- */
114- function confirmDelete ( clientName ) {
115- return confirm (
116- 'Are you sure you want to delete this client?\n\n' +
117- 'Client: ' + clientName + '\n\n' +
118- 'This action cannot be undone and will revoke all access tokens.'
119- ) ;
120- }
121-
122- /**
123- * Confirm regenerate secret
124- */
125- function confirmRegenerateSecret ( ) {
126- return confirm (
127- 'Are you sure you want to regenerate the client secret?\n\n' +
128- 'This will invalidate the current secret and any applications using it will stop working until updated with the new secret.'
129- ) ;
130- }
131-
132- export { copySecret , toggleDescription , confirmDelete , confirmRegenerateSecret } ;
51+ export { copySecret , toggleDescription } ;
13352
13453/**
13554 * Initialize admin page interactions
13655 */
13756document . addEventListener ( 'DOMContentLoaded' , function ( ) {
138- // Add any initialization code here
139-
140- // Example: Auto-select secret on click
141- const secretElements = document . querySelectorAll ( '.secret-value, .secret-value-enhanced' ) ;
57+ var secretElements = document . querySelectorAll ( '.secret-value, .secret-value-enhanced' ) ;
14258 secretElements . forEach ( function ( element ) {
14359 element . addEventListener ( 'click' , function ( ) {
144- const range = document . createRange ( ) ;
60+ var range = document . createRange ( ) ;
14561 range . selectNodeContents ( element ) ;
146- const selection = window . getSelection ( ) ;
62+ var selection = window . getSelection ( ) ;
14763 selection . removeAllRanges ( ) ;
14864 selection . addRange ( range ) ;
14965 } ) ;
0 commit comments