Added if there is no error from the api, a notification will appear and the button will change its name

This commit is contained in:
Данил 2022-09-25 11:06:58 +03:00
parent 8409cd7b75
commit 2b3b95d697

View file

@ -2,75 +2,16 @@ $.ajax({
url: "http://localhost:8080/api/get/settings", url: "http://localhost:8080/api/get/settings",
type: "GET", type: "GET",
success: function(data){ success: function(data){
if(data["autostart"] === 1) {
$("#autorunSwitch").attr("checked", "true");
$("#autorunText").text("On");
}
if(data["autochangewallpaper"] === 1) { if(data["autochangewallpaper"] === 1) {
$("#autosetWallpaperSwitch").attr("checked", "true"); $("#autosetWallpaperSwitch").attr("checked", "true");
$("#autosetWallpaperText").text("On"); $("#autosetWallpaperText").text("On");
} }
} if(data["startup"] === 1) {
$("#startupSwitch").attr("checked", "true");
}) $("#startupText").text("On");
$("#autorunSwitch").click(function(){
$.ajax({
url: "http://localhost:8080/api/get/settings",
type: "GET",
success: function(data){
if(data["autostart"] === 1){
$.ajax({
url: "http://localhost:8080/api/update/settings",
type: "POST",
data: {
autostart: 0
},
success: function(){
$.ajax({
url: "http://localhost:8080/api/update/del/startapp",
type: "POST",
success: function(data){
$(".toast-body").text(data.message);
let toastLiveExample = document.getElementById('liveToast')
let toast = new bootstrap.Toast(toastLiveExample)
toast.show()
if(data.status) {
$("#autorunSwitch").removeAttr("checked");
$("#autorunText").text("Off");
} }
} }
}) });
}
})
} else {
$.ajax({
url: "http://localhost:8080/api/update/settings",
type: "POST",
data: {
autostart: 1
},
success: function(){
$.ajax({
url: "http://localhost:8080/api/update/add/startapp",
type: "POST",
success: function(data){
$(".toast-body").text(data.message);
let toastLiveExample = document.getElementById('liveToast')
let toast = new bootstrap.Toast(toastLiveExample)
toast.show()
if(data.status) {
$("#autorunSwitch").attr("checked", "true");
$("#autorunText").text("On");
}
}
})
}
})
}
}
});
})
$("#autosetWallpaperSwitch").click(function(){ $("#autosetWallpaperSwitch").click(function(){
$.ajax({ $.ajax({
@ -84,11 +25,18 @@ $("#autosetWallpaperSwitch").click(function(){
data: { data: {
autochangewallpaper: 0 autochangewallpaper: 0
}, },
success: function(){ success: function(data){
if(data.status) {
$("#autosetWallpaperSwitch").removeAttr("checked"); $("#autosetWallpaperSwitch").removeAttr("checked");
$("#autosetWallpaperText").text("Off"); $("#autosetWallpaperText").text("Off");
$(".toast-body").text(data.message);
let toastLiveExample = document.getElementById('liveToast');
let toast = new bootstrap.Toast(toastLiveExample);
toast.show();
} }
}) }
});
} else { } else {
$.ajax({ $.ajax({
url: "http://localhost:8080/api/update/settings", url: "http://localhost:8080/api/update/settings",
@ -96,12 +44,94 @@ $("#autosetWallpaperSwitch").click(function(){
data: { data: {
autochangewallpaper: 1 autochangewallpaper: 1
}, },
success: function(){ success: function(data){
if(data.status) {
$("#autosetWallpaperSwitch").attr("checked", "true"); $("#autosetWallpaperSwitch").attr("checked", "true");
$("#autosetWallpaperText").text("On"); $("#autosetWallpaperText").text("On");
}
}) $(".toast-body").text(data.message);
let toastLiveExample = document.getElementById('liveToast');
let toast = new bootstrap.Toast(toastLiveExample);
toast.show();
} else {
$(".toast-body").text("Could not remove the program from autorun.");
let toastLiveExample = document.getElementById('liveToast');
let toast = new bootstrap.Toast(toastLiveExample);
toast.show();
} }
} }
}); });
}) }
}
});
});
$("#startupSwitch").click(function() {
$.ajax({
url: "http://localhost:8080/api/get/settings",
type: "GET",
success: function (data) {
if (data["startup"] === 1) {
$.ajax({
url: "http://localhost:8080/api/update/settings",
type: "POST",
data: {
startup: 0
},
success: function () {
$.ajax({
url: "http://localhost:8080/api/update/del/startup",
type: "POST",
success: function(data){
if(data.status) {
$("#startupSwitch").removeAttr("checked");
$("#startupText").text("Off");
$(".toast-body").text(data.message);
let toastLiveExample = document.getElementById('liveToast');
let toast = new bootstrap.Toast(toastLiveExample);
toast.show();
} else {
$(".toast-body").text("Failed to apply settings.");
let toastLiveExample = document.getElementById('liveToast');
let toast = new bootstrap.Toast(toastLiveExample);
toast.show();
}
}
});
}
});
} else {
$.ajax({
url: "http://localhost:8080/api/update/settings",
type: "POST",
data: {
startup: 1
},
success: function () {
$.ajax({
url: "http://localhost:8080/api/update/set/startup",
type: "POST",
success: function(data){
if(data.status) {
$("#startupSwitch").attr("checked", "true");
$("#startupText").text("On");
$(".toast-body").text(data.message);
let toastLiveExample = document.getElementById('liveToast');
let toast = new bootstrap.Toast(toastLiveExample);
toast.show();
} else {
$(".toast-body").text("Failed to apply settings.");
let toastLiveExample = document.getElementById('liveToast');
let toast = new bootstrap.Toast(toastLiveExample);
toast.show();
}
}
});
}
});
}
}
});
});