diff --git a/powerdnsadmin/static/custom/js/custom.js b/powerdnsadmin/static/custom/js/custom.js index 051a2e0..e4b72b1 100644 --- a/powerdnsadmin/static/custom/js/custom.js +++ b/powerdnsadmin/static/custom/js/custom.js @@ -12,13 +12,7 @@ function applyChanges(data, url, showResult, refreshPage) { console.log("Applied changes successfully."); console.log(data); if (showResult) { - var modal = $("#modal_success"); - if (data['msg']) { - modal.find('.modal-body p').text(data['msg']); - } else { - modal.find('.modal-body p').text("Applied changes successfully"); - } - modal.modal('show'); + showSuccessModal(data['msg'] || "Applied changes successfully"); } if (refreshPage) { location.reload(true); @@ -27,10 +21,8 @@ function applyChanges(data, url, showResult, refreshPage) { error : function(jqXHR, status) { console.log(jqXHR); - var modal = $("#modal_error"); var responseJson = jQuery.parseJSON(jqXHR.responseText); - modal.find('.modal-body p').text(responseJson['msg']); - modal.modal('show'); + showErrorModal(responseJson['msg']); } }); } @@ -50,18 +42,14 @@ function applyRecordChanges(data, domain) { }); console.log("Applied changes successfully.") - var modal = $("#modal_success"); - modal.find('.modal-body p').text("Applied changes successfully"); - modal.modal('show'); + showSuccessModal("Applied changes successfully"); setTimeout(() => {window.location.reload()}, 2000); }, error : function(jqXHR, status) { console.log(jqXHR); - var modal = $("#modal_error"); var responseJson = jQuery.parseJSON(jqXHR.responseText); - modal.find('.modal-body p').text(responseJson['msg']); - modal.modal('show'); + showErrorModal(responseJson['msg']); } }); } diff --git a/powerdnsadmin/templates/admin_history.html b/powerdnsadmin/templates/admin_history.html index a3f0fd4..aa16c4a 100644 --- a/powerdnsadmin/templates/admin_history.html +++ b/powerdnsadmin/templates/admin_history.html @@ -446,9 +446,7 @@ if(!canSearch) { - var modal = $("#modal_error"); - modal.find('.modal-body p').text("Please fill out the " + main_field + " field."); - modal.modal('show'); + showErrorModal("Please fill out the " + main_field + " field."); } else { diff --git a/powerdnsadmin/templates/base.html b/powerdnsadmin/templates/base.html index bb9be5b..649663a 100644 --- a/powerdnsadmin/templates/base.html +++ b/powerdnsadmin/templates/base.html @@ -298,6 +298,18 @@ } }); }); + + function showErrorModal(message) { + var modal = $('#modal_error'); + modal.find('.modal-body p').text(message); + modal.modal('show'); + } + + function showSuccessModal(message) { + var modal = $("#modal_success"); + modal.find('.modal-body p').text(message); + modal.modal('show'); + } {% endif %} {%- endassets %} diff --git a/powerdnsadmin/templates/domain.html b/powerdnsadmin/templates/domain.html index d5e85fc..d821e6a 100755 --- a/powerdnsadmin/templates/domain.html +++ b/powerdnsadmin/templates/domain.html @@ -251,9 +251,7 @@ // handle apply changes button $(document.body).on("click",".button_apply_changes", function() { if (nNew || nEditing) { - var modal = $("#modal_error"); - modal.find('.modal-body p').text("Previous record not saved. Please save it before applying the changes."); - modal.modal('show'); + showErrorModal("Previous record not saved. Please save it before applying the changes."); return; } @@ -277,9 +275,7 @@ // handle add record button $(document.body).on("click", ".button_add_record", function (e) { if (nNew || nEditing) { - var modal = $("#modal_error"); - modal.find('.modal-body p').text("Previous record not saved. Please save it before adding more record."); - modal.modal('show'); + showErrorModal("Previous record not saved. Please save it before adding more record."); return; } // clear search first diff --git a/powerdnsadmin/templates/domain_remove.html b/powerdnsadmin/templates/domain_remove.html index e0b0eb8..6ac5401 100644 --- a/powerdnsadmin/templates/domain_remove.html +++ b/powerdnsadmin/templates/domain_remove.html @@ -73,9 +73,7 @@ $(document.body).on("click", ".button_delete", function(e) { e.stopPropagation(); if ( $("#domainid").val() == 0 ){ - var modal = $("#modal_error"); - modal.find('.modal-body p').text("Please select domain to remove."); - modal.modal('show'); + showErrorModal("Please select domain to remove."); return; } diff --git a/powerdnsadmin/templates/template_edit.html b/powerdnsadmin/templates/template_edit.html index f716293..89faebc 100644 --- a/powerdnsadmin/templates/template_edit.html +++ b/powerdnsadmin/templates/template_edit.html @@ -192,9 +192,7 @@ // handle apply changes button $(document.body).on("click",".button_apply_changes", function() { if (nNew || nEditing) { - var modal = $("#modal_error"); - modal.find('.modal-body p').text("Previous record not saved. Please save it before applying the changes."); - modal.modal('show'); + showErrorModal("Previous record not saved. Please save it before applying the changes."); return; } @@ -217,9 +215,7 @@ // handle add record button $(document.body).on("click", ".button_add_record", function (e) { if (nNew || nEditing) { - var modal = $("#modal_error"); - modal.find('.modal-body p').text("Previous record not saved. Please save it before adding more record."); - modal.modal('show'); + showErrorModal("Previous record not saved. Please save it before adding more record."); return; } // clear search first