mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 12:12:53 -06:00
Tweak the table config form for generic use
This commit is contained in:
parent
4de7fcd758
commit
ff3d0b72b9
@ -1,10 +1,27 @@
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('form.tableconfigform').submit(function(event) {
|
$('form.userconfigform').submit(function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
let table_name = this.getAttribute('data-table-name');
|
|
||||||
let data = {"tables": {}};
|
// Derive an array from the dotted path to the config root
|
||||||
data['tables'][table_name] = {};
|
let path = this.getAttribute('data-config-root').split('.');
|
||||||
data['tables'][table_name]['columns'] = $('#id_columns').val();
|
let data = {};
|
||||||
|
let pointer = data;
|
||||||
|
|
||||||
|
// Construct a nested JSON object from the path
|
||||||
|
let node;
|
||||||
|
for (node of path) {
|
||||||
|
pointer[node] = {};
|
||||||
|
pointer = pointer[node];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assign the form data to the child node
|
||||||
|
let field;
|
||||||
|
$.each($(this).find('[id^="id_"]:input'), function(index, value) {
|
||||||
|
field = $(value);
|
||||||
|
pointer[field.attr("name")] = field.val();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Make the REST API request
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: netbox_api_path + 'users/config/',
|
url: netbox_api_path + 'users/config/',
|
||||||
async: true,
|
async: true,
|
||||||
@ -19,7 +36,7 @@ $(document).ready(function() {
|
|||||||
// Reload the page
|
// Reload the page
|
||||||
window.location.reload(true);
|
window.location.reload(true);
|
||||||
}).fail(function (xhr, status, error) {
|
}).fail(function (xhr, status, error) {
|
||||||
alert("Failed: " + error);
|
alert("Failed to update user config (" + status + "): " + error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -7,8 +7,7 @@
|
|||||||
<h4 class="modal-title">Table Configuration</h4>
|
<h4 class="modal-title">Table Configuration</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<form action="" method="post" class="form-horizontal tableconfigform" data-table-name="{{ table_config_form.table_name }}">
|
<form class="form-horizontal userconfigform" data-config-root="tables.{{ table_config_form.table_name }}">
|
||||||
{% csrf_token %}
|
|
||||||
{% render_form table_config_form %}
|
{% render_form table_config_form %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-9 col-md-offset-3">
|
<div class="col-md-9 col-md-offset-3">
|
||||||
|
Loading…
Reference in New Issue
Block a user