-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathsubmit_achievements.html
More file actions
172 lines (143 loc) · 5.12 KB
/
Copy pathsubmit_achievements.html
File metadata and controls
172 lines (143 loc) · 5.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Submit Achievements</title>
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}" />
<script src="{{ url_for('static', filename='script.js') }}"></script>
</head>
<body>
<div class="toggle-container">
<button id="mode-toggle">Dark Mode 🌙</button>
</div>
{% if error %}
<div class="error-box"
style="background-color: #ffebee; color: #c62828; padding: 15px; border-radius: 8px; border: 1px solid #ef9a9a; margin-bottom: 20px; text-align: center; font-weight: bold;">
⚠️ {{ error }}
</div>
{% endif %}
{% if success %}
<div class="welcome-text">
<p style="color: #2e7d32; font-weight: bold;">
Congratulations! <br> {{ success }}
</p>
</div>
<div class="button">
<a href="/teacher-dashboard" class="btn-primary">Back to Dashboard</a>
</div>
{% else %}
<form action="/submit_achievements" method="POST" enctype="multipart/form-data">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<div class="user-details">
<div class="input-box">
<span class="details">Student ID</span>
<input type="text" name="student_id" placeholder="Enter Student ID" required>
</div>
<div class="input-box">
<span class="details">Certificate File</span>
<input type="file" name="certificate" required>
</div>
</div>
<div class="button" style="display:flex; gap:0.5rem; align-items:center;">
<button id="previewBtn" type="button" class="btn-secondary">Preview</button>
<input type="submit" value="Register Achievement">
</div>
<!-- Preview modal -->
<div id="previewModal" class="modal" role="dialog" aria-modal="true" aria-labelledby="previewTitle" hidden>
<div class="modal-content" role="document">
<h2 id="previewTitle">Preview Achievement</h2>
<div class="preview-body">
<p><strong>Student ID:</strong> <span id="previewStudentId"> </span></p>
<p><strong>Certificate file:</strong> <span id="previewFileName"> </span></p>
</div>
<div class="modal-actions" style="display:flex; gap:0.5rem; justify-content:flex-end; margin-top:1rem;">
<button id="editBtn" type="button" class="btn-secondary">Back to edit</button>
<button id="confirmBtn" type="button" class="btn-primary">Confirm & Submit</button>
</div>
</div>
</div>
</form>
{% endif %}
<style>
.modal:not([hidden]) {
position: fixed;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
background: rgba(0, 0, 0, 0.4);
padding: 1rem;
z-index: 9999;
}
.modal-content {
background: var(--card-bg, #fff);
color: var(--text-color, #111);
max-width: 480px;
width: 100%;
border-radius: 8px;
padding: 1rem 1.25rem;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}
.preview-body p {
margin: 0.5rem 0;
}
@media (max-width: 520px) {
.modal-content {
padding: 0.75rem;
}
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function () {
const previewBtn = document.getElementById('previewBtn');
const previewModal = document.getElementById('previewModal');
const previewStudentId = document.getElementById('previewStudentId');
const previewFileName = document.getElementById('previewFileName');
const editBtn = document.getElementById('editBtn');
const confirmBtn = document.getElementById('confirmBtn');
let form = document.querySelector('form[action="/submit_achievements"]') ||
document.querySelector('form');
let studentInput = form ? form.querySelector('input[name="student_id"]') : null;
let fileInput = form ? form.querySelector('input[type="file"][name="certificate"]') : null;
function openPreview() {
previewStudentId.textContent = studentInput?.value || '(none)';
let fileName = '(none)';
if (fileInput?.files?.length) {
fileName = fileInput.files[0].name;
}
previewFileName.textContent = fileName;
previewModal.removeAttribute('hidden');
editBtn.focus();
}
function closePreview() {
previewModal.setAttribute('hidden', '');
previewBtn.focus();
}
previewBtn?.addEventListener('click', (e) => {
e.preventDefault();
openPreview();
});
editBtn?.addEventListener('click', (e) => {
e.preventDefault();
closePreview();
});
confirmBtn?.addEventListener('click', (e) => {
e.preventDefault();
closePreview();
form.submit();
});
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && !previewModal.hasAttribute('hidden')) {
closePreview();
}
});
previewModal?.addEventListener('click', (e) => {
if (e.target === previewModal) {
closePreview();
}
});
});
</script>
</body>
</html>