summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--endpoint_index.go13
-rw-r--r--frontend/student.js59
-rw-r--r--templates/student.html6
3 files changed, 74 insertions, 4 deletions
diff --git a/endpoint_index.go b/endpoint_index.go
index a6aa441..e5c35ca 100644
--- a/endpoint_index.go
+++ b/endpoint_index.go
@@ -128,6 +128,14 @@ func handleIndex(w http.ResponseWriter, req *http.Request) {
}
return
}
+ sportRequired, err := getCourseTypeMinimumForYearGroup(department, sport)
+ if err != nil {
+ wstr(w, http.StatusInternalServerError, "Failed to get sport requirement")
+ }
+ nonSportRequired, err := getCourseTypeMinimumForYearGroup(department, nonSport)
+ if err != nil {
+ wstr(w, http.StatusInternalServerError, "Failed to get non-sport requirement")
+ }
err = tmpl.ExecuteTemplate(
w,
@@ -136,10 +144,15 @@ func handleIndex(w http.ResponseWriter, req *http.Request) {
Name string
Department string
Groups *map[string]groupT
+ Required struct {
+ Sport int
+ NonSport int
+ }
}{
username,
department,
&_groups,
+ struct{Sport int; NonSport int}{sportRequired, nonSportRequired},
},
)
if err != nil {
diff --git a/frontend/student.js b/frontend/student.js
index 3025e0f..40598b9 100644
--- a/frontend/student.js
+++ b/frontend/student.js
@@ -79,10 +79,25 @@ document.addEventListener("DOMContentLoaded", () => {
document.getElementById(
`tick${ courseIDs[i] }`
).checked = true
+ {
+ let courseType = document.
+ getElementById(`type${ courseIDs[i] }`).
+ textContent
+ document.getElementById(`${ courseType }-chosen`).
+ textContent = parseInt(document.
+ getElementById(`${ courseType }-chosen`).
+ textContent) + 1
+ }
if (gstate === 1) {
document.getElementById(
`tick${ courseIDs[i] }`
).disabled = false
+ if (parseInt(document.getElementById(`Sport-chosen`).textContent) >=
+ parseInt(document.getElementById(`Sport-required`).textContent) &&
+ parseInt(document.getElementById(`Non-sport-chosen`).textContent) >=
+ parseInt(document.getElementById(`Non-sport-required`).textContent)) {
+ document.getElementById("confirmbutton").disabled = false
+ }
}
}
}
@@ -96,6 +111,20 @@ document.addEventListener("DOMContentLoaded", () => {
checked = false
document.getElementById(`tick${ mar[1] }`).
indeterminate = false
+ {
+ let courseType = document.getElementById(`type${ mar[1] }`).
+ textContent
+ document.getElementById(`${ courseType }-chosen`).textContent =
+ parseInt(document.
+ getElementById(`${ courseType }-chosen`).
+ textContent) - 1
+ }
+ if (parseInt(document.getElementById(`Sport-chosen`).textContent) <
+ parseInt(document.getElementById(`Sport-required`).textContent) ||
+ parseInt(document.getElementById(`Non-sport-chosen`).textContent) <
+ parseInt(document.getElementById(`Non-sport-required`).textContent)) {
+ document.getElementById("confirmbutton").disabled = true
+ }
break
case "M":
document.getElementById(`selected${ mar[1] }`).
@@ -132,6 +161,21 @@ document.addEventListener("DOMContentLoaded", () => {
checked = true
document.getElementById(`tick${ mar[1] }`).
indeterminate = false
+ {
+ let courseType = document.getElementById(`type${ mar[1] }`).
+ textContent
+ document.getElementById(`${ courseType }-chosen`).textContent =
+ parseInt(document.
+ getElementById(`${ courseType }-chosen`).
+ textContent) + 1
+ }
+ if (parseInt(document.getElementById(`Sport-chosen`).textContent) >=
+ parseInt(document.getElementById(`Sport-required`).textContent) &&
+ parseInt(document.getElementById(`Non-sport-chosen`).textContent) >=
+ parseInt(document.getElementById(`Non-sport-required`).textContent) &&
+ gstate === 1) {
+ document.getElementById("confirmbutton").disabled = false
+ }
break
case "STOP":
gstate = 0
@@ -144,11 +188,18 @@ document.addEventListener("DOMContentLoaded", () => {
case "START":
gstate = 1
document.querySelectorAll(".courseitem").forEach(c => {
- if (c.querySelector(".selected-number").textContent !== c.querySelector(".max-number").textContent || c.querySelector(".coursecheckbox").checked) {
+ if (c.querySelector(".selected-number").textContent !==
+ c.querySelector(".max-number").textContent ||
+ c.querySelector(".coursecheckbox").checked) {
c.querySelector(".coursecheckbox").disabled = false
}
})
- document.getElementById("confirmbutton").disabled = false
+ if (parseInt(document.getElementById(`Sport-chosen`).textContent) >=
+ parseInt(document.getElementById(`Sport-required`).textContent) &&
+ parseInt(document.getElementById(`Non-sport-chosen`).textContent) >=
+ parseInt(document.getElementById(`Non-sport-required`).textContent)) {
+ document.getElementById("confirmbutton").disabled = false
+ }
document.getElementById("stateindicator").textContent = "enabled"
break
default:
@@ -179,7 +230,9 @@ document.addEventListener("DOMContentLoaded", () => {
case true:
c.indeterminate = true
document.querySelectorAll(".coursecheckbox").forEach(d => {
- if (d.checked === true && d.dataset.group === c.dataset.group && c.id !== d.id) {
+ if (d.checked === true &&
+ d.dataset.group === c.dataset.group &&
+ c.id !== d.id) {
d.indeterminate = true
socket.send(`N ${ d.id.slice(4) }`)
}
diff --git a/templates/student.html b/templates/student.html
index 6f48867..d06de4b 100644
--- a/templates/student.html
+++ b/templates/student.html
@@ -117,6 +117,9 @@
</div>
<div class="need-connection">
<div class="reading-width">
+ <p>
+ Course selections are <span style="font-weight: bold;" id="stateindicator">disabled</span>.
+ </p>
<table class="table-of-courses">
<thead>
<tr>
@@ -162,7 +165,8 @@
<td class="th-like" colspan="7">
<div class="flex-justify">
<div class="left">
- Course selections are <span id="stateindicator">disabled</span>
+ Sport: <span id="Sport-chosen">0</span>/<span id="Sport-required">{{ .Required.Sport }}</span>,
+ Non-sport: <span id="Non-sport-chosen">0</span>/<span id="Non-sport-required">{{ .Required.NonSport }}</span>
</div>
<div class="right">
<button id="confirmbutton" class="btn-primary btn" disabled>Confirm</button>