Add feedback to users

Signed-off-by: Mograine <ghiot.pierre@gmail.com>
This commit is contained in:
Mograine
2019-11-27 00:40:43 +01:00
parent 192ad7ce8b
commit ee7edb5fab
3 changed files with 34 additions and 16 deletions
+1 -8
View File
@@ -30,7 +30,7 @@
<!-- Alerts -->
<div id="alInfo" class="alert alert-info alert-dismissible fade in" role="alert" hidden="true">
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
Adding the custom DNS entry...
Updating the custom DNS entries...
</div>
<div id="alSuccess" class="alert alert-success alert-dismissible fade in" role="alert" hidden="true">
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
@@ -62,13 +62,6 @@
<th>Action</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Domain</th>
<th>IP</th>
<th>Action</th>
</tr>
</tfoot>
</table>
<button type="button" id="resetButton" hidden="true">Clear Filters</button>
</div>
+33 -6
View File
@@ -1,5 +1,26 @@
var table;
function showAlert(type, message)
{
var alertElement = null;
var messageElement = null;
switch (type)
{
case 'info': alertElement = $('#alInfo'); break;
case 'success': alertElement = $('#alSuccess'); break;
case 'warning': alertElement = $('#alWarning'); messageElement = $('#warn'); break;
case 'error': alertElement = $('#alFailure'); messageElement = $('#err'); break;
default: return;
}
if (messageElement != null)
messageElement.html(message);
alertElement.fadeIn(200);
alertElement.delay(8000).fadeOut(2000);
}
$(document).ready(function() {
$('#btnAdd').on('click', addCustomDNS);
@@ -25,19 +46,22 @@ function addCustomDNS()
var ip = $('#ip').val();
var domain = $('#domain').val();
showAlert('info');
$.ajax({
url: "scripts/pi-hole/php/customdns.php",
method: "post",
dataType: 'json',
data: {"action":"add", "ip" : ip, "domain": domain},
success: function(response) {
if (response.success)
if (response.success) {
showAlert('success');
table.ajax.reload();
}
else
alert(response.message);
showAlert('error', response.message);
},
error: function(jqXHR, exception) {
alert("Error while adding this custom DNS entry")
showAlert('error', "Error while adding this custom DNS entry");
}
});
}
@@ -47,19 +71,22 @@ function deleteCustomDNS()
var ip = $(this).attr("data-ip");
var domain = $(this).attr("data-domain");
showAlert('info');
$.ajax({
url: "scripts/pi-hole/php/customdns.php",
method: "post",
dataType: 'json',
data: {"action":"delete", "domain": domain, "ip": ip},
success: function(response) {
if (response.success)
if (response.success) {
showAlert('success');
table.ajax.reload();
}
else
alert(response.message);
showAlert('error', response.message);
},
error: function(jqXHR, exception) {
alert("Error while deleting this custom DNS entry");
showAlert('error', "Error while deleting this custom DNS entry");
console.log(exception);
}
});
-2
View File
@@ -82,7 +82,6 @@
return errorJsonResponse("This domain already has a custom DNS entry for an IPv" . $ipType);
exec("sudo pihole -a addcustomdns ".$ip." ".$domain);
exec("sudo pihole -a restartdns");
return successJsonResponse();
}
@@ -119,7 +118,6 @@
return errorJsonResponse("This domain/ip association does not exist");
exec("sudo pihole -a removecustomdns ".$ip." ".$domain);
exec("sudo pihole -a restartdns");
return successJsonResponse();
}