Finish edit functionality (limit admin)

This commit is contained in:
Aaron Lee 2021-10-26 22:29:39 +08:00
parent 862a9bd9ce
commit 35acf7a64b
9 changed files with 178 additions and 74 deletions

5
.gitignore vendored
View file

@ -1,7 +1,4 @@
*.DS_Store *.DS_Store
*.env *.env
test.py test*.*
demoData/*
dummyData/*
users.txt
__pycache__/* __pycache__/*

View file

@ -76,3 +76,10 @@ def addZeroesUntil(str, number):
else: else:
str = str + '0' str = str + '0'
return addZeroesUntil(str, number) return addZeroesUntil(str, number)
# MANAGE
def removeprefix(s, prefix):
if s.startswith(prefix):
return s[len(prefix):]
return s

View file

@ -3,12 +3,6 @@ from functions import *
manage = Blueprint('manage', __name__) manage = Blueprint('manage', __name__)
def removeprefix(s, prefix):
if s.startswith(prefix):
return s[len(prefix):]
return s
def manageProcess(fCommand, fData): def manageProcess(fCommand, fData):
if (check_login_status()): if (check_login_status()):
return redirect('/logout') return redirect('/logout')
@ -134,8 +128,8 @@ def manageProcess(fCommand, fData):
absData[p][h[0]][h[1]][num] = { absData[p][h[0]][h[1]][num] = {
"name": hrData[num]['name'], "name": hrData[num]['name'],
"eng_name": hrData[num]['eng_name'], "eng_name": hrData[num]['eng_name'],
"alr_fill": ('signature' in tmpAbsData[currDate][p] and "alr_fill": (('signature' in tmpAbsData[currDate][p]) and
cclass['class_id'] in tmpAbsData[currDate][p]['signature']), (cclass['class_id'] in tmpAbsData[currDate][p]['signature'] or 'STUD_AFFAIR_OFFICE' in tmpAbsData[currDate][p]['signature'])),
"absent": False if not num in tmpAbsData[currDate][p] else tmpAbsData[currDate][p][num] "absent": False if not num in tmpAbsData[currDate][p] else tmpAbsData[currDate][p][num]
} }
return render_template('group_teach.html', dateKeys=sorted(tmpAbsData.keys()), cclass=cclass, absData=absData, dow=dow, currDate=currDate, tmpAbsData=tmpAbsData, confirmed=confirmed) return render_template('group_teach.html', dateKeys=sorted(tmpAbsData.keys()), cclass=cclass, absData=absData, dow=dow, currDate=currDate, tmpAbsData=tmpAbsData, confirmed=confirmed)
@ -254,8 +248,6 @@ def group_teach_publish():
else: else:
db.child("Homerooms").child(h[0]).child(h[1]).child( db.child("Homerooms").child(h[0]).child(h[1]).child(
"Absent").child(date).child(period).update({'notes': notes}, session['token']) "Absent").child(date).child(period).update({'notes': notes}, session['token'])
# upload notes
os.remove(os.path.join('temp', rand)) os.remove(os.path.join('temp', rand))
return redirect('/manage') return redirect('/manage')
@ -269,15 +261,6 @@ 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():
@ -310,6 +293,52 @@ def homeroom_abs_publish():
return redirect('/manage') return redirect('/manage')
@manage.route('/manage/edit_abs', methods=['POST'])
def edit_abs():
if (check_login_status() or not check_permission()):
return redirect('/logout')
refresh_token()
date = request.form['date']
homeroom = request.form['homeroom'].split('^')
period = request.form['period']
signature = "https://firebasestorage.googleapis.com/v0/b/attendance-be176.appspot.com/o/stud_affairs.png?alt=media"
formData = request.form.to_dict()
notes = ""
oldData = list(db.child("Homerooms").child(homeroom[0]).child(homeroom[1]).child(
"Absent").child(date).child(period).shallow().get(session['token']).val())
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'])
cfrmstatus = db.child("Homerooms").child(homeroom[0]).child(
homeroom[1]).child("Absent").child(date).get(session['token']).val()
if "confirm" in cfrmstatus:
db.child("Homerooms").child(homeroom[0]).child(homeroom[1]).child(
"Absent").child(date).update({'notes': cfrmstatus['notes'] + '; (確認後學務處有更改)'}, session['token'])
if 'notes' in request.form:
notes = request.form['notes']
formData.pop('notes')
formData.pop('date')
formData.pop('homeroom')
formData.pop('period')
for i in formData:
i = i.split('^')
db.child("Homerooms").child(homeroom[0]).child(
homeroom[1]).child("Absent").child(date).child(period).update({i[1]: int(i[0])}, session['token'])
db.child("Homerooms").child(homeroom[0]).child(homeroom[1]).child(
"Absent").child(date).child(period).update({'notes': notes}, session['token'])
if cfrmstatus[period]['name'] == 'GP':
db.child("Homerooms").child(homeroom[0]).child(
homeroom[1]).child("Absent").child(date).child(period).child("signature").set({'STUD_AFFAIR_OFFICE': signature}, session['token'])
db.child("Homerooms").child(homeroom[0]).child(
homeroom[1]).child("Absent").child(date).child(period).child("names").set({'STUD_AFFAIR_OFFICE': "學務處已編輯"}, session['token'])
else:
db.child("Homerooms").child(homeroom[0]).child(
homeroom[1]).child("Absent").child(date).child(period).child("signature").set(signature, session['token'])
return redirect('/manage/admin/'+homeroom[0]+'/'+homeroom[1]+'/'+date)
@manage.route('/manage/homeroom_confirm', methods=['POST']) @manage.route('/manage/homeroom_confirm', methods=['POST'])
def homeroom_confirm(): def homeroom_confirm():
if (check_login_status()): if (check_login_status()):

View file

@ -24,3 +24,55 @@ function redirAdmin() {
$('.container').hide(); $('.container').hide();
$('#loading').show(); $('#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();
}

View file

@ -57,7 +57,6 @@ function showSignaturePad() {
resizeCanvas(); resizeCanvas();
} }
function afterSelAbs(period) { function afterSelAbs(period) {
var tobeformArr = [];
$('#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').attr('disabled', 'disabled');

BIN
static/stud_affairs.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
static/stud_affairs.xcf Normal file

Binary file not shown.

View file

@ -66,8 +66,8 @@
<div class="col">座號</div> <div class="col">座號</div>
<div class="col">姓名</div> <div class="col">姓名</div>
<div class="col">英文姓名</div> <div class="col">英文姓名</div>
{% for p in periods %} {% for i in periods %}
<div class="col">{{p}}</div> <div class="col">{{i}}</div>
{% endfor %} {% endfor %}
</div> </div>
<div class="row title"> <div class="row title">
@ -76,11 +76,8 @@
<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">{{absData[currDate][i]['name']}} <div class="col">
{% if 'changed' in absData[currDate][i] %} {{absData[currDate][i]['name']}}</div>
<span style="color: red;">(換)</span>
{% endif %}
</div>
{% endfor %} {% endfor %}
</div> </div>
<div class="row title"> <div class="row title">
@ -93,7 +90,6 @@
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
{% if data != None %}
{% for i in homeroomData %} {% for i in homeroomData %}
<div class="row"> <div class="row">
<div class="col">{{homeroomCode[0]}}{{homeroomCode[1]}}</div> <div class="col">{{homeroomCode[0]}}{{homeroomCode[1]}}</div>
@ -101,23 +97,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 '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'] or 'STUD_AFFAIR_OFFICE' in 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 %}
@ -135,7 +131,28 @@
{% endfor %} {% endfor %}
</div> </div>
{% endfor %} {% endfor %}
{% if showUpload == '1' %}
<div class="row">
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
{% for i in periods %}
<div id="btns-{{i}}" class="col">
{% if ('signature' in absData[currDate][i] or 'confirm' in absData[currDate][i]) %}
<button class="btn btn-danger afterSelButton" onclick="edit('{{i|string}}')">編輯
<br>{{absData[currDate][i]['name']}}</button>
{% endif %} {% endif %}
</div>
{% endfor %}
</div>
{% endif %}
<form action="/manage/edit_abs" id="postHomeroomAbs" hidden="hidden" method="post">
<input type="text" id="HR-date" name="date" value="{{currDate}}">
<input type="text" id="HR-period" name="period" value="">
<input type="text" id="HR-notes" name="notes" value="">
<input type="text" id="HR-homeroom" name="homeroom" value="{{homeroomCode[0]}}^{{homeroomCode[1]}}">
</form>
{% for c in range(periods|length + 1) %} {% for c in range(periods|length + 1) %}
{% if c % 4 == 0 %} {% if c % 4 == 0 %}
<div class="row signatures"> <div class="row signatures">
@ -153,7 +170,8 @@
{% if absData[currDate][periods[c-1]]['name'] == 'GP' %} {% if absData[currDate][periods[c-1]]['name'] == 'GP' %}
{% if 'signature' in absData[currDate][periods[c-1]] %} {% if 'signature' in absData[currDate][periods[c-1]] %}
{% for i in absData[currDate][periods[c-1]]['signature'] %} {% for i in absData[currDate][periods[c-1]]['signature'] %}
<div class="row needborder">{{periods[c-1]}}: {{absData[currDate][periods[c-1]]['teacher']}}: {{i}}: <div class="row needborder">{{periods[c-1]}}:
{{absData[currDate][periods[c-1]]['teacher']}}: {{i}}:
{{absData[currDate][periods[c-1]]['names'][i]}}</div> {{absData[currDate][periods[c-1]]['names'][i]}}</div>
<div class="row"><img src="{{absData[currDate][periods[c-1]]['signature'][i]}}" alt=""> <div class="row"><img src="{{absData[currDate][periods[c-1]]['signature'][i]}}" alt="">
{% if loop.index == loop.length %} {% if loop.index == loop.length %}
@ -162,7 +180,8 @@
</div> </div>
{% endfor %} {% endfor %}
{% else %} {% else %}
<div class="row needborder">{{periods[c-1]}}: {{absData[currDate][periods[c-1]]['teacher']}}: No <div class="row needborder">{{periods[c-1]}}:
{{absData[currDate][periods[c-1]]['teacher']}}: No
Signature Signature
</div> </div>
<div class="row"></div> <div class="row"></div>
@ -171,8 +190,8 @@
<div class="row needborder">{{periods[c-1]}}: {{absData[currDate][periods[c-1]]['name']}}: <div class="row needborder">{{periods[c-1]}}: {{absData[currDate][periods[c-1]]['name']}}:
{{absData[currDate][periods[c-1]]['teacher']}} {{absData[currDate][periods[c-1]]['teacher']}}
</div> </div>
<div class="row"><img src="{{absData[currDate][periods[c-1]]['signature']}}" <div class="row"><img src="{{absData[currDate][periods[c-1]]['signature']}}" alt=""><br>備註:
alt=""><br>備註:{{absData[currDate][periods[c-1]]['notes']}}</div> {{absData[currDate][periods[c-1]]['notes']}}</div>
{% endif %} {% endif %}
{% endif %} {% endif %}
</div> </div>
@ -181,6 +200,29 @@
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>
<div id="finalCheck" class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false"
tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-xl">
<form onsubmit="return false;">
<div class="modal-content">
<div class="modal-body">
<div class="alert alert-danger margin-top" id="allPresentWarning" role="alert">
<h4 class="alert-heading">請確認更改Please confirm that you are editting records!</h4>
</div>
<h3 class="margin-top">Notes 備註欄</h3>
<input type="textarea" class="form-control" name="notes" id="subjectNotes"
placeholder="Enter Notes 請輸入備註" style="width: 80%; margin-left: 10%;" row="3">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" onclick="location.reload();">Cancel
取消</button>
<button type="submit" class="btn btn-primary submitButton" onclick="submitForm()">Submit
提交</button>
</div>
</div>
</form>
</div>
</div>
{% if showUpload == '1' %} {% if showUpload == '1' %}
<div class="row margin-top"> <div class="row margin-top">
<div class="col"> <div class="col">
@ -204,7 +246,9 @@
</div> </div>
{% endif %} {% endif %}
</div> </div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"></script>
<script type="text/javascript" src="/static/jquery.min.js"></script> <script type="text/javascript" src="/static/jquery.min.js"></script>
<div id="loading" style="text-align:center; width:100%; display:none;"><img src="/static/loading.gif" alt="" <div id="loading" style="text-align:center; width:100%; display:none;"><img src="/static/loading.gif" alt=""
style="height:100%;" /> style="height:100%;" />

View file

@ -94,7 +94,7 @@
<p class="highlightAbs n-1 view-n-{{i}}">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'] or 'STUD_AFFAIR_OFFICE' in absData[currDate][j]['signature'])%}
<p class="highlightAbs n-1 view-n-{{i}}">V</p> <p class="highlightAbs n-1 view-n-{{i}}">V</p>
{% else %} {% else %}
<p class="highlightAbs n-2 view-n-{{i}}"></p> <p class="highlightAbs n-2 view-n-{{i}}"></p>
@ -125,11 +125,9 @@
<div class="col"></div> <div class="col"></div>
{% for i in periods %} {% for i in periods %}
<div id="btns-{{i}}" 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 (absData[currDate][i]['name'] == 'GP' or 'confirm' in absData[currDate]) %} {% if (absData[currDate][i]['name'] == 'GP' or 'confirm' in absData[currDate] or 'signature' in
<button class="btn btn-danger afterSelButton" disabled="disabled"></button> absData[currDate][i]) %}
{% elif ('signature' in absData[currDate][i]) %} <button class="btn btn-primary afterSelButton" disabled="disabled"></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}}', 'newSubmit')">Confirm<br>{{absData[currDate][i]['name']}}</button> onclick="afterSelAbs('{{i|string}}', 'newSubmit')">Confirm<br>{{absData[currDate][i]['name']}}</button>
@ -242,28 +240,6 @@
{% for i in periods %} {% for i in periods %}
periodData['{{i}}'] = '{{ absData[currDate][i]['name'] }}' periodData['{{i}}'] = '{{ absData[currDate][i]['name'] }}'
{% endfor %} {% endfor %}
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>");
}
</script> </script>
<script src="/static/pagejs/homeroom.js"></script> <script src="/static/pagejs/homeroom.js"></script>
<script src="/static/time.js"></script> <script src="/static/time.js"></script>