Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions scripts/js/settings-dhcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ $(() => {
],
drawCallback() {
$('button[id^="deleteLease_"]').on("click", deleteLease);
$('button[id^="copyLease_"]').on("click", copyLease);

// Hide buttons if all messages were deleted
const hasRows = this.api().rows({ filter: "applied" }).data().length > 0;
Expand All @@ -74,15 +75,23 @@ $(() => {
},
rowCallback(row, data) {
$(row).attr("data-id", data.ip);
const button =
const copyButton =
'<button type="button" class="btn btn-default btn-xs" id="copyLease_"' +
'data-hwaddr="' +
data.hwaddr +
'" data-ip="' +
data.ip +
'" data-name="' +
data.name +
'" title="Copy as static DHCP lease">' +
'<span class="far fa-copy"></span></button>';
const deleteButton =
'<button type="button" class="btn btn-danger btn-xs" id="deleteLease_' +
data.ip +
'" data-del-ip="' +
data.ip +
'">' +
'<span class="far fa-trash-alt"></span>' +
"</button>";
$("td:eq(6)", row).html(button);
'"><span class="far fa-trash-alt"></span></button>';
$("td:eq(6)", row).html(copyButton + "&nbsp;" + deleteButton);
},
select: {
style: "multi",
Expand Down Expand Up @@ -159,6 +168,33 @@ $(() => {
});
});

function copyLease() {
const button = $(this);
const hwaddr = button.data("hwaddr");
const ip = button.data("ip");
const name = button.data("name");

// Handle cases where name is not available
const hostname = name === "*" || name === null ? "" : name;

const textToCopy = `${hwaddr},${ip},${hostname}`;

navigator.clipboard
.writeText(textToCopy)
.then(() => {
utils.showAlert("success", "far fa-copy", "Copied to clipboard!", textToCopy);
})
.catch(error => {
console.error("Could not copy text:", error); // eslint-disable-line no-console
utils.showAlert(
"error",
"",
"Failed to copy to clipboard",
"See browser console for details"
);
});
}

function deleteLease() {
// Passes the button data-del-id attribute as IP
delLease($(this).attr("data-del-ip"));
Expand Down