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

Enable reordering table columns

Jeremy Stretch 5 лет назад
Родитель
Сommit
f51e7519dc

+ 25 - 0
netbox/project-static/js/forms.js

@@ -448,4 +448,29 @@ $(document).ready(function() {
     $('a.image-preview').on('mouseout', function() {
         $('#image-preview-window').fadeOut('fast');
     });
+
+    // Rearrange options within a <select> list
+    $('#move-option-up').bind('click', function() {
+        var select_id = '#' + $(this).attr('data-target');
+        $(select_id + ' option:selected').each(function () {
+            var newPos = $(select_id + ' option').index(this) - 1;
+            if (newPos > -1) {
+                $(select_id + ' option').eq(newPos).before("<option value='" + $(this).val() + "' selected='selected'>" + $(this).text() + "</option>");
+                $(this).remove();
+            }
+        });
+    });
+    $('#move-option-down').bind('click', function() {
+        var select_id = '#' + $(this).attr('data-target');
+        var countOptions = $(select_id + ' option').length;
+        var countSelectedOptions = $(select_id + ' option:selected').length;
+        $(select_id + ' option:selected').each(function () {
+            var newPos = $(select_id + ' option').index(this) + countSelectedOptions;
+            if (newPos < countOptions) {
+                $(select_id + ' option').eq(newPos).after("<option value='" + $(this).val() + "' selected='selected'>" + $(this).text() + "</option>");
+                $(this).remove();
+            }
+        });
+    });
+
 });

+ 7 - 3
netbox/templates/inc/table_config_form.html

@@ -1,6 +1,4 @@
 {% load form_helpers %}
-
-<button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#tableconfig" title="Configure table"><i class="fa fa-cog"></i></button>
 <div class="modal fade" tabindex="-1" id="tableconfig">
     <div class="modal-dialog">
         <div class="modal-content">
@@ -12,9 +10,15 @@
                 <form action="" method="post" class="form-horizontal">
                     {% csrf_token %}
                     {% render_form table_config_form %}
+                    <div class="row">
+                        <div class="col-md-9 col-md-offset-3">
+                            <a class="btn btn-primary btn-xs" id="move-option-up" data-target="id_columns"><i class="fa fa-arrow-up"></i> Move up</a>
+                            <a class="btn btn-primary btn-xs" id="move-option-down" data-target="id_columns"><i class="fa fa-arrow-down"></i> Move down</a>
+                        </div>
+                    </div>
                     <div class="text-right">
                         <input type="submit" class="btn btn-primary" name="set" value="Save" />
-                        <input type="submit" class="btn btn-danger" name="clear" value="Clear" />
+                        <input type="submit" class="btn btn-danger" name="clear" value="Reset" />
                     </div>
                 </form>
             </div>

+ 6 - 3
netbox/templates/utilities/obj_list.html

@@ -5,6 +5,9 @@
 {% block content %}
 <div class="pull-right noprint">
     {% block buttons %}{% endblock %}
+    {% if table_config_form %}
+        <button type="button" class="btn btn-default" data-toggle="modal" data-target="#tableconfig" title="Configure table"><i class="fa fa-cog"></i> Configure</button>
+    {% endif %}
     {% if permissions.add and 'add' in action_buttons %}
         {% add_button content_type.model_class|url_name:"add" %}
     {% endif %}
@@ -18,9 +21,6 @@
 <h1>{% block title %}{{ content_type.model_class|meta:"verbose_name_plural"|bettertitle }}{% endblock %}</h1>
 <div class="row">
     <div class="col-md-{% if filter_form %}9{% else %}12{% endif %}">
-        {% if table_config_form %}
-            {% include 'inc/table_config_form.html' %}
-        {% endif %}
         {% with bulk_edit_url=content_type.model_class|url_name:"bulk_edit" bulk_delete_url=content_type.model_class|url_name:"bulk_delete" %}
         {% if permissions.change or permissions.delete %}
             <form method="post" class="form form-horizontal">
@@ -71,6 +71,9 @@
         {% endwith %}
         {% include 'inc/paginator.html' with paginator=table.paginator page=table.page %}
         <div class="clearfix"></div>
+        {% if table_config_form %}
+            {% include 'inc/table_config_form.html' %}
+        {% endif %}
     </div>
     {% if filter_form %}
         <div class="col-md-3 noprint">

+ 2 - 1
netbox/utilities/forms.py

@@ -765,7 +765,8 @@ class TableConfigForm(BootstrapMixin, forms.Form):
         choices=[],
         widget=forms.SelectMultiple(
             attrs={'size': 10}
-        )
+        ),
+        help_text="Use the buttons below to arrange columns in the desired order, then select all columns to display."
     )
 
     def __init__(self, table, *args, **kwargs):

+ 1 - 1
netbox/utilities/views.py

@@ -202,7 +202,7 @@ class ObjectListView(View):
                 request.user.config.clear(preference_name, commit=True)
             messages.success(request, "Your preferences have been updated.")
 
-        return redirect(request.path)
+        return redirect(request.get_full_path())
 
     def alter_queryset(self, request):
         # .all() is necessary to avoid caching queries