@@ -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,33 @@ $(() => {
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 ( "success" , "far fa-copy" , "Copied to clipboard!" , textToCopy ) ;
186+ } )
187+ . catch ( error => {
188+ console . error ( "Could not copy text:" , error ) ; // eslint-disable-line no-console
189+ utils . showAlert (
190+ "error" ,
191+ "" ,
192+ "Failed to copy to clipboard" ,
193+ "See browser console for details"
194+ ) ;
195+ } ) ;
196+ }
197+
162198function deleteLease ( ) {
163199 // Passes the button data-del-id attribute as IP
164200 delLease ( $ ( this ) . attr ( "data-del-ip" ) ) ;
0 commit comments