mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-04-19 19:59:13 +03:00
Use const instead of var for js variables
This commit is contained in:
parent
9617425033
commit
680e73c990
4 changed files with 38 additions and 38 deletions
|
@ -121,7 +121,7 @@ Wireguard Clients
|
||||||
{{define "bottom_js"}}
|
{{define "bottom_js"}}
|
||||||
<script>
|
<script>
|
||||||
function setClientStatus(clientID, status) {
|
function setClientStatus(clientID, status) {
|
||||||
var data = {"id": clientID, "status": status}
|
const data = {"id": clientID, "status": status};
|
||||||
$.ajax({
|
$.ajax({
|
||||||
cache: false,
|
cache: false,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
@ -133,7 +133,7 @@ Wireguard Clients
|
||||||
console.log("Set client " + clientID + " status to " + status)
|
console.log("Set client " + clientID + " status to " + status)
|
||||||
},
|
},
|
||||||
error: function (jqXHR, exception) {
|
error: function (jqXHR, exception) {
|
||||||
var responseJson = jQuery.parseJSON(jqXHR.responseText);
|
const responseJson = jQuery.parseJSON(jqXHR.responseText);
|
||||||
toastr.error(responseJson['message']);
|
toastr.error(responseJson['message']);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -141,23 +141,23 @@ Wireguard Clients
|
||||||
|
|
||||||
function resumeClient(clientID) {
|
function resumeClient(clientID) {
|
||||||
setClientStatus(clientID, true);
|
setClientStatus(clientID, true);
|
||||||
var divElement = document.getElementById("paused_" + clientID);
|
const divElement = document.getElementById("paused_" + clientID);
|
||||||
divElement.style.visibility = "hidden";
|
divElement.style.visibility = "hidden";
|
||||||
}
|
}
|
||||||
|
|
||||||
function pauseClient(clientID) {
|
function pauseClient(clientID) {
|
||||||
setClientStatus(clientID, false);
|
setClientStatus(clientID, false);
|
||||||
var divElement = document.getElementById("paused_" + clientID);
|
const divElement = document.getElementById("paused_" + clientID);
|
||||||
divElement.style.visibility = "visible";
|
divElement.style.visibility = "visible";
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
// modal_pause_client modal event
|
// modal_pause_client modal event
|
||||||
$('#modal_pause_client').on('show.bs.modal', function (event) {
|
$('#modal_pause_client').on('show.bs.modal', function (event) {
|
||||||
var button = $(event.relatedTarget);
|
const button = $(event.relatedTarget);
|
||||||
var client_id = button.data('clientid');
|
const client_id = button.data('clientid');
|
||||||
var client_name = button.data('clientname');
|
const client_name = button.data('clientname');
|
||||||
var modal = $(this);
|
const modal = $(this);
|
||||||
modal.find('.modal-body').text("You are about to disable client " + client_name);
|
modal.find('.modal-body').text("You are about to disable client " + client_name);
|
||||||
modal.find('#pause_client_confirm').val(client_id);
|
modal.find('#pause_client_confirm').val(client_id);
|
||||||
})
|
})
|
||||||
|
@ -165,7 +165,7 @@ Wireguard Clients
|
||||||
// pause_client_confirm button event
|
// pause_client_confirm button event
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$('#pause_client_confirm').click(function () {
|
$('#pause_client_confirm').click(function () {
|
||||||
var client_id = $(this).val();
|
const client_id = $(this).val();
|
||||||
pauseClient(client_id);
|
pauseClient(client_id);
|
||||||
$('#modal_pause_client').modal('hide');
|
$('#modal_pause_client').modal('hide');
|
||||||
});
|
});
|
||||||
|
@ -173,10 +173,10 @@ Wireguard Clients
|
||||||
|
|
||||||
// modal_remove_client modal event
|
// modal_remove_client modal event
|
||||||
$('#modal_remove_client').on('show.bs.modal', function (event) {
|
$('#modal_remove_client').on('show.bs.modal', function (event) {
|
||||||
var button = $(event.relatedTarget);
|
const button = $(event.relatedTarget);
|
||||||
var client_id = button.data('clientid');
|
const client_id = button.data('clientid');
|
||||||
var client_name = button.data('clientname');
|
const client_name = button.data('clientname');
|
||||||
var modal = $(this);
|
const modal = $(this);
|
||||||
modal.find('.modal-body').text("You are about to remove client " + client_name);
|
modal.find('.modal-body').text("You are about to remove client " + client_name);
|
||||||
modal.find('#remove_client_confirm').val(client_id);
|
modal.find('#remove_client_confirm').val(client_id);
|
||||||
})
|
})
|
||||||
|
@ -184,8 +184,8 @@ Wireguard Clients
|
||||||
// remove_client_confirm button event
|
// remove_client_confirm button event
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$('#remove_client_confirm').click(function () {
|
$('#remove_client_confirm').click(function () {
|
||||||
var client_id = $(this).val();
|
const client_id = $(this).val();
|
||||||
var data = {"id": client_id};
|
const data = {"id": client_id};
|
||||||
$.ajax({
|
$.ajax({
|
||||||
cache: false,
|
cache: false,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
@ -196,11 +196,11 @@ Wireguard Clients
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$('#modal_remove_client').modal('hide');
|
$('#modal_remove_client').modal('hide');
|
||||||
toastr.success('Removed client successfully');
|
toastr.success('Removed client successfully');
|
||||||
var divElement = document.getElementById('client_' + client_id);
|
const divElement = document.getElementById('client_' + client_id);
|
||||||
divElement.style.display = "none";
|
divElement.style.display = "none";
|
||||||
},
|
},
|
||||||
error: function(jqXHR, exception) {
|
error: function(jqXHR, exception) {
|
||||||
var responseJson = jQuery.parseJSON(jqXHR.responseText);
|
const responseJson = jQuery.parseJSON(jqXHR.responseText);
|
||||||
toastr.error(responseJson['message']);
|
toastr.error(responseJson['message']);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -106,12 +106,12 @@ Global Settings
|
||||||
{{define "bottom_js"}}
|
{{define "bottom_js"}}
|
||||||
<script>
|
<script>
|
||||||
function submitGlobalSettings() {
|
function submitGlobalSettings() {
|
||||||
var endpoint_address = $("#endpoint_address").val();
|
const endpoint_address = $("#endpoint_address").val();
|
||||||
var dns_servers = $("#dns_servers").val().split(",");
|
const dns_servers = $("#dns_servers").val().split(",");
|
||||||
var mtu = $("#mtu").val();
|
const mtu = $("#mtu").val();
|
||||||
var persistent_keepalive = $("#persistent_keepalive").val();
|
const persistent_keepalive = $("#persistent_keepalive").val();
|
||||||
var config_file_path = $("#config_file_path").val();
|
const config_file_path = $("#config_file_path").val();
|
||||||
var data = {"endpoint_address": endpoint_address, "dns_servers": dns_servers, "mtu": mtu, "persistent_keepalive": persistent_keepalive, "config_file_path": config_file_path};
|
const data = {"endpoint_address": endpoint_address, "dns_servers": dns_servers, "mtu": mtu, "persistent_keepalive": persistent_keepalive, "config_file_path": config_file_path};
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
cache: false,
|
cache: false,
|
||||||
|
@ -125,7 +125,7 @@ Global Settings
|
||||||
toastr.success('Update global settings successfully');
|
toastr.success('Update global settings successfully');
|
||||||
},
|
},
|
||||||
error: function(jqXHR, exception) {
|
error: function(jqXHR, exception) {
|
||||||
var responseJson = jQuery.parseJSON(jqXHR.responseText);
|
const responseJson = jQuery.parseJSON(jqXHR.responseText);
|
||||||
toastr.error(responseJson['message']);
|
toastr.error(responseJson['message']);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -223,7 +223,7 @@ Global Settings
|
||||||
// Use selected IP address from suggestion form
|
// Use selected IP address from suggestion form
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$('#btn_use_ip').click(function () {
|
$('#btn_use_ip').click(function () {
|
||||||
var ip = $('#ip_suggestion').select2('val');
|
const ip = $('#ip_suggestion').select2('val');
|
||||||
$('#endpoint_address').val(ip);
|
$('#endpoint_address').val(ip);
|
||||||
$('#modal_endpoint_address_suggestion').modal('hide');
|
$('#modal_endpoint_address_suggestion').modal('hide');
|
||||||
});
|
});
|
||||||
|
|
|
@ -80,8 +80,8 @@
|
||||||
</body>
|
</body>
|
||||||
<script>
|
<script>
|
||||||
function redirectNext() {
|
function redirectNext() {
|
||||||
var urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
var nextURL = urlParams.get('next');
|
const nextURL = urlParams.get('next');
|
||||||
if (nextURL) {
|
if (nextURL) {
|
||||||
window.location.href = nextURL;
|
window.location.href = nextURL;
|
||||||
} else {
|
} else {
|
||||||
|
@ -92,9 +92,9 @@
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$('#btn_login').click(function () {
|
$('#btn_login').click(function () {
|
||||||
var username = $("#username").val();
|
const username = $("#username").val();
|
||||||
var password = $("#password").val();
|
const password = $("#password").val();
|
||||||
var data = {"username": username, "password": password}
|
const data = {"username": username, "password": password}
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -110,7 +110,7 @@
|
||||||
redirectNext();
|
redirectNext();
|
||||||
},
|
},
|
||||||
error: function(jqXHR, exception) {
|
error: function(jqXHR, exception) {
|
||||||
var responseJson = jQuery.parseJSON(jqXHR.responseText);
|
const responseJson = jQuery.parseJSON(jqXHR.responseText);
|
||||||
document.getElementById("message").innerHTML = '<p style="color:red">' + responseJson['message'] + '</p>';
|
document.getElementById("message").innerHTML = '<p style="color:red">' + responseJson['message'] + '</p>';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -117,9 +117,9 @@ Wireguard Server Settings
|
||||||
{{define "bottom_js"}}
|
{{define "bottom_js"}}
|
||||||
<script>
|
<script>
|
||||||
function submitServerInterfaceSetting() {
|
function submitServerInterfaceSetting() {
|
||||||
var addresses = $("#addresses").val().split(",");
|
const addresses = $("#addresses").val().split(",");
|
||||||
var listen_port = $("#listen_port").val();
|
const listen_port = $("#listen_port").val();
|
||||||
var data = {"addresses": addresses, "listen_port": listen_port};
|
const data = {"addresses": addresses, "listen_port": listen_port};
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
cache: false,
|
cache: false,
|
||||||
|
@ -133,7 +133,7 @@ Wireguard Server Settings
|
||||||
toastr.success('Updated Wireguard server interface addresses successfully');
|
toastr.success('Updated Wireguard server interface addresses successfully');
|
||||||
},
|
},
|
||||||
error: function(jqXHR, exception) {
|
error: function(jqXHR, exception) {
|
||||||
var responseJson = jQuery.parseJSON(jqXHR.responseText);
|
const responseJson = jQuery.parseJSON(jqXHR.responseText);
|
||||||
toastr.error(responseJson['message']);
|
toastr.error(responseJson['message']);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -210,7 +210,7 @@ Wireguard Server Settings
|
||||||
$('#public_key').val(data['public_key']);
|
$('#public_key').val(data['public_key']);
|
||||||
},
|
},
|
||||||
error: function(jqXHR, exception) {
|
error: function(jqXHR, exception) {
|
||||||
var responseJson = jQuery.parseJSON(jqXHR.responseText);
|
const responseJson = jQuery.parseJSON(jqXHR.responseText);
|
||||||
toastr.error(responseJson['message']);
|
toastr.error(responseJson['message']);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -220,8 +220,8 @@ Wireguard Server Settings
|
||||||
// Show private key button event
|
// Show private key button event
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$('#btn_show_private_key').click(function () {
|
$('#btn_show_private_key').click(function () {
|
||||||
var privateElement = document.getElementById("private_key");
|
const privateElement = document.getElementById("private_key");
|
||||||
var btnElement = document.getElementById("btn_show_private_key");
|
const btnElement = document.getElementById("btn_show_private_key");
|
||||||
if (privateElement.type === 'password') {
|
if (privateElement.type === 'password') {
|
||||||
privateElement.type = 'text';
|
privateElement.type = 'text';
|
||||||
btnElement.innerText = 'Hide';
|
btnElement.innerText = 'Hide';
|
||||||
|
|
Loading…
Add table
Reference in a new issue