Просмотр исходного кода

Closes #13962: Add a copy-to-clipboard button to the key field of the API token creation form

Jeremy Stretch 2 лет назад
Родитель
Сommit
51ef4fb920

Разница между файлами не показана из-за своего большого размера
+ 0 - 0
netbox/project-static/dist/netbox.js


Разница между файлами не показана из-за своего большого размера
+ 0 - 0
netbox/project-static/dist/netbox.js.map


+ 1 - 1
netbox/project-static/src/clipboard.ts

@@ -2,7 +2,7 @@ import Clipboard from 'clipboard';
 import { getElements } from './util';
 import { getElements } from './util';
 
 
 export function initClipboard(): void {
 export function initClipboard(): void {
-  for (const element of getElements('a.copy-content')) {
+  for (const element of getElements('.copy-content')) {
     new Clipboard(element);
     new Clipboard(element);
   }
   }
 }
 }

+ 0 - 5
netbox/templates/account/token.html

@@ -15,11 +15,6 @@
 {% block content %}
 {% block content %}
   <div class="row">
   <div class="row">
     <div class="col col-md-12">
     <div class="col col-md-12">
-      {% if key and not settings.ALLOW_TOKEN_RETRIEVAL %}
-        <div class="alert alert-danger" role="alert">
-          <i class="mdi mdi-alert"></i> Tokens cannot be retrieved at a later time. You must <a href="#" class="copy-content" data-clipboard-target="#token_id" title="Copy to clipboard">copy the token value</a> below and store it securely.
-        </div>
-      {% endif %}
       <div class="card">
       <div class="card">
         <h5 class="card-header">{% trans "Token" %}</h5>
         <h5 class="card-header">{% trans "Token" %}</h5>
         <div class="card-body">
         <div class="card-body">

+ 3 - 0
netbox/users/forms/model_forms.py

@@ -114,6 +114,9 @@ class UserTokenForm(BootstrapMixin, forms.ModelForm):
         help_text=_(
         help_text=_(
             'Keys must be at least 40 characters in length. <strong>Be sure to record your key</strong> prior to '
             'Keys must be at least 40 characters in length. <strong>Be sure to record your key</strong> prior to '
             'submitting this form, as it may no longer be accessible once the token has been created.'
             'submitting this form, as it may no longer be accessible once the token has been created.'
+        ),
+        widget=forms.TextInput(
+            attrs={'data-clipboard': 'true'}
         )
         )
     )
     )
     allowed_ips = SimpleArrayField(
     allowed_ips = SimpleArrayField(

+ 8 - 0
netbox/utilities/templates/form_helpers/render_field.html

@@ -29,6 +29,14 @@
           {{ label }}
           {{ label }}
         </label>
         </label>
       </div>
       </div>
+    {# Include a copy-to-clipboard button #}
+    {% elif 'data-clipboard' in field.field.widget.attrs %}
+      <div class="input-group">
+        {{ field }}
+        <button type="button" title="{% trans "Copy to clipboard" %}" class="btn btn-outline-dark border-input copy-content" data-clipboard-target="#{{ field.id_for_label }}">
+          <i class="mdi mdi-content-copy"></i>
+        </button>
+      </div>
     {# Default field rendering #}
     {# Default field rendering #}
     {% else %}
     {% else %}
       {{ field }}
       {{ field }}

Некоторые файлы не были показаны из-за большого количества измененных файлов