diff --git a/scripts/js/settings-dhcp.js b/scripts/js/settings-dhcp.js index 74ae32d1..8d369ba2 100644 --- a/scripts/js/settings-dhcp.js +++ b/scripts/js/settings-dhcp.js @@ -286,8 +286,8 @@ function parseStaticDHCPLine(line) { }; } -// Save button for each row updates only that line in the textarea -$(document).on("click", ".save-static-row", function () { +// Save button for each row updates only that line in the textarea, if it doesn't contain the class ".disabled" +$(document).on("click", ".save-static-row:not(.disabled)", function () { const rowIdx = Number.parseInt($(this).data("row"), 10); const row = $(this).closest("tr"); const hwaddr = row.find(".static-hwaddr").text().trim(); @@ -365,13 +365,15 @@ $(document).on("focus input", "#StaticDHCPTable td[contenteditable]", function ( ); } }); -// On save, re-enable all buttons and remove the hint + +// On save, re-enable all buttons (except buttons with class "disabled") and remove the hint $(document).on("click", ".save-static-row", function () { $( - "#StaticDHCPTable .save-static-row, #StaticDHCPTable .delete-static-row, #StaticDHCPTable .add-static-row" + "#StaticDHCPTable .save-static-row:not(.disabled), #StaticDHCPTable .delete-static-row, #StaticDHCPTable .add-static-row" ).prop("disabled", false); $(".edit-hint-row").remove(); }); + // On table redraw, ensure all buttons are enabled and hints are removed function renderStaticDHCPTable() { const tbody = $("#StaticDHCPTable tbody"); @@ -379,54 +381,59 @@ function renderStaticDHCPTable() { const lines = $("#dhcp-hosts").val().split(/\r?\n/); for (const [idx, line] of lines.entries()) { const parsed = parseStaticDHCPLine(line); + + const saveBtn = $( + '' + ) + .attr("data-row", idx) + .attr("title", "Confirm changes to this line") + .attr("data-toggle", "tooltip"); + + const delBtn = $( + '' + ) + .attr("data-row", idx) + .attr("title", "Delete this line") + .attr("data-toggle", "tooltip"); + + const addBtn = $( + '' + ) + .attr("data-row", idx) + .attr("title", "Add new line after this") + .attr("data-toggle", "tooltip"); + + const tr = $("") + if (parsed === "advanced") { - const tr = $( - 'Advanced settings present in line ' + - (idx + 1) + - "" - ); + tr.addClass("table-warning") + .append( + 'Advanced settings present in line ' + + (idx + 1) + + "", + ) + + // Keep the original data tr.data("original-line", line); - tbody.append(tr); - continue; + + // Disable the save button on advanced rows + saveBtn + .addClass("disabled") + .prop("disabled", true) + .attr("title", "Disabled"); + + } else { + // Append 3 cells containing parsed values, with placeholder for empty hwaddr + tr.append($('').text(parsed.hwaddr)) + .append($('').text(parsed.ipaddr)) + .append( + $('').text(parsed.hostname), + ); } - const tr = $("") - .append($('')) - .append($('')) - .append($('')) - .append( - $("") - .append( - $( - '' - ) - .attr("data-row", idx) - .attr("title", "Confirm changes to this line") - .attr("data-toggle", "tooltip") - ) - .append(" ") - .append( - $( - '' - ) - .attr("data-row", idx) - .attr("title", "Delete this line") - .attr("data-toggle", "tooltip") - ) - .append(" ") - .append( - $( - '' - ) - .attr("data-row", idx) - .attr("title", "Add new line after this") - .attr("data-toggle", "tooltip") - ) - ); - // Set cell values, with placeholder for empty hwaddr - tr.find(".static-hwaddr").text(parsed.hwaddr); - tr.find(".static-ipaddr").text(parsed.ipaddr); - tr.find(".static-hostname").text(parsed.hostname); + // Append a last cell containing the buttons + tr.append($("").append(saveBtn, " ", delBtn, " ", addBtn)); + tbody.append(tr); }