/* Pi-hole: A black hole for Internet advertisements
* (c) 2023 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. */
/* global utils:false, apiFailure: false, applyCheckboxRadioStyle: false, saveSettings:false */
/* exported createDynamicConfigTabs */
function addAllowedValues(allowed) {
if (typeof allowed === "object") {
return (
"
";
}
}
function generateRow(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];
generateRow(topic, key + "." + subkey, subvalue);
});
return;
}
// else: we have a setting we can display
var box =
'
"
);
});
Object.keys(data.config).forEach(function (topic) {
var value = data.config[topic];
generateRow(topic, topic, value, data);
});
$("#advanced-overlay").hide();
$("button[id='save']").on("click", function () {
saveSettings();
});
applyCheckboxRadioStyle();
applyOnlyChanged();
})
.fail(function (data) {
apiFailure(data);
});
}
function initOnlyChanged() {
const elem = $("#only-changed");
// Restore settings level from local storage (if available) or default to "false"
if (localStorage.getItem("only-changed") === null) {
localStorage.setItem("only-changed", "false");
}
elem.prop("checked", localStorage.getItem("only-changed") === "true");
elem.bootstrapToggle({
on: "Modified settings",
off: "All settings",
onstyle: "primary",
offstyle: "success",
size: "small",
width: "180px",
});
elem.on("change", function () {
localStorage.setItem("only-changed", $(this).prop("checked") ? "true" : "false");
applyOnlyChanged();
});
elem.bootstrapToggle(localStorage.getItem("only-changed") === "true" ? "on" : "off");
elem.trigger("change");
}
function applyOnlyChanged() {
if (localStorage.getItem("only-changed") === "true") {
// Hide all boxes that have a data-key attribute
$(".box-title[data-key]").not("[data-modified='true']").closest(".box").hide();
} else {
// Show all boxes that have a data-key attribute
$(".box-title[data-key]").closest(".box").show();
}
// Hide group headers on the all settings page after toggling to show only
// modified settings if there are no modified settings within that group. This
// prevents empty boxes when only-changed is enabled by hiding all boxes if
// the box does not have at least one visible box as a child
$(".box-title:not([data-key])").each(function () {
const box = $(this).closest(".box");
if (
box.find(".box-title[data-key]:visible").length === 0 &&
localStorage.getItem("only-changed") === "true"
) {
box.hide();
} else {
box.show();
}
});
}
$(document).ready(function () {
createDynamicConfigTabs();
initOnlyChanged();
});