/* 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. */ /* global utils:false */ var table; var groups = []; var token = $("#token").text(); var GETDict = {}; var showtype = "all"; function get_groups() { $.post( "scripts/pi-hole/php/groups.php", { action: "get_groups", token: token }, function (data) { groups = data.data; initTable(); }, "json" ); } $(document).ready(function () { window.location.search .substr(1) .split("&") .forEach(function (item) { GETDict[item.split("=")[0]] = item.split("=")[1]; }); if ("type" in GETDict && (GETDict.type === "white" || GETDict.type === "black")) { showtype = GETDict.type; } // sync description fields, reset inactive inputs on tab change $('a[data-toggle="tab"]').on("shown.bs.tab", function () { var tabHref = $(this).attr("href"); var val; if (tabHref === "#tab_domain") { val = $("#new_regex_comment").val(); $("#new_domain_comment").val(val); $("#new_regex").val(""); } else if (tabHref === "#tab_regex") { val = $("#new_domain_comment").val(); $("#new_regex_comment").val(val); $("#new_domain").val(""); $("#wildcard_checkbox").prop("checked", false); } }); // Disable autocorrect in the search box var input = document.querySelector("input[type=search]"); input.setAttribute("autocomplete", "off"); input.setAttribute("autocorrect", "off"); input.setAttribute("autocapitalize", "off"); input.setAttribute("spellcheck", false); $("#add2black, #add2white").on("click", addDomain); get_groups(); }); function initTable() { table = $("#domainsTable").DataTable({ ajax: { url: "scripts/pi-hole/php/groups.php", data: { action: "get_domains", showtype: showtype, token: token }, type: "POST" }, order: [[0, "asc"]], columns: [ { data: "id", visible: false }, { data: "domain" }, { data: "type", searchable: false }, { data: "enabled", searchable: false }, { data: "comment" }, { data: "groups", searchable: false }, { data: null, width: "80px", orderable: false } ], drawCallback: function () { $('button[id^="deleteDomain_"]').on("click", deleteDomain); }, rowCallback: function (row, data) { $(row).attr("data-id", data.id); var tooltip = "Added: " + utils.datetime(data.date_added) + "\nLast modified: " + utils.datetime(data.date_modified) + "\nDatabase ID: " + data.id; $("td:eq(0)", row).html( '' + data.domain + "" ); var whitelist_options = ""; if (showtype === "all" || showtype === "white") { whitelist_options = '" + '"; } var blacklist_options = ""; if (showtype === "all" || showtype === "black") { blacklist_options = '" + '"; } $("td:eq(1)", row).html( '" ); var typeEl = $("#type_" + data.id, row); typeEl.on("change", editDomain); var disabled = data.enabled === 0; $("td:eq(2)", row).html( '" ); var statusEl = $("#status_" + data.id, row); statusEl.bootstrapToggle({ on: "Enabled", off: "Disabled", size: "small", onstyle: "success", width: "80px" }); statusEl.on("change", editDomain); $("td:eq(3)", row).html(''); var commentEl = $("#comment_" + data.id, row); commentEl.val(data.comment); commentEl.on("change", editDomain); // Show group assignment field only if in full domain management mode if (table.column(5).visible()) { $("td:eq(4)", row).empty(); $("td:eq(4)", row).append( '
' + '
' ); var selectEl = $("#multiselect_" + data.id, row); // Add all known groups for (var i = 0; i < groups.length; i++) { var extra = ""; if (!groups[i].enabled) { extra = " (disabled)"; } selectEl.append( $("