Made everything working

This commit is contained in:
DL6ER
2016-12-31 16:24:10 +00:00
parent 05f2df720e
commit a33301911a
2 changed files with 52 additions and 12 deletions

View File

@@ -6,13 +6,18 @@ var token = $("#token").html();
var listType = $("#list-type").html();
var fullName = listType === "white" ? "Whitelist" : "Blacklist";
function sub(index, entry) {
function sub(index, entry, arg) {
var domain = $("#"+index);
var locallistType = listType;
domain.hide("highlight");
if(arg === "wild")
{
locallistType = "wild";
}
$.ajax({
url: "scripts/pi-hole/php/sub.php",
method: "post",
data: {"domain":entry, "list":listType, "token":token},
data: {"domain":entry, "list":locallistType, "token":token},
success: function(response) {
if(response.length !== 0){
return;
@@ -34,6 +39,10 @@ function refresh(fade) {
}
if(fade) {
list.fadeOut(100);
if(listw)
{
listw.fadeOut(100);
}
}
$.ajax({
url: "scripts/pi-hole/php/get.php",
@@ -41,6 +50,10 @@ function refresh(fade) {
data: {"list":listType},
success: function(response) {
list.html("");
if(listw)
{
listw.html("");
}
var data = JSON.parse(response);
if(data.length === 0) {
@@ -57,6 +70,11 @@ function refresh(fade) {
"<li id=\"" + index + "\" class=\"list-group-item clearfix\">" + entry +
"<button class=\"btn btn-danger btn-xs pull-right\" type=\"button\">" +
"<span class=\"glyphicon glyphicon-trash\"></span></button></li>");
// Handle button
$("#list-wildcard #"+index+"").on("click", "button", function() {
sub(index, entry, "wild");
console.log("wild rm");
});
}
else
{
@@ -65,15 +83,19 @@ function refresh(fade) {
"<li id=\"" + index + "\" class=\"list-group-item clearfix\">" + entry +
"<button class=\"btn btn-danger btn-xs pull-right\" type=\"button\">" +
"<span class=\"glyphicon glyphicon-trash\"></span></button></li>");
// Handle button
$("#list #"+index+"").on("click", "button", function() {
sub(index, entry, "exact");
});
}
// Handle button
$("#list #"+index+"").on("click", "button", function() {
sub(index, entry);
});
});
}
list.fadeIn("fast");
list.fadeIn(100);
if(listw)
{
listw.fadeIn(100);
}
},
error: function(jqXHR, exception) {
$("#alFailure").show();
@@ -83,11 +105,16 @@ function refresh(fade) {
window.onload = refresh(false);
function add() {
function add(arg) {
var locallistType = listType;
var domain = $("#domain");
if(domain.val().length === 0){
return;
}
if(arg === "wild")
{
locallistType = "wild";
}
var alInfo = $("#alInfo");
var alSuccess = $("#alSuccess");
@@ -98,7 +125,7 @@ function add() {
$.ajax({
url: "scripts/pi-hole/php/add.php",
method: "post",
data: {"domain":domain.val(), "list":listType, "token":token},
data: {"domain":domain.val(), "list":locallistType, "token":token},
success: function(response) {
if (response.indexOf("not a valid argument") >= 0 ||
response.indexOf("is not a valid domain") >= 0) {
@@ -139,14 +166,19 @@ function add() {
$(document).keypress(function(e) {
if(e.which === 13 && $("#domain").is(":focus")) {
// Enter was pressed, and the input has focus
add();
add("exact");
}
});
// Handle buttons
$("#btnAdd").on("click", function() {
add();
add("exact");
});
$("#btnAddWildcard").on("click", function() {
add("wild");
});
$("#btnRefresh").on("click", function() {
refresh(true);
});