Skip to content

Instantly share code, notes, and snippets.

@InersIn
Created October 11, 2020 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save InersIn/ed1f2f7ed3bc8af3ef8c12421861fc35 to your computer and use it in GitHub Desktop.
Save InersIn/ed1f2f7ed3bc8af3ef8c12421861fc35 to your computer and use it in GitHub Desktop.
(function(s, objectName) {
setupLinks = function() {
if (s.admin) {
var sl = document.getElementsByClassName("student-link");
for (i = 0; i < sl.length; i++) {
let name = sl[i].innerHTML;
sl[i].style.cursor = 'pointer';
sl[i].addEventListener("click", function() {
window.location = '/update-' + objectName + '/' + this.dataset.id;
});
}
}
};
updateForm = function() {
var submitButton = document.getElementsByClassName("update-record");
if (submitButton.length === 1) {
submitButton[0].addEventListener("click", function() {
var english = document.getElementById("english");
english = english.options[english.selectedIndex].value;
var science = document.getElementById("science");
science = science.options[science.selectedIndex].value;
var maths = document.getElementById("maths");
maths = maths.options[maths.selectedIndex].value;
var grades = new Set(["A", "B", "C", "D", "E", "F"]);
if (grades.has(english) && grades.has(science) && grades.has(maths)) {
document.getElementById('student-form').submit();
} else {
alert('Grades should only be between A - F');
}
});
}
};
setupLinks();
updateForm();
})(staff, 'student');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment