Homeroom edit functionality

This commit is contained in:
Aaron Lee 2021-10-15 20:29:53 +08:00
parent 9ae3fd8c2a
commit 94394334f4
2 changed files with 48 additions and 14 deletions

View file

@ -269,6 +269,15 @@ def homeroom_abs_publish():
homeroom = request.form['homeroom'].split('^') homeroom = request.form['homeroom'].split('^')
period = request.form['period'] period = request.form['period']
signature = request.form['signatureData'] signature = request.form['signatureData']
if (request.form['stype'] == 'edit'):
oldData = list(db.child("Homerooms").child(homeroom[0]).child(homeroom[1]).child(
"Absent").child(date).child(period).shallow().get(session['token']).val())
print(oldData, type(oldData))
for k in oldData:
if k == 'name' or k == 'teacher':
continue
db.child("Homerooms").child(homeroom[0]).child(homeroom[1]).child(
"Absent").child(date).child(period).child(k).remove(session['token'])
formData = request.form.to_dict() formData = request.form.to_dict()
notes = "" notes = ""
if "confirm" in db.child("Homerooms").child(homeroom[0]).child(homeroom[1]).child("Absent").child(date).get(session['token']).val(): if "confirm" in db.child("Homerooms").child(homeroom[0]).child(homeroom[1]).child("Absent").child(date).get(session['token']).val():
@ -288,6 +297,7 @@ def homeroom_abs_publish():
formData.pop('date') formData.pop('date')
formData.pop('homeroom') formData.pop('homeroom')
formData.pop('period') formData.pop('period')
formData.pop('stype')
for i in formData: for i in formData:
i = i.split('^') i = i.split('^')
db.child("Homerooms").child(homeroom[0]).child( db.child("Homerooms").child(homeroom[0]).child(

View file

@ -87,23 +87,23 @@
<div class="col">{{ homeroomData[i]['name'] }}</div> <div class="col">{{ homeroomData[i]['name'] }}</div>
<div class="col">{{ homeroomData[i]['eng_name'] }}</div> <div class="col">{{ homeroomData[i]['eng_name'] }}</div>
{% for j in periods %} {% for j in periods %}
<div class="col" {% if currPeriod==j %} style="background-color: #ffdf81;" {% endif %}> <div class="col view-{{j}}" {% if currPeriod==j %} style="background-color: #ffdf81;" {% endif %}>
{% if 'signature' in absData[currDate][j] %} {% if 'signature' in absData[currDate][j] %}
{% if i in absData[currDate][j] %} {% if i in absData[currDate][j] %}
{% if absData[currDate][j][i] == 1 %} {% if absData[currDate][j][i] == 1 %}
<p class="highlightAbs n-2">X</p> <p class="highlightAbs n-2 view-n-{{i}}">X</p>
{% else %} {% else %}
<p class="highlightAbs n-3">𝜑</p> <p class="highlightAbs n-3 view-n-{{i}}">𝜑</p>
{% endif %} {% endif %}
{% else %} {% else %}
{% if absData[currDate][j]['name'] != 'GP' %} {% if absData[currDate][j]['name'] != 'GP' %}
<p class="highlightAbs n-1">V</p> <p class="highlightAbs n-1 view-n-{{i}}">V</p>
{% else %} {% else %}
{% if (homeroomData[i]['GP_Class'][absData[currDate][j]['teacher']] in {% if (homeroomData[i]['GP_Class'][absData[currDate][j]['teacher']] in
absData[currDate][j]['signature'])%} absData[currDate][j]['signature'])%}
<p class="highlightAbs n-1">V</p> <p class="highlightAbs n-1 view-n-{{i}}">V</p>
{% else %} {% else %}
<p class="highlightAbs n-2"></p> <p class="highlightAbs n-2 view-n-{{i}}"></p>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endif %} {% endif %}
@ -130,14 +130,15 @@
<div class="col"></div> <div class="col"></div>
<div class="col"></div> <div class="col"></div>
{% for i in periods %} {% for i in periods %}
<div class="col" {% if currPeriod==i %} style="background-color: #ffdf81;" {% endif %}> <div id="btns-{{i}}" class="col" {% if currPeriod==i %} style="background-color: #ffdf81;" {% endif %}>
{% if ('signature' in absData[currDate][i] or absData[currDate][i]['name'] == 'GP' or {% if (absData[currDate][i]['name'] == 'GP' or 'confirm' in absData[currDate]) %}
'confirm' in absData[currDate]) %} <button class="btn btn-danger afterSelButton" disabled="disabled"></button>
<button class="btn btn-primary afterSelButton" disabled="disabled" {% elif ('signature' in absData[currDate][i]) %}
onclick="afterSelAbs('{{i|string}}')"></button> <button class="btn btn-danger afterSelButton" onclick="edit('{{i|string}}')">Edit
<br>{{absData[currDate][i]['name']}}</button>
{% else %} {% else %}
<button class="btn btn-primary afterSelButton" <button class="btn btn-primary afterSelButton"
onclick="afterSelAbs('{{i|string}}')">Confirm<br>{{absData[currDate][i]['name']}}</button> onclick="afterSelAbs('{{i|string}}', 'newSubmit')">Confirm<br>{{absData[currDate][i]['name']}}</button>
{% endif %} {% endif %}
</div> </div>
{% endfor %} {% endfor %}
@ -148,6 +149,7 @@
<input type="text" id="HR-signatureData" name="signatureData" value=""> <input type="text" id="HR-signatureData" name="signatureData" value="">
<input type="text" id="HR-notes" name="notes" value=""> <input type="text" id="HR-notes" name="notes" value="">
<input type="text" id="HR-homeroom" name="homeroom" value="{{homeroomCode[0]}}^{{homeroomCode[1]}}"> <input type="text" id="HR-homeroom" name="homeroom" value="{{homeroomCode[0]}}^{{homeroomCode[1]}}">
<input type="text" id="HR-type" name="stype" value="">
</form> </form>
{% if 'confirm' in absData[currDate] %} {% if 'confirm' in absData[currDate] %}
<button class="btn btn-primary margin-top afterSelButton" onclick="homeroomCfrm()" disabled="disabled"> <button class="btn btn-primary margin-top afterSelButton" onclick="homeroomCfrm()" disabled="disabled">
@ -282,11 +284,12 @@
resizeCanvas(); resizeCanvas();
$('html,body').unbind().animate({ scrollTop: $("#finalCheck").offset().top - $(".sticky-top").outerHeight() - 10 }, 'slow'); $('html,body').unbind().animate({ scrollTop: $("#finalCheck").offset().top - $(".sticky-top").outerHeight() - 10 }, 'slow');
} }
function afterSelAbs(period) { function afterSelAbs(period, typeofsubmit) {
var tobeformArr = []; var tobeformArr = [];
$("#postHomeroomAbs #HR-type").attr('value', typeofsubmit);
$('#postHomeroomAbs #HR-period').attr('value', period); $('#postHomeroomAbs #HR-period').attr('value', period);
$('.tobeform').attr('disabled', 'disabled'); $('.tobeform').attr('disabled', 'disabled');
$('.afterSelButton').attr('disabled', 'disabled'); $('.afterSelButton, .editSaveButton').attr('disabled', 'disabled');
$('#showSignPeriod').text(period); $('#showSignPeriod').text(period);
$('#showSignSubjectName').text(periodData[period]); $('#showSignSubjectName').text(periodData[period]);
var cnt = 0; var cnt = 0;
@ -305,6 +308,27 @@
// show signature pad // show signature pad
showSignaturePad() showSignaturePad()
} }
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 {
$(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 + "')\" checked>");
}
});
$('#btns-' + string).html("")
$('.afterSelButton').attr('disabled', 'disabled');
$('#btns-' + string).append("<button class=\"btn btn-secondary editSaveButton\" onclick=\"afterSelAbs('" + string + "', 'edit')\">Save</button>");
}
function homeroomCfrm() { function homeroomCfrm() {
hrCfrm = true; hrCfrm = true;
$('.tobeform').attr('disabled', 'disabled'); $('.tobeform').attr('disabled', 'disabled');