@@ -64,6 +64,7 @@ $(() => {
6464 ] ,
6565 drawCallback ( ) {
6666 $ ( 'button[id^="deleteLease_"]' ) . on ( "click" , deleteLease ) ;
67+ $ ( 'button[id^="copyLease_"]' ) . on ( "click" , copyLease ) ;
6768
6869 // Hide buttons if all messages were deleted
6970 const hasRows = this . api ( ) . rows ( { filter : "applied" } ) . data ( ) . length > 0 ;
@@ -74,15 +75,23 @@ $(() => {
7475 } ,
7576 rowCallback ( row , data ) {
7677 $ ( row ) . attr ( "data-id" , data . ip ) ;
77- const button =
78+ const copyButton =
79+ '<button type="button" class="btn btn-default btn-xs" id="copyLease_"' +
80+ 'data-hwaddr="' +
81+ data . hwaddr +
82+ '" data-ip="' +
83+ data . ip +
84+ '" data-name="' +
85+ data . name +
86+ '" title="Copy as static DHCP lease">' +
87+ '<span class="far fa-copy"></span></button>' ;
88+ const deleteButton =
7889 '<button type="button" class="btn btn-danger btn-xs" id="deleteLease_' +
7990 data . ip +
8091 '" data-del-ip="' +
8192 data . ip +
82- '">' +
83- '<span class="far fa-trash-alt"></span>' +
84- "</button>" ;
85- $ ( "td:eq(6)" , row ) . html ( button ) ;
93+ '"><span class="far fa-trash-alt"></span></button>' ;
94+ $ ( "td:eq(6)" , row ) . html ( copyButton + " " + deleteButton ) ;
8695 } ,
8796 select : {
8897 style : "multi" ,
@@ -159,6 +168,38 @@ $(() => {
159168 } ) ;
160169} ) ;
161170
171+ function copyLease ( ) {
172+ const button = $ ( this ) ;
173+ const hwaddr = button . data ( "hwaddr" ) ;
174+ const ip = button . data ( "ip" ) ;
175+ const name = button . data ( "name" ) ;
176+
177+ // Handle cases where name is not available
178+ const hostname = name === "*" || name === null ? "" : name ;
179+
180+ const textToCopy = `${ hwaddr } ,${ ip } ,${ hostname } ` ;
181+
182+ navigator . clipboard
183+ . writeText ( textToCopy )
184+ . then ( ( ) => {
185+ utils . showAlert (
186+ "success" ,
187+ "far fa-copy" ,
188+ "Copied to clipboard!" ,
189+ textToCopy
190+ ) ;
191+ } )
192+ . catch ( err => {
193+ console . error ( "Could not copy text: " , err ) ; // eslint-disable-line no-console
194+ utils . showAlert (
195+ "error" ,
196+ "" ,
197+ "Failed to copy to clipboard" ,
198+ "See browser console for details"
199+ ) ;
200+ } ) ;
201+ }
202+
162203function deleteLease ( ) {
163204 // Passes the button data-del-id attribute as IP
164205 delLease ( $ ( this ) . attr ( "data-del-ip" ) ) ;
0 commit comments