Files
web/scripts/pi-hole/js/settings.js
DL6ER f0f26c13ed Add 2FA frontend handling
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-03-08 20:46:56 +01:00

68 lines
1.9 KiB
JavaScript

/* Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
// Handle hiding of alerts
$(function () {
$("[data-hide]").on("click", function () {
$(this)
.closest("." + $(this).attr("data-hide"))
.hide();
});
});
// Globally available function to set config values
// eslint-disable-next-line no-unused-vars
function setConfigValues(topic, key, value) {
// If the value is an object, we need to recurse
if (!("description" in value)) {
Object.keys(value).forEach(function (subkey) {
var subvalue = value[subkey];
setConfigValues(topic, key + "." + subkey, subvalue);
});
return;
}
// else: we have a setting we can set
var escapedKey = key.replace(/\./g, "\\.");
switch (value.type) {
case "enum (string)": {
// Remove all options from select
$("#" + escapedKey + " option").remove();
// Add allowed select items (if available)
value.allowed.forEach(function (allowedValue) {
var newopt = $("<option></option>")
.attr("value", allowedValue.item)
.text(allowedValue.description);
$("#" + escapedKey).append(newopt);
});
// Select the current value
$("#" + escapedKey + "-" + value.value).trigger("click");
break;
}
case "boolean": {
// Select checkboxes (if available)
$("#" + escapedKey).prop("checked", value.value);
break;
}
case "string array": {
// Set input field values from array (if available)
$("#" + escapedKey).val(value.value.join("\n"));
break;
}
default: {
// Set input field values (if available)
$("#" + escapedKey).val(value.value);
}
}
}