ichieh commited on
Commit
e9f7742
·
1 Parent(s): cf0186c

Restore table settings functionality in admin page

Browse files
Files changed (1) hide show
  1. templates/admin.html +80 -4
templates/admin.html CHANGED
@@ -1,5 +1,5 @@
1
  <!DOCTYPE html>
2
- <html lang="zh-TW">
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -12,6 +12,32 @@
12
  <div class="container mt-4">
13
  <h2>管理員後台</h2>
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  <!-- 備份和恢復按鈕 -->
16
  <div class="row mb-4">
17
  <div class="col">
@@ -24,6 +50,7 @@
24
  </div>
25
  </div>
26
 
 
27
  <div class="row">
28
  <div class="col">
29
  <div class="table-responsive">
@@ -97,6 +124,51 @@
97
  let participants = [];
98
  let tables = [];
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  // 載入參與者資料
101
  async function loadParticipants() {
102
  try {
@@ -171,7 +243,7 @@
171
  const response = await fetch(`/api/admin/participant/${participantId}/move`, {
172
  method: 'POST',
173
  headers: {
174
- 'Content-Type': 'application/json',
175
  },
176
  body: JSON.stringify({ new_table_id: newTableId })
177
  });
@@ -217,12 +289,13 @@
217
  });
218
 
219
  if (response.ok) {
220
- Swal.fire('已刪除!', '報名者已被刪除。', 'success');
221
  loadParticipants();
222
  } else {
223
  throw new Error('刪除失敗');
224
  }
225
  } catch (error) {
 
226
  Swal.fire('錯誤', error.message, 'error');
227
  }
228
  }
@@ -290,7 +363,10 @@
290
  }
291
 
292
  // 初始載入
293
- document.addEventListener('DOMContentLoaded', loadParticipants);
 
 
 
294
  </script>
295
  </body>
296
  </html>
 
1
  <!DOCTYPE html>
2
+ <html>
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
 
12
  <div class="container mt-4">
13
  <h2>管理員後台</h2>
14
 
15
+ <!-- 桌次設定 -->
16
+ <div class="card mb-4">
17
+ <div class="card-header">
18
+ <h5 class="mb-0">桌次設定</h5>
19
+ </div>
20
+ <div class="card-body">
21
+ <form id="tableSettingsForm">
22
+ <div class="row">
23
+ <div class="col-md-6">
24
+ <div class="mb-3">
25
+ <label for="totalTables" class="form-label">總桌數</label>
26
+ <input type="number" class="form-control" id="totalTables" min="1" required>
27
+ </div>
28
+ </div>
29
+ <div class="col-md-6">
30
+ <div class="mb-3">
31
+ <label for="seatsPerTable" class="form-label">每桌人數</label>
32
+ <input type="number" class="form-control" id="seatsPerTable" min="1" required>
33
+ </div>
34
+ </div>
35
+ </div>
36
+ <button type="submit" class="btn btn-primary">更新設定</button>
37
+ </form>
38
+ </div>
39
+ </div>
40
+
41
  <!-- 備份和恢復按鈕 -->
42
  <div class="row mb-4">
43
  <div class="col">
 
50
  </div>
51
  </div>
52
 
53
+ <!-- 參與者列表 -->
54
  <div class="row">
55
  <div class="col">
56
  <div class="table-responsive">
 
124
  let participants = [];
125
  let tables = [];
126
 
127
+ // 載入目前設定
128
+ async function loadCurrentSettings() {
129
+ try {
130
+ const response = await fetch('/api/admin/settings');
131
+ const data = await response.json();
132
+ document.getElementById('totalTables').value = data.total_tables;
133
+ document.getElementById('seatsPerTable').value = data.seats_per_table;
134
+ } catch (error) {
135
+ console.error('Error:', error);
136
+ Swal.fire('錯誤', '載入設定失敗', 'error');
137
+ }
138
+ }
139
+
140
+ // 更新桌次設定
141
+ document.getElementById('tableSettingsForm').addEventListener('submit', async (e) => {
142
+ e.preventDefault();
143
+ const totalTables = document.getElementById('totalTables').value;
144
+ const seatsPerTable = document.getElementById('seatsPerTable').value;
145
+
146
+ try {
147
+ const response = await fetch('/api/admin/settings', {
148
+ method: 'POST',
149
+ headers: {
150
+ 'Content-Type': 'application/json'
151
+ },
152
+ body: JSON.stringify({
153
+ total_tables: parseInt(totalTables),
154
+ seats_per_table: parseInt(seatsPerTable)
155
+ })
156
+ });
157
+
158
+ const data = await response.json();
159
+
160
+ if (response.ok) {
161
+ Swal.fire('成功', '桌次設定已更新', 'success');
162
+ loadParticipants(); // 重新載入參與者列表以反映新的桌次設定
163
+ } else {
164
+ throw new Error(data.error);
165
+ }
166
+ } catch (error) {
167
+ console.error('Error:', error);
168
+ Swal.fire('錯誤', error.message || '更新設定失敗', 'error');
169
+ }
170
+ });
171
+
172
  // 載入參與者資料
173
  async function loadParticipants() {
174
  try {
 
243
  const response = await fetch(`/api/admin/participant/${participantId}/move`, {
244
  method: 'POST',
245
  headers: {
246
+ 'Content-Type': 'application/json'
247
  },
248
  body: JSON.stringify({ new_table_id: newTableId })
249
  });
 
289
  });
290
 
291
  if (response.ok) {
292
+ Swal.fire('已刪除!', '該報名者已被刪除。', 'success');
293
  loadParticipants();
294
  } else {
295
  throw new Error('刪除失敗');
296
  }
297
  } catch (error) {
298
+ console.error('Error:', error);
299
  Swal.fire('錯誤', error.message, 'error');
300
  }
301
  }
 
363
  }
364
 
365
  // 初始載入
366
+ document.addEventListener('DOMContentLoaded', () => {
367
+ loadCurrentSettings();
368
+ loadParticipants();
369
+ });
370
  </script>
371
  </body>
372
  </html>