Attendance/static/pagejs/admin.js

126 lines
5.3 KiB
JavaScript
Raw Permalink Normal View History

2021-10-19 07:30:49 -07:00
function getHR() {
var grade = $('#sel-grade').val();
$('#sel-room').html('<option value="">請先選擇年級</option>');
if (grade === "") {
$('#sel-room').attr('disabled', 'disabled')
return
}
homerooms[grade].forEach(element => {
$('#sel-room').append(`<option value="${element}">${element}</option>`)
});
$('#sel-room').removeAttr('disabled')
}
function redirAdmin() {
if ($("#sel-room").val() == "") {
alert("請選擇年級 / 班級!");
return;
}
var url = "/manage/admin/" + $('#sel-grade').val() + "/" + $('#sel-room').val() + "/" + $('#date').val();
var new_form = document.createElement('form');
new_form.method = 'GET';
new_form.action = url;
document.body.appendChild(new_form);
new_form.submit();
$('.container').hide();
$('#loading').show();
}
function edit(string) {
$('.view-' + string).each(function (i, obj) {
var num = $(this.firstElementChild).attr('class').split(' ')[2].replace('view-n-', '');
if ($(this.firstElementChild).attr('class').split(' ')[1] == "n-1") {
$(this).html("")
$(this).append("<input type=\"checkbox\" class=\"tobeform 2^" + string + "^" + num + " late\" id=\"late^" + string + "^" + num + "\" onchange=\"unCheckAbs('" + string + "^" + num + "')\">");
$(this).append("\n<input type=\"checkbox\" class=\"tobeform 1^" + string + "^" + num + " absent\" id=\"absent^" + string + "^" + num + "\" onchange=\"unCheckLate('" + string + "^" + num + "')\">");
} else if ($(this.firstElementChild).attr('class').split(' ')[1] == "n-2") {
$(this).html("")
$(this).append("<input type=\"checkbox\" class=\"tobeform 2^" + string + "^" + num + " late\" id=\"late^" + string + "^" + num + "\" onchange=\"unCheckAbs('" + string + "^" + num + "')\">");
$(this).append("\n<input type=\"checkbox\" class=\"tobeform 1^" + string + "^" + num + " absent\" id=\"absent^" + string + "^" + num + "\" onchange=\"unCheckLate('" + string + "^" + num + "')\" checked>");
} else if ($(this.firstElementChild).attr('class').split(' ')[1] == "n-3") {
$(this).html("")
$(this).append("<input type=\"checkbox\" class=\"tobeform 2^" + string + "^" + num + " late\" id=\"late^" + string + "^" + num + "\" onchange=\"unCheckAbs('" + string + "^" + num + "')\" checked>");
$(this).append("\n<input type=\"checkbox\" class=\"tobeform 1^" + string + "^" + num + " absent\" id=\"absent^" + string + "^" + num + "\" onchange=\"unCheckLate('" + string + "^" + num + "')\">");
}
});
$('#btns-' + string).html("")
$('.afterSelButton').attr('disabled', 'disabled');
$('#btns-' + string).append("<button class=\"btn btn-secondary editSaveButton\" onclick=\"afterSelAbs('" + string + "', 'edit')\">Save</button>");
}
function unCheckLate(string) {
document.getElementById('late^' + string).checked = false;
}
function unCheckAbs(string) {
document.getElementById('absent^' + string).checked = false;
}
function afterSelAbs(period) {
$('#postHomeroomAbs #HR-period').attr('value', period);
$('.tobeform').attr('disabled', 'disabled');
$('.afterSelButton').attr('disabled', 'disabled');
$('.tobeform').each(function (i, obj) {
if ($(this).attr('class').split(' ')[1].split('^')[1] == period &&
$(this).is(":checked")) {
$('#postHomeroomAbs').append('<input type="checkbox" name="' + $(this).attr('class').split(' ')[1].split('^')[0] + '^'
+ $(this).attr('class').split(' ')[1].split('^')[2]
+ '" checked="checked">');
}
});
$('#finalCheck').modal('show');
}
function submitForm() {
$('#HR-notes').attr('value', $('#subjectNotes').val());
$('#postHomeroomAbs').submit();
$('#finalCheck').modal('hide');
$('.container').hide();
$('#loading').show();
2021-12-26 05:08:50 -08:00
}
function refresh_homeroom() {
var grade = $('#grade').val();
$('#class').html('<option value="">請先選擇年級</option>');
$('span#name').html = ""
if (grade === "") {
$('#class').attr('disabled', 'disabled')
return
}
// get keys in dict
var keys = Object.keys(students[grade]);
keys.forEach(element => {
$('#class').append(`<option value="${element}">${element}</option>`)
});
$('#class').removeAttr('disabled')
}
function refresh_numbers() {
var grade = $('#grade').val();
var class_ = $('#class').val();
$('span#name').html = ""
$('#number').html('<option value="">請先選擇年級、班級</option>');
if (grade === "") {
$('#class').attr('disabled', 'disabled')
if (clas_ !== "") return
} if (class_ === "") {
$('#number').attr('disabled', 'disabled')
return
}
// get keys in dict
var keys = Object.keys(students[grade][class_]);
keys.forEach(element => {
$('#number').append(`<option value="${element}">${element}</option>`)
});
$('#number').removeAttr('disabled')
}
function showName() {
var grade = $('#grade').val();
var class_ = $('#class').val();
var number = $('#number').val();
$('#name').html(students[grade][class_][number]);
}
function clearForm() {
document.getElementById('newabs').reset();
$('#class').attr('disabled', 'disabled')
$('#number').attr('disabled', 'disabled')
$('span#name').html = ""
}