Skip to content

Commit d00b7a3

Browse files
committed
Add function to restore previous values when user cancels the edition
Signed-off-by: RD WebDesign <[email protected]>
1 parent 0232439 commit d00b7a3

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

scripts/pi-hole/js/settings-dns.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,26 @@ function saveRecord() {
274274
}
275275

276276
function restoreRecord() {
277+
// Find the row index
278+
const index = $(this).attr("data-index");
279+
280+
// Reset values
281+
$("#enabled_" + index).prop("checked", $("#enabled_" + index).attr("data-initial-value"));
282+
$("#network_" + index).val($("#network_" + index).attr("data-initial-value"));
283+
$("#ip_" + index).val($("#ip_" + index).attr("data-initial-value"));
284+
$("#domain_" + index).val($("#domain_" + index).attr("data-initial-value"));
285+
286+
// Show cancellation message
287+
utils.showAlert("info", "fas fa-undo", "Operation canceled", "Original values restored");
288+
289+
// Finish the edition disabling the fields
290+
$(this).closest("tr").find("td input").prop("disabled", true);
291+
292+
// Show EDIT and DELETE buttons. Hide SAVE and UNDO buttons
293+
$(this).siblings('[id^="edit"]').show();
294+
$(this).siblings('[id^="delete"]').show();
295+
$(this).siblings('[id^="save"]').hide();
296+
$(this).hide();
277297
}
278298

279299
function deleteRecord() {

0 commit comments

Comments
 (0)