@@ -286,8 +286,8 @@ function parseStaticDHCPLine(line) {
286286 } ;
287287}
288288
289- // Save button for each row updates only that line in the textarea
290- $ ( document ) . on ( "click" , ".save-static-row" , function ( ) {
289+ // Save button for each row updates only that line in the textarea, if it doesn't contain the class ".disabled"
290+ $ ( document ) . on ( "click" , ".save-static-row:not(.disabled) " , function ( ) {
291291 const rowIdx = Number . parseInt ( $ ( this ) . data ( "row" ) , 10 ) ;
292292 const row = $ ( this ) . closest ( "tr" ) ;
293293 const hwaddr = row . find ( ".static-hwaddr" ) . text ( ) . trim ( ) ;
@@ -365,68 +365,82 @@ $(document).on("focus input", "#StaticDHCPTable td[contenteditable]", function (
365365 ) ;
366366 }
367367} ) ;
368- // On save, re-enable all buttons and remove the hint
368+
369+ // On save, re-enable all buttons (except buttons with class "disabled") and remove the hint
369370$ ( document ) . on ( "click" , ".save-static-row" , function ( ) {
370371 $ (
371- "#StaticDHCPTable .save-static-row, #StaticDHCPTable .delete-static-row, #StaticDHCPTable .add-static-row"
372+ "#StaticDHCPTable .save-static-row:not(.disabled) , #StaticDHCPTable .delete-static-row, #StaticDHCPTable .add-static-row"
372373 ) . prop ( "disabled" , false ) ;
373374 $ ( ".edit-hint-row" ) . remove ( ) ;
374375} ) ;
376+
375377// On table redraw, ensure all buttons are enabled and hints are removed
376378function renderStaticDHCPTable ( ) {
377379 const tbody = $ ( "#StaticDHCPTable tbody" ) ;
378380 tbody . empty ( ) ;
379381 const lines = $ ( "#dhcp-hosts" ) . val ( ) . split ( / \r ? \n / ) ;
380382 for ( const [ idx , line ] of lines . entries ( ) ) {
381383 const parsed = parseStaticDHCPLine ( line ) ;
384+
385+ const saveBtn = $ (
386+ '<button type="button" class="btn btn-success btn-xs save-static-row"><i class="fa fa-fw fa-check"></i></button>'
387+ )
388+ . attr ( "data-row" , idx )
389+ . attr ( "title" , "Confirm changes to this line" )
390+ . attr ( "data-toggle" , "tooltip" ) ;
391+
392+ const delBtn = $ (
393+ '<button type="button" class="btn btn-danger btn-xs delete-static-row"><i class="fa fa-fw fa-trash"></i></button>'
394+ )
395+ . attr ( "data-row" , idx )
396+ . attr ( "title" , "Delete this line" )
397+ . attr ( "data-toggle" , "tooltip" ) ;
398+
399+ const addBtn = $ (
400+ '<button type="button" class="btn btn-primary btn-xs add-static-row"><i class="fa fa-fw fa-plus"></i></button>'
401+ )
402+ . attr ( "data-row" , idx )
403+ . attr ( "title" , "Add new line after this" )
404+ . attr ( "data-toggle" , "tooltip" ) ;
405+
406+ const tr = $ ( "<tr></tr>" )
407+
382408 if ( parsed === "advanced" ) {
383- const tr = $ (
384- '<tr class="table-warning"><td colspan="4" style="font-style:italic;color:#888;">Advanced settings present in line ' +
385- ( idx + 1 ) +
386- "</td></tr>"
387- ) ;
409+ tr . addClass ( "table-warning" )
410+ . append (
411+ '<td colspan="3" class="text-muted"><em>Advanced settings present in line</em> ' +
412+ ( idx + 1 ) +
413+ "</td>" ,
414+ )
415+
416+ // Keep the original data
388417 tr . data ( "original-line" , line ) ;
389- tbody . append ( tr ) ;
390- continue ;
418+
419+ // Disable the save button on advanced rows
420+ saveBtn
421+ . addClass ( "disabled" )
422+ . prop ( "disabled" , true )
423+ . attr ( "title" , "Disabled" ) ;
424+
425+ } else {
426+ // Append 3 cells containing parsed values, with placeholder for empty hwaddr
427+ tr . append ( $ ( '<td contenteditable="true" class="static-hwaddr"></td>' ) . text ( parsed . hwaddr ) )
428+ . append ( $ ( '<td contenteditable="true" class="static-ipaddr"></td>' ) . text ( parsed . ipaddr ) )
429+ . append (
430+ $ ( '<td contenteditable="true" class="static-hostname"></td>' ) . text ( parsed . hostname ) ,
431+ ) ;
391432 }
392433
393- const tr = $ ( "<tr>" )
394- . append ( $ ( '<td contenteditable="true" class="static-hwaddr"></td>' ) )
395- . append ( $ ( '<td contenteditable="true" class="static-ipaddr"></td>' ) )
396- . append ( $ ( '<td contenteditable="true" class="static-hostname"></td>' ) )
397- . append (
398- $ ( "<td></td>" )
399- . append (
400- $ (
401- '<button type="button" class="btn btn-success btn-xs save-static-row"><i class="fa fa-fw fa-check"></i></button>'
402- )
403- . attr ( "data-row" , idx )
404- . attr ( "title" , "Confirm changes to this line" )
405- . attr ( "data-toggle" , "tooltip" )
406- )
407- . append ( " " )
408- . append (
409- $ (
410- '<button type="button" class="btn btn-danger btn-xs delete-static-row"><i class="fa fa-fw fa-trash"></i></button>'
411- )
412- . attr ( "data-row" , idx )
413- . attr ( "title" , "Delete this line" )
414- . attr ( "data-toggle" , "tooltip" )
415- )
416- . append ( " " )
417- . append (
418- $ (
419- '<button type="button" class="btn btn-primary btn-xs add-static-row"><i class="fa fa-fw fa-plus"></i></button>'
420- )
421- . attr ( "data-row" , idx )
422- . attr ( "title" , "Add new line after this" )
423- . attr ( "data-toggle" , "tooltip" )
424- )
425- ) ;
426- // Set cell values, with placeholder for empty hwaddr
427- tr . find ( ".static-hwaddr" ) . text ( parsed . hwaddr ) ;
428- tr . find ( ".static-ipaddr" ) . text ( parsed . ipaddr ) ;
429- tr . find ( ".static-hostname" ) . text ( parsed . hostname ) ;
434+ // Append a last cell containing the buttons
435+ tr . append (
436+ $ ( "<td></td>" )
437+ . append ( saveBtn )
438+ . append ( " " )
439+ . append ( delBtn )
440+ . append ( " " )
441+ . append ( addBtn )
442+ ) ;
443+
430444 tbody . append ( tr ) ;
431445 }
432446
0 commit comments