-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhomework.html
More file actions
333 lines (311 loc) · 10.9 KB
/
homework.html
File metadata and controls
333 lines (311 loc) · 10.9 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>布置課業</title>
<link href="https://fonts.googleapis.com/css2?family=Noto+Serif+TC:wght@400;700&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Noto Serif TC', serif;
background-image: url('https://i.ibb.co/XZG0T6jR/6.png');
background-size: cover;
background-attachment: fixed;
background-position: center;
margin: 0;
padding: 0;
min-height: 100vh;
display: flex;
flex-direction: column;
color: #f0f0f0;
}
.header {
text-align: center;
padding: 20px;
background: rgba(51, 51, 51, 0.95);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
position: sticky;
top: 0;
z-index: 1000;
}
.header h1 {
font-size: 48px;
color: #2471a3;
margin: 0 0 8px;
font-weight: 700;
letter-spacing: 2px;
animation: float 2s ease-in-out infinite;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}
.header a {
color: #87CEEB;
font-size: 14px;
text-decoration: none;
}
.header a:hover { text-decoration: underline; }
@keyframes float {
0% { transform: translateY(0); }
50% { transform: translateY(-8px); }
100% { transform: translateY(0); }
}
.main-content {
flex: 1;
max-width: 1200px;
margin: 0 auto;
padding: 40px 20px;
display: flex;
flex-direction: column;
gap: 30px;
}
.form-container {
background: rgba(51, 51, 51, 0.9);
border-radius: 20px;
padding: 30px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
color: #f0f0f0;
}
label {
font-size: 18px;
margin-bottom: 10px;
display: block;
color: #f0f0f0;
}
select, input {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: 1px solid #555;
border-radius: 5px;
font-size: 16px;
background: #444;
color: #f0f0f0;
box-sizing: border-box;
}
input[type="datetime-local"] {
color-scheme: dark;
}
.hint {
font-size: 13px;
color: #aaa;
margin-top: -15px;
margin-bottom: 15px;
}
button {
padding: 15px 30px;
background: #4682B4;
color: white;
border: none;
border-radius: 10px;
font-size: 18px;
cursor: pointer;
transition: background 0.3s ease, transform 0.2s ease;
}
button:hover {
background: #3670a1;
transform: scale(1.05);
}
#submit-btn, #confirm-btn {
background: #4CAF50;
}
#submit-btn:hover, #confirm-btn:hover {
background: #45a049;
}
#cancel-btn {
background: #FF4444;
}
#cancel-btn:hover {
background: #ff1a1a;
}
.homework-list {
margin-top: 20px;
color: #f0f0f0;
}
.homework-item {
padding: 10px;
border-bottom: 1px solid #555;
}
.modal {
display: none;
position: fixed;
z-index: 1001;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
.modal-content {
background-color: #333;
margin: 15% auto;
padding: 20px;
border-radius: 10px;
width: 50%;
text-align: center;
color: #f0f0f0;
}
.modal-buttons {
margin-top: 20px;
}
.modal-buttons button {
margin: 0 10px;
}
</style>
</head>
<body>
<div class="header">
<h1>布置課業</h1>
<a href="<?= baseUrl ?>">← 返回控制面板</a>
</div>
<div class="main-content">
<div class="form-container">
<label for="class-select">選擇班別:</label>
<select id="class-select"></select>
<label for="category-select">選擇課業類別:</label>
<select id="category-select">
<!-- 動態載入 -->
</select>
<label for="homework-name">課業名稱:</label>
<input type="text" id="homework-name" placeholder="例如:藏在泥土的寶物">
<label for="keyword">關鍵詞(須包含於課業名稱中):</label>
<input type="text" id="keyword" placeholder="例如:寶物">
<p class="hint">📂 學生上傳檔案時,請以「<b>班別_姓名_關鍵詞</b>」命名,例如:<b>1C_陳大文_寶物.pdf</b>。</p>
<label for="deadline">截止日期和時間(香港時間):</label>
<input type="datetime-local" id="deadline">
<p class="hint">⏰ 請按香港時間填寫截止日期及時間。</p>
<button id="submit-btn">提交</button>
<div class="homework-list" id="homework-list"></div>
</div>
</div>
<!-- 確認視窗 -->
<div id="confirm-modal" class="modal">
<div class="modal-content">
<h2>確認課業資料</h2>
<p id="confirm-class"></p>
<p id="confirm-category"></p>
<p id="confirm-homework-name"></p>
<p id="confirm-keyword"></p>
<p id="confirm-deadline"></p>
<div class="modal-buttons">
<button id="confirm-btn">確定</button>
<button id="cancel-btn">取消</button>
</div>
</div>
</div>
<script>
// 將 datetime-local 值(YYYY-MM-DDTHH:MM)轉換為儲存格式(YYYY-MM-DD HH:MM)
function formatDeadline(dtLocal) {
return dtLocal.replace('T', ' ');
}
// 載入班別選項並初始化頁面
function loadClassesAndData() {
google.script.run
.withSuccessHandler(function(data) {
const classSelect = document.getElementById('class-select');
classSelect.innerHTML = '';
data.classes.forEach(function(cls) {
const option = document.createElement('option');
option.value = cls;
option.textContent = cls;
classSelect.appendChild(option);
});
// 動態填入課業類別
const categorySelect = document.getElementById('category-select');
categorySelect.innerHTML = '';
(data.categories || []).forEach(function(cat) {
const option = document.createElement('option');
option.value = cat;
option.textContent = cat;
categorySelect.appendChild(option);
});
if (data.classes.length > 0) {
loadHomeworkList(data.homeworks, data.classes[0]);
}
})
.withFailureHandler(function(err) {
alert('載入失敗:' + err.message);
})
.getSpreadsheetData();
}
// 根據選中的班別顯示課業資料
function loadHomeworkList(homeworks, className) {
const homeworkList = document.getElementById('homework-list');
homeworkList.innerHTML = '<h3>現有課業</h3>';
const classData = (homeworks && homeworks[className]) || { names: [], deadlines: [] };
classData.names.forEach(function(name, index) {
const deadline = classData.deadlines[index] || '未設定';
const div = document.createElement('div');
div.className = 'homework-item';
div.textContent = name + ' - 截止日期:' + deadline;
homeworkList.appendChild(div);
});
}
document.getElementById('class-select').addEventListener('change', function() {
const selectedClass = this.value;
google.script.run
.withSuccessHandler(function(data) { loadHomeworkList(data.homeworks, selectedClass); })
.withFailureHandler(function(err) { alert('載入失敗:' + err.message); })
.getSpreadsheetData();
});
// 提交按鈕:驗證並顯示確認視窗
document.getElementById('submit-btn').addEventListener('click', function() {
const className = document.getElementById('class-select').value;
const category = document.getElementById('category-select').value;
const homeworkName = document.getElementById('homework-name').value.trim();
const keyword = document.getElementById('keyword').value.trim();
const deadlineRaw = document.getElementById('deadline').value;
if (!className || !category || !homeworkName || !keyword || !deadlineRaw) {
alert('請填寫所有欄位');
return;
}
if (!homeworkName.includes(keyword)) {
alert('關鍵詞必須是課業名稱的一部分');
return;
}
const deadline = formatDeadline(deadlineRaw);
document.getElementById('confirm-class').textContent = '班別:' + className;
document.getElementById('confirm-category').textContent = '課業類別:' + category;
document.getElementById('confirm-homework-name').textContent = '課業名稱:' + homeworkName;
document.getElementById('confirm-keyword').textContent = '關鍵詞:' + keyword;
document.getElementById('confirm-deadline').textContent = '截止日期(香港時間):' + deadline;
document.getElementById('confirm-modal').style.display = 'block';
});
// 確認按鈕:提交至試算表
document.getElementById('confirm-btn').addEventListener('click', function() {
const className = document.getElementById('class-select').value;
const category = document.getElementById('category-select').value;
const homeworkName = document.getElementById('homework-name').value.trim();
const keyword = document.getElementById('keyword').value.trim();
const deadline = formatDeadline(document.getElementById('deadline').value);
// 格式化課業名稱:「寫作(長文)」藏在泥土的【寶物】
const finalHomeworkName = '「' + category + '」' + homeworkName.replace(keyword, '【' + keyword + '】');
const savedClass = className;
const savedDeadline = deadline;
google.script.run
.withSuccessHandler(function() {
alert('課業已成功添加');
// 直接在本地追加新課業,無需再次呼叫伺服器
const homeworkList = document.getElementById('homework-list');
const div = document.createElement('div');
div.className = 'homework-item';
div.textContent = finalHomeworkName + ' - 截止日期:' + savedDeadline;
homeworkList.appendChild(div);
document.getElementById('homework-name').value = '';
document.getElementById('keyword').value = '';
document.getElementById('deadline').value = '';
document.getElementById('confirm-modal').style.display = 'none';
})
.withFailureHandler(function(err) {
alert('提交失敗:' + err.message);
document.getElementById('confirm-modal').style.display = 'none';
})
.updateSpreadsheet(savedClass, finalHomeworkName, savedDeadline);
});
// 取消按鈕
document.getElementById('cancel-btn').addEventListener('click', function() {
document.getElementById('confirm-modal').style.display = 'none';
});
// 頁面載入時初始化
document.addEventListener('DOMContentLoaded', loadClassesAndData);
</script>
</body>
</html>