mirror of
https://github.com/pi-hole/web.git
synced 2025-12-20 10:48:26 +00:00
Reduce code-duplication by moving the addFromQueryLog() function into utils.js. This also fixes non-visible modals on the long-term query log page.
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -244,6 +244,81 @@ function getGraphType() {
|
||||
return localStorage.getItem("barchart_chkbox") === "false" ? "line" : "bar";
|
||||
}
|
||||
|
||||
function addFromQueryLog(domain, list) {
|
||||
var token = $("#token").text();
|
||||
var alertModal = $("#alertModal");
|
||||
var alProcessing = alertModal.find(".alProcessing");
|
||||
var alSuccess = alertModal.find(".alSuccess");
|
||||
var alFailure = alertModal.find(".alFailure");
|
||||
var alNetworkErr = alertModal.find(".alFailure #alNetErr");
|
||||
var alCustomErr = alertModal.find(".alFailure #alCustomErr");
|
||||
var alList = "#alList";
|
||||
var alDomain = "#alDomain";
|
||||
|
||||
// Exit the function here if the Modal is already shown (multiple running interlock)
|
||||
if (alertModal.css("display") !== "none") {
|
||||
return;
|
||||
}
|
||||
|
||||
var listtype = list === "white" ? "Whitelist" : "Blacklist";
|
||||
|
||||
alProcessing.children(alDomain).html(domain);
|
||||
alProcessing.children(alList).html(listtype);
|
||||
alertModal.modal("show");
|
||||
|
||||
// add Domain to List after Modal has faded in
|
||||
alertModal.one("shown.bs.modal", function () {
|
||||
$.ajax({
|
||||
url: "scripts/pi-hole/php/groups.php",
|
||||
method: "post",
|
||||
data: {
|
||||
domain: domain,
|
||||
list: list,
|
||||
token: token,
|
||||
action: "replace_domain",
|
||||
comment: "Added from Query Log"
|
||||
},
|
||||
success: function (response) {
|
||||
alProcessing.hide();
|
||||
if (!response.success) {
|
||||
// Failure
|
||||
alNetworkErr.hide();
|
||||
alCustomErr.html(response.message);
|
||||
alFailure.fadeIn(1000);
|
||||
setTimeout(function () {
|
||||
alertModal.modal("hide");
|
||||
}, 10000);
|
||||
} else {
|
||||
// Success
|
||||
alSuccess.children(alDomain).html(domain);
|
||||
alSuccess.children(alList).html(listtype);
|
||||
alSuccess.fadeIn(1000);
|
||||
setTimeout(function () {
|
||||
alertModal.modal("hide");
|
||||
}, 2000);
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
// Network Error
|
||||
alProcessing.hide();
|
||||
alNetworkErr.show();
|
||||
alFailure.fadeIn(1000);
|
||||
setTimeout(function () {
|
||||
alertModal.modal("hide");
|
||||
}, 8000);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Reset Modal after it has faded out
|
||||
alertModal.one("hidden.bs.modal", function () {
|
||||
alProcessing.show();
|
||||
alSuccess.add(alFailure).hide();
|
||||
alProcessing.add(alSuccess).children(alDomain).html("").end().children(alList).html("");
|
||||
alCustomErr.html("");
|
||||
});
|
||||
}
|
||||
|
||||
window.utils = (function () {
|
||||
return {
|
||||
escapeHtml: escapeHtml,
|
||||
@@ -261,6 +336,7 @@ window.utils = (function () {
|
||||
stateLoadCallback: stateLoadCallback,
|
||||
getGraphType: getGraphType,
|
||||
validateMAC: validateMAC,
|
||||
validateHostname: validateHostname
|
||||
validateHostname: validateHostname,
|
||||
addFromQueryLog: addFromQueryLog
|
||||
};
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user