diff --git a/web/static/scripts/switch.js b/web/static/scripts/switch.js index 8858059..5a23242 100644 --- a/web/static/scripts/switch.js +++ b/web/static/scripts/switch.js @@ -2,75 +2,16 @@ $.ajax({ url: "http://localhost:8080/api/get/settings", type: "GET", success: function(data){ - if(data["autostart"] === 1) { - $("#autorunSwitch").attr("checked", "true"); - $("#autorunText").text("On"); - } if(data["autochangewallpaper"] === 1) { $("#autosetWallpaperSwitch").attr("checked", "true"); $("#autosetWallpaperText").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"); - } - } - }) - } - }) - } + if(data["startup"] === 1) { + $("#startupSwitch").attr("checked", "true"); + $("#startupText").text("On"); } - }); -}) + } +}); $("#autosetWallpaperSwitch").click(function(){ $.ajax({ @@ -84,11 +25,18 @@ $("#autosetWallpaperSwitch").click(function(){ data: { autochangewallpaper: 0 }, - success: function(){ - $("#autosetWallpaperSwitch").removeAttr("checked"); - $("#autosetWallpaperText").text("Off"); + success: function(data){ + if(data.status) { + $("#autosetWallpaperSwitch").removeAttr("checked"); + $("#autosetWallpaperText").text("Off"); + + $(".toast-body").text(data.message); + let toastLiveExample = document.getElementById('liveToast'); + let toast = new bootstrap.Toast(toastLiveExample); + toast.show(); + } } - }) + }); } else { $.ajax({ url: "http://localhost:8080/api/update/settings", @@ -96,12 +44,94 @@ $("#autosetWallpaperSwitch").click(function(){ data: { autochangewallpaper: 1 }, - success: function(){ - $("#autosetWallpaperSwitch").attr("checked", "true"); - $("#autosetWallpaperText").text("On"); + success: function(data){ + if(data.status) { + $("#autosetWallpaperSwitch").attr("checked", "true"); + $("#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(); + } } - }) + }); } } }); -}) \ No newline at end of file +}); + +$("#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(); + } + } + }); + } + }); + } + } + }); +}); \ No newline at end of file