@@ -19,13 +19,7 @@ <h1>{% block heading %}{% trans 'Finish Payout' %}{% endblock heading %}</h1>
1919
2020< form method ="post ">
2121
22- < div class ="d-flex justify-content-between align-items-start mb-3 ">
23- < h5 class ="mb-0 "> {% trans 'Payout Details' %}</ h5 >
24- < button type ="button " class ="btn btn-sm btn-outline-primary " id ="copy-payout-info " title ="{% trans 'Copy payout information' %} ">
25- < span class ="fa fa-copy mr-1 " aria-hidden ="true "> </ span >
26- < span id ="copy-btn-text "> {% trans 'Copy Info' %}</ span >
27- </ button >
28- </ div >
22+ < h5 class ="mb-3 "> {% trans 'Payout Details' %}</ h5 >
2923
3024 < dl >
3125 < dt > {% trans 'Publisher' %}</ dt >
@@ -38,19 +32,32 @@ <h5 class="mb-0">{% trans 'Payout Details' %}</h5>
3832
3933 {% if payout.publisher.paypal_email %}
4034 < dt > {% trans 'User' %}</ dt >
41- < dd id ="payout-email ">
42- {{ payout.publisher.paypal_email }}
35+ < dd >
36+ < span id ="payout-email "> {{ payout.publisher.paypal_email }}</ span >
37+ < button type ="button " class ="btn btn-sm btn-outline-secondary ml-2 copy-btn " data-copy-target ="payout-email " title ="{% trans 'Copy email' %} ">
38+ < span class ="fa fa-copy " aria-hidden ="true "> </ span >
39+ </ button >
4340 </ dd >
4441 {% endif %}
4542
4643 < dt > {% trans 'Status' %}</ dt >
4744 < dd > {{ payout.get_status_display }}</ dd >
4845
4946 < dt > {% trans 'Amount' %}</ dt >
50- < dd id ="payout-amount "> ${{ payout.amount|floatformat:2|intcomma }}</ dd >
47+ < dd >
48+ < span id ="payout-amount "> ${{ payout.amount|floatformat:2|intcomma }}</ span >
49+ < button type ="button " class ="btn btn-sm btn-outline-secondary ml-2 copy-btn " data-copy-target ="payout-amount " title ="{% trans 'Copy amount' %} ">
50+ < span class ="fa fa-copy " aria-hidden ="true "> </ span >
51+ </ button >
52+ </ dd >
5153
5254 < dt > {% trans 'Subject' %}</ dt >
53- < dd id ="payout-subject "> {% trans "EthicalAds Payout" %} - {{ payout.publisher.name }}</ dd >
55+ < dd >
56+ < span id ="payout-subject "> {% trans "EthicalAds Payout" %} - {{ payout.publisher.name }}</ span >
57+ < button type ="button " class ="btn btn-sm btn-outline-secondary ml-2 copy-btn " data-copy-target ="payout-subject " title ="{% trans 'Copy subject' %} ">
58+ < span class ="fa fa-copy " aria-hidden ="true "> </ span >
59+ </ button >
60+ </ dd >
5461
5562 < dt > {% trans 'Action' %}</ dt >
5663 < dd >
@@ -95,59 +102,67 @@ <h5 class="mb-0">{% trans 'Payout Details' %}</h5>
95102
96103< script >
97104 ( function ( ) {
98- var COPIED_TEXT = '{% trans "Copied!" %}' ;
99- var RESET_TIMEOUT = 2000 ;
100-
101- document . getElementById ( 'copy-payout-info' ) . addEventListener ( 'click' , function ( ) {
102- // Get the payout information
103- var amount = document . getElementById ( 'payout-amount' ) . textContent . trim ( ) ;
104- var subject = document . getElementById ( 'payout-subject' ) . textContent . trim ( ) ;
105- var emailElement = document . getElementById ( 'payout-email' ) ;
106- var email = emailElement ? emailElement . textContent . trim ( ) : '' ;
107-
108- // Format the text to copy
109- var textToCopy = 'Amount: ' + amount + '\n' ;
110- if ( email ) {
111- textToCopy += 'Email: ' + email + '\n' ;
112- }
113- textToCopy += 'Subject: ' + subject ;
114-
115- // Function to show success feedback
116- function showSuccessFeedback ( ) {
117- var btnText = document . getElementById ( 'copy-btn-text' ) ;
118- var originalText = btnText . textContent ;
119- btnText . textContent = COPIED_TEXT ;
120-
121- setTimeout ( function ( ) {
122- btnText . textContent = originalText ;
123- } , RESET_TIMEOUT ) ;
124- }
105+ var RESET_TIMEOUT = 1500 ;
125106
126- // Copy to clipboard
107+ // Function to copy text to clipboard
108+ function copyToClipboard ( text , button , callback ) {
127109 if ( navigator . clipboard && navigator . clipboard . writeText ) {
128- navigator . clipboard . writeText ( textToCopy ) . then ( function ( ) {
129- showSuccessFeedback ( ) ;
110+ navigator . clipboard . writeText ( text ) . then ( function ( ) {
111+ callback ( ) ;
130112 } ) . catch ( function ( err ) {
131113 console . error ( 'Failed to copy text: ' , err ) ;
132114 alert ( 'Failed to copy to clipboard' ) ;
133115 } ) ;
134116 } else {
135117 // Fallback for older browsers
136118 var textArea = document . createElement ( 'textarea' ) ;
137- textArea . value = textToCopy ;
119+ textArea . value = text ;
138120 textArea . style . position = 'fixed' ;
139121 textArea . style . left = '-999999px' ;
140122 document . body . appendChild ( textArea ) ;
141123 textArea . select ( ) ;
142124 try {
143125 document . execCommand ( 'copy' ) ;
144- showSuccessFeedback ( ) ;
126+ callback ( ) ;
145127 } catch ( err ) {
146128 console . error ( 'Fallback: Failed to copy text: ' , err ) ;
147129 alert ( 'Failed to copy to clipboard' ) ;
148130 }
149131 document . body . removeChild ( textArea ) ;
150132 }
133+ }
134+
135+ // Function to show success feedback on button
136+ function showSuccessFeedback ( button ) {
137+ var icon = button . querySelector ( '.fa-copy' ) ;
138+ if ( icon ) {
139+ icon . classList . remove ( 'fa-copy' ) ;
140+ icon . classList . add ( 'fa-check' ) ;
141+ button . classList . remove ( 'btn-outline-secondary' ) ;
142+ button . classList . add ( 'btn-success' ) ;
143+
144+ setTimeout ( function ( ) {
145+ icon . classList . remove ( 'fa-check' ) ;
146+ icon . classList . add ( 'fa-copy' ) ;
147+ button . classList . remove ( 'btn-success' ) ;
148+ button . classList . add ( 'btn-outline-secondary' ) ;
149+ } , RESET_TIMEOUT ) ;
150+ }
151+ }
152+
153+ // Add click handlers to all copy buttons
154+ var copyButtons = document . querySelectorAll ( '.copy-btn' ) ;
155+ copyButtons . forEach ( function ( button ) {
156+ button . addEventListener ( 'click' , function ( ) {
157+ var targetId = this . getAttribute ( 'data-copy-target' ) ;
158+ var targetElement = document . getElementById ( targetId ) ;
159+ if ( targetElement ) {
160+ var textToCopy = targetElement . textContent . trim ( ) ;
161+ copyToClipboard ( textToCopy , this , function ( ) {
162+ showSuccessFeedback ( button ) ;
163+ } ) ;
164+ }
165+ } ) ;
151166 } ) ;
152167 } ) ( ) ;
153168</ script >
0 commit comments