-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (35 loc) · 1.23 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
window.onload = function() {
console.log("Window loaded!")
function parseCmd() {
// Get app info.
var idx = parseInt(this.getAttribute("data-index"), 10)
var type = parseInt(this.getAttribute("data-type"), 10)
// Send POST request to back-end that submits command.
fetch("/backend/submit", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ index: idx, type: type })
})
.then(data => {
if (type == 0)
console.log("Launched application successfully!")
else
console.log("Stopped application successfully!")
})
.catch((err) => {
console.error(err)
})
}
// Handle on clicks for app start buttons.
var appStarts = document.getElementsByClassName("app-start")
for (var i = 0; i < appStarts.length; i++) {
appStarts[i].addEventListener("click", parseCmd)
}
// Handle on clicks for app stop buttons.
var appStops = document.getElementsByClassName("app-stop")
for (var i = 0; i < appStops.length; i++) {
appStops[i].addEventListener("click", parseCmd)
}
}