mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Separate device component lists into discrete views
This commit is contained in:
46
netbox/project-static/js/connection_toggles.js
Normal file
46
netbox/project-static/js/connection_toggles.js
Normal file
@@ -0,0 +1,46 @@
|
||||
function toggleConnection(elem) {
|
||||
var url = netbox_api_path + "dcim/cables/" + elem.attr('data') + "/";
|
||||
if (elem.hasClass('connected')) {
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: 'PATCH',
|
||||
dataType: 'json',
|
||||
beforeSend: function(xhr, settings) {
|
||||
xhr.setRequestHeader("X-CSRFToken", netbox_csrf_token);
|
||||
},
|
||||
data: {
|
||||
'status': 'planned'
|
||||
},
|
||||
context: this,
|
||||
success: function() {
|
||||
elem.parents('tr').removeClass('success').addClass('info');
|
||||
elem.removeClass('connected btn-warning').addClass('btn-success');
|
||||
elem.attr('title', 'Mark installed');
|
||||
elem.children('i').removeClass('mdi mdi-lan-disconnect').addClass('mdi mdi-lan-connect')
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: 'PATCH',
|
||||
dataType: 'json',
|
||||
beforeSend: function(xhr, settings) {
|
||||
xhr.setRequestHeader("X-CSRFToken", netbox_csrf_token);
|
||||
},
|
||||
data: {
|
||||
'status': 'connected'
|
||||
},
|
||||
context: this,
|
||||
success: function() {
|
||||
elem.parents('tr').removeClass('info').addClass('success');
|
||||
elem.removeClass('btn-success').addClass('connected btn-warning');
|
||||
elem.attr('title', 'Mark planned');
|
||||
elem.children('i').removeClass('mdi mdi-lan-connect').addClass('mdi mdi-lan-disconnect')
|
||||
}
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
$(".cable-toggle").click(function() {
|
||||
return toggleConnection($(this));
|
||||
});
|
@@ -3,20 +3,16 @@ $('input.interface-filter').on('input', function() {
|
||||
var filter = new RegExp(this.value);
|
||||
var interface;
|
||||
|
||||
for (interface of $('#interfaces_table > tbody > tr.interface')) {
|
||||
for (interface of $('table > tbody > tr')) {
|
||||
// Slice off 'interface_' at the start of the ID
|
||||
if (filter.test(interface.id.slice(10))) {
|
||||
// Match the toggle in case the filter now matches the interface
|
||||
$(interface).find('input:checkbox[name=pk]').prop('checked', $('input.toggle').prop('checked'));
|
||||
$(interface).show();
|
||||
if ($('button.toggle-ips').attr('selected')) {
|
||||
$(interface).next('tr.ipaddresses').show();
|
||||
}
|
||||
} else {
|
||||
// Uncheck to prevent actions from including it when it doesn't match
|
||||
$(interface).find('input:checkbox[name=pk]').prop('checked', false);
|
||||
$(interface).hide();
|
||||
$(interface).next('tr.ipaddresses').hide();
|
||||
}
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user