mirror of
https://github.com/pi-hole/web.git
synced 2025-12-20 02:38:28 +00:00
@@ -7,7 +7,7 @@
|
||||
|
||||
/* global utils:false, apiFailure:false, updateFtlInfo:false, processGroupResult:false, delGroupItems:false */
|
||||
|
||||
var table;
|
||||
let table;
|
||||
|
||||
function handleAjaxError(xhr, textStatus) {
|
||||
if (textStatus === "timeout") {
|
||||
@@ -20,7 +20,7 @@ function handleAjaxError(xhr, textStatus) {
|
||||
table.draw();
|
||||
}
|
||||
|
||||
$(function () {
|
||||
$(() => {
|
||||
$("#btnAdd").on("click", addGroup);
|
||||
|
||||
table = $("#groupsTable").DataTable({
|
||||
@@ -44,7 +44,7 @@ $(function () {
|
||||
{
|
||||
targets: 1,
|
||||
className: "select-checkbox",
|
||||
render: function () {
|
||||
render() {
|
||||
return "";
|
||||
},
|
||||
},
|
||||
@@ -53,18 +53,18 @@ $(function () {
|
||||
render: $.fn.dataTable.render.text(),
|
||||
},
|
||||
],
|
||||
drawCallback: function () {
|
||||
drawCallback() {
|
||||
// Hide buttons if all groups were deleted
|
||||
// if there is one row, it's the default group
|
||||
var hasRows = this.api().rows({ filter: "applied" }).data().length > 1;
|
||||
const hasRows = this.api().rows({ filter: "applied" }).data().length > 1;
|
||||
$(".datatable-bt").css("visibility", hasRows ? "visible" : "hidden");
|
||||
|
||||
$('button[id^="deleteGroup_"]').on("click", deleteGroup);
|
||||
},
|
||||
rowCallback: function (row, data) {
|
||||
var dataId = utils.hexEncode(data.name);
|
||||
rowCallback(row, data) {
|
||||
const dataId = utils.hexEncode(data.name);
|
||||
$(row).attr("data-id", dataId);
|
||||
var tooltip =
|
||||
const tooltip =
|
||||
"Added: " +
|
||||
utils.datetime(data.date_added, false) +
|
||||
"\nLast modified: " +
|
||||
@@ -74,7 +74,7 @@ $(function () {
|
||||
$("td:eq(1)", row).html(
|
||||
'<input id="name_' + dataId + '" title="' + tooltip + '" class="form-control">'
|
||||
);
|
||||
var nameEl = $("#name_" + dataId, row);
|
||||
const nameEl = $("#name_" + dataId, row);
|
||||
nameEl.val(data.name);
|
||||
nameEl.on("change", editGroup);
|
||||
|
||||
@@ -85,7 +85,7 @@ $(function () {
|
||||
(data.enabled ? " checked" : "") +
|
||||
">"
|
||||
);
|
||||
var enabledEl = $("#enabled_" + dataId, row);
|
||||
const enabledEl = $("#enabled_" + dataId, row);
|
||||
enabledEl.bootstrapToggle({
|
||||
on: "Enabled",
|
||||
off: "Disabled",
|
||||
@@ -96,15 +96,15 @@ $(function () {
|
||||
enabledEl.on("change", editGroup);
|
||||
|
||||
$("td:eq(3)", row).html('<input id="comment_' + dataId + '" class="form-control">');
|
||||
var comment = data.comment !== null ? data.comment : "";
|
||||
var commentEl = $("#comment_" + dataId, row);
|
||||
const comment = data.comment !== null ? data.comment : "";
|
||||
const commentEl = $("#comment_" + dataId, row);
|
||||
commentEl.val(comment);
|
||||
commentEl.on("change", editGroup);
|
||||
|
||||
$("td:eq(4)", row).empty();
|
||||
// Show delete button for all but the default group
|
||||
if (data.id !== 0) {
|
||||
var button =
|
||||
const button =
|
||||
'<button type="button" class="btn btn-danger btn-xs" id="deleteGroup_' +
|
||||
dataId +
|
||||
'" data-id="' +
|
||||
@@ -125,7 +125,7 @@ $(function () {
|
||||
text: '<span class="far fa-square"></span>',
|
||||
titleAttr: "Select All",
|
||||
className: "btn-sm datatable-bt selectAll",
|
||||
action: function () {
|
||||
action() {
|
||||
table.rows({ page: "current" }).select();
|
||||
},
|
||||
},
|
||||
@@ -133,7 +133,7 @@ $(function () {
|
||||
text: '<span class="far fa-plus-square"></span>',
|
||||
titleAttr: "Select All",
|
||||
className: "btn-sm datatable-bt selectMore",
|
||||
action: function () {
|
||||
action() {
|
||||
table.rows({ page: "current" }).select();
|
||||
},
|
||||
},
|
||||
@@ -147,9 +147,9 @@ $(function () {
|
||||
text: '<span class="far fa-trash-alt"></span>',
|
||||
titleAttr: "Delete Selected",
|
||||
className: "btn-sm datatable-bt deleteSelected",
|
||||
action: function () {
|
||||
action() {
|
||||
// For each ".selected" row ...
|
||||
var ids = [];
|
||||
const ids = [];
|
||||
$("tr.selected").each(function () {
|
||||
// ... add the row identified by "data-id".
|
||||
ids.push({ item: $(this).attr("data-id") });
|
||||
@@ -171,11 +171,11 @@ $(function () {
|
||||
],
|
||||
stateSave: true,
|
||||
stateDuration: 0,
|
||||
stateSaveCallback: function (settings, data) {
|
||||
stateSaveCallback(settings, data) {
|
||||
utils.stateSaveCallback("groups-table", data);
|
||||
},
|
||||
stateLoadCallback: function () {
|
||||
var data = utils.stateLoadCallback("groups-table");
|
||||
stateLoadCallback() {
|
||||
const data = utils.stateLoadCallback("groups-table");
|
||||
|
||||
// Return if not available
|
||||
if (data === null) {
|
||||
@@ -190,7 +190,7 @@ $(function () {
|
||||
});
|
||||
|
||||
// Disable autocorrect in the search box
|
||||
var input = document.querySelector("input[type=search]");
|
||||
const input = document.querySelector("input[type=search]");
|
||||
if (input !== null) {
|
||||
input.setAttribute("autocomplete", "off");
|
||||
input.setAttribute("autocorrect", "off");
|
||||
@@ -198,8 +198,9 @@ $(function () {
|
||||
input.setAttribute("spellcheck", false);
|
||||
}
|
||||
|
||||
table.on("init select deselect", function () {
|
||||
table.on("init select deselect", () => {
|
||||
// if the Default group is selected, undo the selection of it
|
||||
// eslint-disable-next-line unicorn/prefer-includes
|
||||
if (table.rows({ selected: true }).data().pluck("id").indexOf(0) !== -1) {
|
||||
table.rows(0).deselect();
|
||||
}
|
||||
@@ -207,8 +208,8 @@ $(function () {
|
||||
utils.changeBulkDeleteStates(table);
|
||||
});
|
||||
|
||||
table.on("order.dt", function () {
|
||||
var order = table.order();
|
||||
table.on("order.dt", () => {
|
||||
const order = table.order();
|
||||
if (order[0][0] !== 0 || order[0][1] !== "asc") {
|
||||
$("#resetButton").removeClass("hidden");
|
||||
} else {
|
||||
@@ -216,7 +217,7 @@ $(function () {
|
||||
}
|
||||
});
|
||||
|
||||
$("#resetButton").on("click", function () {
|
||||
$("#resetButton").on("click", () => {
|
||||
table.order([[0, "asc"]]).draw();
|
||||
$("#resetButton").addClass("hidden");
|
||||
});
|
||||
@@ -237,15 +238,15 @@ function addGroup() {
|
||||
// Check if the user wants to add multiple groups (space or newline separated)
|
||||
// If so, split the input and store it in an array, however, do not split
|
||||
// group names enclosed in quotes
|
||||
var names = utils
|
||||
let names = utils
|
||||
.escapeHtml($("#new_name"))
|
||||
.val()
|
||||
.match(/(?:[^\s"]+|"[^"]*")+/g)
|
||||
.map(function (name) {
|
||||
.map(name => {
|
||||
return name.replaceAll(/(^"|"$)/g, "");
|
||||
});
|
||||
// Remove empty elements
|
||||
names = names.filter(function (el) {
|
||||
names = names.filter(el => {
|
||||
return el !== "";
|
||||
});
|
||||
const groupStr = JSON.stringify(names);
|
||||
@@ -268,10 +269,10 @@ function addGroup() {
|
||||
contentType: "application/json; charset=utf-8",
|
||||
data: JSON.stringify({
|
||||
name: names,
|
||||
comment: comment,
|
||||
comment,
|
||||
enabled: true,
|
||||
}),
|
||||
success: function (data) {
|
||||
success(data) {
|
||||
utils.enableAll();
|
||||
utils.listsAlert("group", names, data);
|
||||
$("#new_name").val("");
|
||||
@@ -282,7 +283,7 @@ function addGroup() {
|
||||
// Update number of groups in the sidebar
|
||||
updateFtlInfo();
|
||||
},
|
||||
error: function (data, exception) {
|
||||
error(data, exception) {
|
||||
apiFailure(data);
|
||||
utils.enableAll();
|
||||
utils.showAlert("error", "", "Error while adding new group", data.responseText);
|
||||
@@ -300,8 +301,8 @@ function editGroup() {
|
||||
const enabled = tr.find("#enabled_" + id).is(":checked");
|
||||
const comment = tr.find("#comment_" + id).val();
|
||||
|
||||
var done = "edited";
|
||||
var notDone = "editing";
|
||||
let done = "edited";
|
||||
let notDone = "editing";
|
||||
switch (elem) {
|
||||
case "enabled_" + id:
|
||||
if (!enabled) {
|
||||
@@ -335,16 +336,16 @@ function editGroup() {
|
||||
processData: false,
|
||||
contentType: "application/json; charset=utf-8",
|
||||
data: JSON.stringify({
|
||||
name: name,
|
||||
comment: comment,
|
||||
enabled: enabled,
|
||||
name,
|
||||
comment,
|
||||
enabled,
|
||||
}),
|
||||
success: function (data) {
|
||||
success(data) {
|
||||
utils.enableAll();
|
||||
processGroupResult(data, "group", done, notDone);
|
||||
table.ajax.reload(null, false);
|
||||
},
|
||||
error: function (data, exception) {
|
||||
error(data, exception) {
|
||||
apiFailure(data);
|
||||
utils.enableAll();
|
||||
utils.showAlert(
|
||||
|
||||
Reference in New Issue
Block a user