Skip to content

Commit a0fc9cd

Browse files
committed
Use CSS to show confirmation message when editing static DHCP table rows
Remove the javascript code used to add and remove "hints" and replace it with a single CSS pseudo-element after the table, instead of one message per line. Also, adjust LCARS message position. Signed-off-by: RD WebDesign <[email protected]>
1 parent e43c4c6 commit a0fc9cd

3 files changed

Lines changed: 57 additions & 22 deletions

File tree

scripts/js/settings-dhcp.js

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -313,19 +313,17 @@ $(document).on("click", ".save-static-row", function () {
313313
hwaddr || ipaddr || hostname ? [hwaddr, ipaddr, hostname].filter(Boolean).join(",") : "";
314314
$("#dhcp-hosts").val(lines.join("\n"));
315315

316-
// On save remove the save button and the hint
316+
// On save remove the save button
317317
$(this).remove();
318-
row.next(".edit-hint-row").remove();
319318
// and remove highlight colors from all cells on this row
320319
$("td", row).removeClass("table-danger");
321320

322321
// Check if all rows were already saved (no rows are still being edited)
323-
if ($("#StaticDHCPTable .edit-hint-row").length == 0) {
322+
if ($("#StaticDHCPTable .save-static-row").length == 0) {
324323
// Re-enable all table buttons
325324
$("#StaticDHCPTable button").prop("disabled", false);
326325
// and re-enable the textarea
327326
$("#dhcp-hosts").prop("disabled", false);
328-
$("#dhcp-hosts").prop("title", "");
329327
}
330328
});
331329

@@ -367,8 +365,8 @@ $(document).on("focus input", "#StaticDHCPTable td[contenteditable]", function (
367365
// Disable all action buttons in all rows
368366
$("#StaticDHCPTable .delete-static-row, #StaticDHCPTable .add-static-row").prop("disabled", true);
369367

370-
// Add save button and show a hint below the current row if not already present
371-
if (!row.next().hasClass("edit-hint-row")) {
368+
// Add save button (a hint asking to click on the button will be shown below the table - CSS pseudo-element)
369+
if (row.find(".save-static-row").length == 0) {
372370
const idx = row.attr("data-row");
373371
const saveBtn = $(
374372
'<button type="button" class="btn btn-success btn-xs save-static-row"><i class="fa fa-fw fa-check"></i></button>'
@@ -380,23 +378,8 @@ $(document).on("focus input", "#StaticDHCPTable td[contenteditable]", function (
380378
// Add the save button to the actions column
381379
row.find('td').last().prepend(saveBtn, " ");
382380

383-
// Create a table row containing the edit hint and the save button
384-
const hintRow = $('<tr class="edit-hint-row"></tr>')
385-
.append(
386-
$(
387-
'<td colspan="4" class="bg-info"><em>Please confirm changes using the green button, then click "Save &amp; Apply" before leaving the page.</em></td>'
388-
)
389-
);
390-
391381
// Disable the textarea to avoid losing unsaved changes to the table
392382
$("#dhcp-hosts").prop("disabled", true);
393-
$("#dhcp-hosts").prop("title", "Disabled.\nConfirm all changes above to enable this field");
394-
395-
// Remove any previously existing hint
396-
row.next(".edit-hint-row").remove();
397-
398-
// Add the created hint
399-
row.after(hintRow);
400383
}
401384
});
402385

@@ -446,7 +429,6 @@ function renderStaticDHCPTable() {
446429
}
447430

448431
tbody.find(".delete-static-row, .add-static-row").prop("disabled", false);
449-
tbody.find(".edit-hint-row").remove();
450432
showLineNumbers();
451433
}
452434

style/pi-hole.css

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,24 @@ textarea.no-wrap {
16251625
resize: none;
16261626
}
16271627

1628+
/* Show hint message on the static DHCP lease table, when at least one Save button exists */
1629+
div:has(> .table-responsive #StaticDHCPTable) {
1630+
position: relative;
1631+
}
1632+
div:has(> .table-responsive #StaticDHCPTable .save-static-row)::before {
1633+
content: 'Please confirm changes using the green button, then click "Save & Apply" before leaving the page.';
1634+
position:absolute;
1635+
display: block;
1636+
padding: 4px 12px;
1637+
max-width: calc(100% - 30px);
1638+
right: 15px;
1639+
bottom: 0px;
1640+
color: #000;
1641+
font-style: italic;
1642+
text-align: right;
1643+
background: #eedd88;
1644+
}
1645+
16281646
/*
16291647
Calculate the total height using the number of lines and line-height. Also account for borders and padding.
16301648
Use the same values used by ".form-control" class:
@@ -1642,6 +1660,24 @@ border-top=1px + padding-top=6px + padding-bottom=6px + border-bottom=1px
16421660
gap: 0;
16431661
}
16441662

1663+
/* Message displayed when the textarea is disabled because there are table rows being edited */
1664+
.dhcp-hosts-wrapper:has(textarea[disabled]):hover::before {
1665+
content: "Please confirm all changes above before editing this field.";
1666+
display: block;
1667+
position: absolute;
1668+
width: 380px;
1669+
padding:8px;
1670+
top: 50%;
1671+
left:50%;
1672+
transform: translate(-45%,-50%);
1673+
text-align: center;
1674+
font-style: italic;
1675+
color: #000;
1676+
background: #ed8;
1677+
box-shadow: 0 0 8px rgba(0,0,0,.35);
1678+
cursor: not-allowed;
1679+
}
1680+
16451681
#dhcp-hosts {
16461682
height: var(--total-height);
16471683
}

style/themes/lcars.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,3 +2185,20 @@ td.highlight {
21852185
.help-block {
21862186
color: #76808a;
21872187
}
2188+
2189+
div:has(> .table-responsive #StaticDHCPTable .save-static-row)::after {
2190+
padding: 1px 10px 3px;
2191+
background: #fd8;
2192+
border-radius: 5px;
2193+
}
2194+
.dhcp-hosts-wrapper:has(textarea[disabled]):hover::before {
2195+
padding: 6px 8px 8px;
2196+
background: #fd8;
2197+
border-radius: 5px;
2198+
width: 400px;
2199+
transform: translate(-47%,-50%);
2200+
box-shadow: 0 0 10px 2px #000;
2201+
}
2202+
.line-numbers {
2203+
border-color: transparent;
2204+
}

0 commit comments

Comments
 (0)