ichieh commited on
Commit
1f3ce0c
·
1 Parent(s): 9d5d9ea

Update layout: Move registration form to right side and fix table selection

Browse files
Files changed (1) hide show
  1. templates/index.html +92 -108
templates/index.html CHANGED
@@ -7,9 +7,35 @@
7
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
8
  <link href="https://cdn.jsdelivr.net/npm/sweetalert2@11.3.0/dist/sweetalert2.min.css" rel="stylesheet">
9
  <style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  .table-circle {
11
- width: 200px;
12
- height: 200px;
13
  border-radius: 50%;
14
  border: 2px solid #ddd;
15
  display: flex;
@@ -19,7 +45,7 @@
19
  cursor: pointer;
20
  transition: all 0.3s ease;
21
  background-color: white;
22
- margin: 20px;
23
  position: relative;
24
  }
25
 
@@ -74,61 +100,32 @@
74
  <div class="container">
75
  <h1 class="text-center my-4">活動座位選擇</h1>
76
 
77
- <div class="row">
78
- <div class="col-md-12">
79
- <div id="tables">
80
- <!-- 桌子將由 JavaScript 動態生成 -->
81
- </div>
82
  </div>
83
- </div>
84
-
85
- <div class="row justify-content-center mt-4">
86
- <div class="col-md-4">
87
- <div class="card">
88
- <div class="card-body">
89
- <h5 class="card-title">登記資料</h5>
90
- <button type="button" class="btn btn-primary w-100" onclick="showRegistrationForm()" disabled id="registerBtn">
91
- 確認選位
92
- </button>
93
- </div>
94
  </div>
95
- </div>
96
- </div>
97
- </div>
98
-
99
- <!-- 報名表單 Modal -->
100
- <div class="modal fade" id="registrationForm" tabindex="-1">
101
- <div class="modal-dialog">
102
- <div class="modal-content">
103
- <div class="modal-header">
104
- <h5 class="modal-title">報名表單</h5>
105
- <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
106
  </div>
107
- <div class="modal-body">
108
- <form id="seatRegistration">
109
- <div class="mb-3">
110
- <label for="nickname" class="form-label">暱稱 <span class="text-danger">*</span></label>
111
- <input type="text" class="form-control" id="nickname" required>
112
- </div>
113
- <div class="mb-3">
114
- <label for="email" class="form-label">Email <span class="text-danger">*</span></label>
115
- <input type="email" class="form-control" id="email" required>
116
- </div>
117
- <div class="mb-3">
118
- <label for="fb_link" class="form-label">FB連結</label>
119
- <input type="url" class="form-control" id="fb_link">
120
- </div>
121
- <div class="mb-3">
122
- <label for="introduction" class="form-label">自我介紹 <small class="text-muted">(最多500字元)</small></label>
123
- <textarea class="form-control" id="introduction" maxlength="500" rows="4"></textarea>
124
- <div class="form-text text-end"><span id="charCount">0</span>/500</div>
125
- </div>
126
- </form>
127
  </div>
128
- <div class="modal-footer">
129
- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
130
- <button type="button" class="btn btn-primary" onclick="submitRegistration()">確認報名</button>
131
  </div>
 
 
 
132
  </div>
133
  </div>
134
  </div>
@@ -137,16 +134,9 @@
137
  <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.3.0/dist/sweetalert2.all.min.js"></script>
138
  <script>
139
  let selectedTableId = null;
140
- const registrationModal = new bootstrap.Modal(document.getElementById('registrationForm'));
141
-
142
- function showRegistrationForm() {
143
- if (selectedTableId) {
144
- registrationModal.show();
145
- }
146
- }
147
 
148
- function selectTable(tableId, isFull) {
149
- if (isFull) return;
150
 
151
  // 移除之前選擇的桌子的選中狀態
152
  const previousSelected = document.querySelector('.table-circle.selected');
@@ -154,12 +144,14 @@
154
  previousSelected.classList.remove('selected');
155
  }
156
 
157
- // 選中當前桌子
158
- const currentTable = document.querySelector(`[data-table-id="${tableId}"]`);
159
- if (currentTable) {
160
- currentTable.classList.add('selected');
 
 
 
161
  selectedTableId = tableId;
162
- document.getElementById('registerBtn').disabled = false;
163
  }
164
  }
165
 
@@ -182,6 +174,7 @@
182
  // 創建桌次元素
183
  const circle = document.createElement('div');
184
  circle.className = `table-circle${isFull ? ' full' : ''}`;
 
185
  circle.onclick = isFull ? null : () => selectTable(table.id);
186
 
187
  // 桌次名稱
@@ -223,31 +216,27 @@
223
  }
224
  }
225
 
226
- document.getElementById('introduction').addEventListener('input', function() {
227
- const maxLength = 500;
228
- const currentLength = this.value.length;
229
- document.getElementById('charCount').textContent = currentLength;
230
-
231
- if (currentLength > maxLength) {
232
- this.value = this.value.substring(0, maxLength);
233
- }
234
  });
235
 
236
  async function submitRegistration() {
 
 
 
 
 
237
  const nickname = document.getElementById('nickname').value;
238
  const email = document.getElementById('email').value;
239
  const fb_link = document.getElementById('fb_link').value;
240
  const introduction = document.getElementById('introduction').value;
241
 
242
  if (!nickname || !email) {
243
- Swal.fire({
244
- icon: 'error',
245
- title: '請填寫必填欄位',
246
- text: '暱稱和Email為必填欄位'
247
- });
248
  return;
249
  }
250
-
251
  try {
252
  const response = await fetch('/api/register', {
253
  method: 'POST',
@@ -255,42 +244,37 @@
255
  'Content-Type': 'application/json',
256
  },
257
  body: JSON.stringify({
258
- table_id: selectedTableId,
259
  nickname,
260
  email,
261
- fb_link: fb_link || '',
262
- introduction: introduction || ''
 
263
  })
264
  });
265
-
266
- const data = await response.json();
267
 
268
- if (!response.ok) {
269
- throw new Error(data.error || '報名失敗');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
  }
271
-
272
- await Swal.fire({
273
- icon: 'success',
274
- title: '報名成功!',
275
- text: '您已成功報名座位'
276
- });
277
-
278
- registrationModal.hide();
279
- document.getElementById('seatRegistration').reset();
280
- document.getElementById('registerBtn').disabled = true;
281
- selectedTableId = null;
282
- await loadTables();
283
  } catch (error) {
284
- Swal.fire({
285
- icon: 'error',
286
- title: '報名失敗',
287
- text: error.message
288
- });
289
  }
290
  }
291
-
292
- // 初始載入桌位資訊
293
- loadTables();
294
  </script>
295
  </body>
296
  </html>
 
7
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
8
  <link href="https://cdn.jsdelivr.net/npm/sweetalert2@11.3.0/dist/sweetalert2.min.css" rel="stylesheet">
9
  <style>
10
+ .main-container {
11
+ display: flex;
12
+ justify-content: space-between;
13
+ padding: 20px;
14
+ gap: 20px;
15
+ }
16
+
17
+ .tables-section {
18
+ flex: 2;
19
+ display: flex;
20
+ flex-wrap: wrap;
21
+ gap: 20px;
22
+ }
23
+
24
+ .registration-section {
25
+ flex: 1;
26
+ min-width: 300px;
27
+ max-width: 400px;
28
+ padding: 20px;
29
+ background-color: #f8f9fa;
30
+ border-radius: 8px;
31
+ position: sticky;
32
+ top: 20px;
33
+ height: fit-content;
34
+ }
35
+
36
  .table-circle {
37
+ width: 180px;
38
+ height: 180px;
39
  border-radius: 50%;
40
  border: 2px solid #ddd;
41
  display: flex;
 
45
  cursor: pointer;
46
  transition: all 0.3s ease;
47
  background-color: white;
48
+ margin: 15px;
49
  position: relative;
50
  }
51
 
 
100
  <div class="container">
101
  <h1 class="text-center my-4">活動座位選擇</h1>
102
 
103
+ <div class="main-container">
104
+ <div class="tables-section" id="tables">
105
+ <!-- 桌子將由 JavaScript 動態生成 -->
 
 
106
  </div>
107
+
108
+ <div class="registration-section">
109
+ <h4 class="mb-3">登記資料</h4>
110
+ <div class="mb-3">
111
+ <label for="nickname" class="form-label">暱稱</label>
112
+ <input type="text" class="form-control" id="nickname" required>
 
 
 
 
 
113
  </div>
114
+ <div class="mb-3">
115
+ <label for="email" class="form-label">Email</label>
116
+ <input type="email" class="form-control" id="email" required>
 
 
 
 
 
 
 
 
117
  </div>
118
+ <div class="mb-3">
119
+ <label for="fb_link" class="form-label">FB個人連結</label>
120
+ <input type="url" class="form-control" id="fb_link">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  </div>
122
+ <div class="mb-3">
123
+ <label for="introduction" class="form-label">自我介紹</label>
124
+ <textarea class="form-control" id="introduction" rows="3"></textarea>
125
  </div>
126
+ <button class="btn btn-primary w-100" id="confirmBtn" disabled onclick="submitRegistration()">
127
+ 確認選位
128
+ </button>
129
  </div>
130
  </div>
131
  </div>
 
134
  <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.3.0/dist/sweetalert2.all.min.js"></script>
135
  <script>
136
  let selectedTableId = null;
 
 
 
 
 
 
 
137
 
138
+ function selectTable(tableId) {
139
+ if (!tableId) return;
140
 
141
  // 移除之前選擇的桌子的選中狀態
142
  const previousSelected = document.querySelector('.table-circle.selected');
 
144
  previousSelected.classList.remove('selected');
145
  }
146
 
147
+ // 設置新選擇的桌子
148
+ const selectedTable = document.querySelector(`.table-circle[data-table-id="${tableId}"]`);
149
+ if (selectedTable) {
150
+ selectedTable.classList.add('selected');
151
+ // 啟用確認按鈕
152
+ document.getElementById('confirmBtn').disabled = false;
153
+ // 儲存選擇的桌號
154
  selectedTableId = tableId;
 
155
  }
156
  }
157
 
 
174
  // 創建桌次元素
175
  const circle = document.createElement('div');
176
  circle.className = `table-circle${isFull ? ' full' : ''}`;
177
+ circle.setAttribute('data-table-id', table.id);
178
  circle.onclick = isFull ? null : () => selectTable(table.id);
179
 
180
  // 桌次名稱
 
216
  }
217
  }
218
 
219
+ // 初始化頁面
220
+ document.addEventListener('DOMContentLoaded', () => {
221
+ loadTables();
 
 
 
 
 
222
  });
223
 
224
  async function submitRegistration() {
225
+ if (!selectedTableId) {
226
+ Swal.fire('錯誤', '請先選擇座位', 'error');
227
+ return;
228
+ }
229
+
230
  const nickname = document.getElementById('nickname').value;
231
  const email = document.getElementById('email').value;
232
  const fb_link = document.getElementById('fb_link').value;
233
  const introduction = document.getElementById('introduction').value;
234
 
235
  if (!nickname || !email) {
236
+ Swal.fire('錯誤', '請填寫必要欄位', 'error');
 
 
 
 
237
  return;
238
  }
239
+
240
  try {
241
  const response = await fetch('/api/register', {
242
  method: 'POST',
 
244
  'Content-Type': 'application/json',
245
  },
246
  body: JSON.stringify({
 
247
  nickname,
248
  email,
249
+ fb_link,
250
+ introduction,
251
+ table_id: selectedTableId
252
  })
253
  });
 
 
254
 
255
+ const result = await response.json();
256
+
257
+ if (result.success) {
258
+ await Swal.fire('成功', '報名成功!', 'success');
259
+ // 重新載入桌次資料
260
+ loadTables();
261
+ // 清除表單
262
+ document.getElementById('nickname').value = '';
263
+ document.getElementById('email').value = '';
264
+ document.getElementById('fb_link').value = '';
265
+ document.getElementById('introduction').value = '';
266
+ // 禁用確認按鈕
267
+ document.getElementById('confirmBtn').disabled = true;
268
+ // 清除選擇的桌號
269
+ selectedTableId = null;
270
+ } else {
271
+ Swal.fire('錯誤', result.message || '報名失敗', 'error');
272
  }
 
 
 
 
 
 
 
 
 
 
 
 
273
  } catch (error) {
274
+ console.error('Error:', error);
275
+ Swal.fire('錯誤', '報名失敗', 'error');
 
 
 
276
  }
277
  }
 
 
 
278
  </script>
279
  </body>
280
  </html>