diff --git a/netbox/project-static/js/tableconfig.js b/netbox/project-static/js/tableconfig.js index ddea201a1..29b5e46d5 100644 --- a/netbox/project-static/js/tableconfig.js +++ b/netbox/project-static/js/tableconfig.js @@ -1,10 +1,27 @@ $(document).ready(function() { - $('form.tableconfigform').submit(function(event) { + $('form.userconfigform').submit(function(event) { event.preventDefault(); - let table_name = this.getAttribute('data-table-name'); - let data = {"tables": {}}; - data['tables'][table_name] = {}; - data['tables'][table_name]['columns'] = $('#id_columns').val(); + + // Derive an array from the dotted path to the config root + let path = this.getAttribute('data-config-root').split('.'); + 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({ url: netbox_api_path + 'users/config/', async: true, @@ -19,7 +36,7 @@ $(document).ready(function() { // Reload the page window.location.reload(true); }).fail(function (xhr, status, error) { - alert("Failed: " + error); + alert("Failed to update user config (" + status + "): " + error); }); }); }); diff --git a/netbox/templates/inc/table_config_form.html b/netbox/templates/inc/table_config_form.html index 59baecd8b..c4bc3f41d 100644 --- a/netbox/templates/inc/table_config_form.html +++ b/netbox/templates/inc/table_config_form.html @@ -7,8 +7,7 @@