From 4405bc41826d11cd139607212347347ed40dc393 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 19 Oct 2016 15:45:26 -0400 Subject: [PATCH] Closes #608: Add "toggle all" button to device and device type components --- netbox/project-static/js/forms.js | 11 ++++- netbox/templates/dcim/device.html | 44 ++++++++++++------- .../dcim/inc/devicetype_component_table.html | 13 ++++-- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/netbox/project-static/js/forms.js b/netbox/project-static/js/forms.js index 944b01868..439cf8701 100644 --- a/netbox/project-static/js/forms.js +++ b/netbox/project-static/js/forms.js @@ -1,6 +1,6 @@ $(document).ready(function() { - // "Toggle all" checkbox in a table header + // "Toggle all" checkbox (table header) $('#toggle_all').click(function (event) { $('td input:checkbox[name=pk]').prop('checked', $(this).prop('checked')); if ($(this).is(':checked')) { @@ -16,6 +16,15 @@ $(document).ready(function() { } }); + // Simple "Toggle all" button (panel) + $('button.toggle').click(function (event) { + var selected = $(this).attr('selected'); + $(this).closest('form').find('input:checkbox[name=pk]').prop('checked', !selected); + $(this).attr('selected', !selected); + $(this).children('span').toggleClass('glyphicon-unchecked glyphicon-check'); + return false; + }); + // Slugify function slugify(s, num_chars) { s = s.replace(/[^\-\.\w\s]/g, ''); // Remove unneeded chars diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index 345944370..62683930b 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -314,13 +314,16 @@
Device Bays - {% if perms.dcim.add_devicebay and device_bays|length > 10 %} -
+
+ + {% if perms.dcim.add_devicebay and device_bays|length > 10 %} Add device bays -
- {% endif %} + {% endif %} +
{% for devicebay in device_bays %} @@ -361,13 +364,16 @@
Interfaces - {% if perms.dcim.add_interface and interfaces|length > 10 %} -
+
+ + {% if perms.dcim.add_interface and interfaces|length > 10 %} Add interfaces -
- {% endif %} + {% endif %} +
{% for iface in interfaces %} @@ -413,13 +419,16 @@
Console Server Ports - {% if perms.dcim.add_consoleserverport and cs_ports|length > 10 %} -
+
+ + {% if perms.dcim.add_consoleserverport and cs_ports|length > 10 %} Add console server ports -
- {% endif %} + {% endif %} +
{% for csp in cs_ports %} @@ -460,13 +469,16 @@
Power Outlets - {% if perms.dcim.add_poweroutlet and power_outlets|length > 10 %} -
+
+ + {% if perms.dcim.add_poweroutlet and power_outlets|length > 10 %} Add power outlets -
- {% endif %} + {% endif %} +
{% for po in power_outlets %} diff --git a/netbox/templates/dcim/inc/devicetype_component_table.html b/netbox/templates/dcim/inc/devicetype_component_table.html index c71c5b4da..9954fec23 100644 --- a/netbox/templates/dcim/inc/devicetype_component_table.html +++ b/netbox/templates/dcim/inc/devicetype_component_table.html @@ -5,14 +5,19 @@
{{ title }} - {% if table.rows|length > 10 %} -
+
+ {% if table.rows|length > 3 %} + + {% endif %} + {% if table.rows|length > 10 %} Add {{ title }} -
- {% endif %} + {% endif %} +
{% render_table table 'table.html' %}