diff --git a/scripts/js/settings-dhcp.js b/scripts/js/settings-dhcp.js
index 370396cdd4..323e64da36 100644
--- a/scripts/js/settings-dhcp.js
+++ b/scripts/js/settings-dhcp.js
@@ -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;
@@ -74,15 +75,23 @@ $(() => {
},
rowCallback(row, data) {
$(row).attr("data-id", data.ip);
- const button =
+ const copyButton =
+ '';
+ const deleteButton =
'";
- $("td:eq(6)", row).html(button);
+ '">';
+ $("td:eq(6)", row).html(copyButton + " " + deleteButton);
},
select: {
style: "multi",
@@ -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"));