-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
469 lines (410 loc) · 24 KB
/
index.html
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
<!DOCTYPE html>
<html lang="th">
<head>
<script src="./library/utils.js"></script>
<!-- CSS files -->
<link rel="stylesheet" href="https://phurich.github.io/phuthon/library/style.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/1.1.2/css/bootstrap-multiselect.css">
<!-- JavaScript files -->
<script src="https://code.jquery.com/jquery-3.6.0.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.quicksearch/2.3.1/jquery.quicksearch.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/js/bootstrap-multiselect.min.js"></script>
<style>
.label-textarea {
display: flex;
flex-wrap: wrap;
/* Allows wrapping of elements */
align-items: center;
}
.first-column {
display: flex;
/* Align label and input in one row */
flex-direction: column;
/* Stack label and input vertically */
gap: 0.5em;
/* Space between label and input */
}
.second-column textarea {
height: 5em;
/* Adjust height of textarea */
}
.label-textarea label,
.label-textarea input {
flex: 0 0 auto;
/* Keep label and input in the same column */
}
.label-textarea textarea {
flex: 1 1 100%;
/* Make the textarea take up the second column or full width */
}
/* Responsive design for small screens */
@media (max-width: 600px) {
.label-textarea {
flex-direction: column;
/* Stack elements vertically */
align-items: flex-start;
/* Align elements to the left */
}
}
.checkbox {
margin-top: 0px;
margin-bottom: 0px;
}
</style>
<html-header></html-header>
</head>
<body>
<img src="./library/logo600px.png" alt="ภูธรเดลิเวอรี่">
<div id="dialog-overlay" class="dialog-overlay"></div>
<div id="dialog-sky" class="setting-sky sky">
<div class="satellite"></div>
</div>
<form id="assignRider" name="assignRider" style="margin: 20px;" method="post" accept-charset="UTF-8">
<div class="form-group row">
<label>🛵ไรเดอร์💨</label>
<div class="form-check-inline">
<div>
<input name="rider" id="rider_0" type="radio" value="Mo|Ufe2ad2a0e3a3c6d42c5de0716034dacd">
<label id="lblRider_0" for="rider_0">โม</label>
</div>
<div>
<input name="rider" id="rider_1" type="radio" value="Fluke|Ub357c51443beaf4a9164b8131437aba1">
<label for="rider_1">ฟลุ๊ค</label>
</div>
<div>
<input name="rider" id="rider_2" type="radio" value="Piya|U966035e63ab3e7d6707ec3d226e0995d">
<label for="rider_2">ปิยะ</label>
</div>
<div>
<input name="rider" id="rider_3" type="radio" value="Champ|U6fd0d6c2e9a26995749ce8d93c888ab1">
<label for="rider_3">แชมป์</label>
</div>
<div>
<input name="rider" id="rider_4" type="radio" value="Phurich|U50cf3d26ba28cb6a75ca8a40fba2b2e0">
<label for="rider_4">ภู</label>
</div>
</div>
</div>
<div class="form-group row">
<label>⏱ ตั้งเวลาส่งงานให้ไรเดอร์</label>
<select title="setTimeDelay" name="timeDelay" id="timeDelay">
<option value="10s">ทันที</option>
<option value="5m">5 นาที</option>
<option value="10m">10 นาที</option>
<option value="15m">15 นาที</option>
<option value="20m">20 นาที</option>
<option value="30m">30 นาที</option>
<option value="40m">40 นาที</option>
<option value="50m">50 นาที</option>
<option value="60m">60 นาที</option>
</select>
</div>
<div class="form-group row">
<label for="restaurantList">🔊 แจ้งเตือนร้านทันที</label>
<div class="form-check-inline">
<select id="restaurantList" name="restaurantList" multiple="multiple">
<option value="KuaiChapRo">ก๋วยจั๊บรสเด็ด</option>
<option value="KuaiChapUb">ก๋วยจั๊บอุบล</option>
<option value="KTKaiMaRaB">ก๋วยเตี๋ยวไก่มะระ@บางจาก</option>
<option value="KTChaoKao">ก๋วยเตี๋ยวเจ้าเก่า</option>
<option value="KTTomYam">ก๋วยเตี๋ยวต้มยำ</option>
<option value="KTMiaLuang">ก๋วยเตี๋ยวเมียหลวง</option>
<option value="KanBan">การบ้าน</option>
<option value="KhaoTomKho">ข้าวต้มโคคึก</option>
<option value="KMKKhunPhu">ข้าวมันไก่คุณพุก</option>
<option value="KCSuKi">เคซีสุกี้</option>
<option value="ChaOiLapPe">จ่าอ๋อยลาบเป็ด</option>
<option value="CheTaenNue">เจ๊แตนเนื้อสด</option>
<option value="ChehMuaiTa">เจ๊หมวยตามสั่ง</option>
<option value="NaNaKhopFi">นานา</option>
<option value="PhengPhiPo">เพ็งพี่ป้อม</option>
<option value="MaeLiKhrok">แม่ลีครกสะดุ้ง</option>
<option value="RotKhenBaM">รถเข็นบะหมี่@ไปรษณีย์</option>
<option value="RaChaBaMiK">ราชาบะหมี่กวางตุ้ง</option>
<option value="LaMun">ละมุน</option>
<option value="LapMaeChai">ลาบแม่ใจ</option>
<option value="SaWetKaMon">เศวตกมล</option>
<option value="STChoiBanD">ส้มตำจอย</option>
<option value="STThaiWitT">ส้มตำไทยวิทยุ</option>
<option value="STPaBird">ส้มตำป๋าเบริ์ด</option>
<option value="STYaiCha">ส้มตำยายจ๋า</option>
<option value="SuMaLiNuea">สุมาลีเนื้อย่าง</option>
<option value="SaiWaKaiMa">ไสวก๋วยเตี๋ยวไก่มะระ</option>
<option value="MaLaTitRom">หม่าล่าติดรมย์</option>
<option value="AmzBanNgon">อเมซอน ปตท.บ้านง่อน</option>
<option value="AmzSchool">อเมซอน ปตท.สด.</option>
<option value="AmzSaNam">อเมซอน ปตท.สนามชัย</option>
<option value="EmPhai">เอ็มไพร์ราดหน้ายอดผัก</option>
</select>
<button id="add-to-textbox" title="เพิ่ม/ลบ ร้าน" type="button" class="button button-lg button-warning button-space">เพิ่ม/ลบ</button>
</div>
</div>
<div class="form-group row">
<label>🔔 แจ้งเตือนโดย</label>
<div class="form-check-inline">
<div>
<input name="notify" id="notify_0" type="radio" value="0">
<label id="lblNotify_0" for="notify_0">💻ระบบ</label>
</div>
<div>
<input name="notify" id="notify_1" type="radio" value="1">
<label for="notify_1">🛵ไรเดอร์</label>
</div>
</div>
</div>
<div class="form-group row">
<div id="textareas">
</div>
</div>
<div class="form-group row">
<div><label for="detailArea">📝 รายละเอียดงานอื่น ๆ</label></div>
<div>
<ul>
<li><span onclick="insertAtCursor('detailArea',' (🎉สั่งร้านแล้ว)');">(🎉สั่งร้านแล้ว)</span></li>
<li><span onclick="insertAtCursor('detailArea',' (☎️ลูกค้าสั่งทางโทรศัพท์ / 🚫ไม่มีไลน์)');">☎️ลูกค้าสั่งทางโทรศัพท์</span></li>
<li><span onclick="insertAtCursor('detailArea',' (🎉สั่งร้านแล้ว / 💵จ่ายร้านแล้ว)');">(💵สั่งร้านแล้ว/จ่ายร้านแล้ว)</span></li>
<li><span onclick="insertAtCursor('detailArea',' 🏪ร้านไหนก็ได้');">🏪ร้านไหนก็ได้</span></li>
<li><span onclick="insertAtCursor('detailArea',' 🛵ส่งเลย ผู้สั่งจะโอนทีหลัง');">🛵ส่งเลย ผู้สั่งจะโอนทีหลัง</span></li>
</ul>
</div>
<textarea style="width: 100%" id="detailArea" name="detailArea" rows="7" maxlength="900" placeholder="รายละเอียดของงาน"></textarea>
</div>
<div class="form-group row">
<div><label for="address">🏬 สถานที่จัดส่ง</label></div>
<div>
<ul>
<li><span onclick="insertAtCursor('address','☎️ สอบถามเบอร์โทรผู้รับปลายทางกับทางร้านเลย');">☎️ สอบถามเบอร์โทร</span></li>
<li><span onclick="insertAtCursor('address','🌐 สอบถามสถานที่จัดส่งและเบอร์โทรศัพท์กับทางร้านเลย');">🌐 สอบถามสถานที่จัดส่ง</span></li>
</ul>
</div>
<textarea style="width: 100%" id="address" name="address" rows="4" maxlength="900" placeholder="ระบุข้อมูลการจัดส่ง เบอร์โทร และพิกัดในรูปแบบ Google Pluscode URL"></textarea>
</div>
<div class="row justify-content-center">
<div class="file-input-container">
<label for="fileInput" id="fileLabel" class="button button-info button-lg">📎 แนบรูปให้ไรเดอร์ (jpg)</label>
<input type="file" id="fileInput" name="photo" accept="image/jpeg" multiple>
</div>
</div>
<div class="row justify-content-center">
<canvas id="canvas" style="display:none;"></canvas>
<img id="photo" alt="Captured Photo" style="display:none;">
</div>
<input type="hidden" id="imageName" name="imageName" value="">
<input type="hidden" id="imageBase64" name="imageBase64" value="">
<div class="row justify-content-center">
<button name="formSubmit" type="submit" class="button button-lg button-primary">🛵 ส่งงาน</button>
<button name="reset" type="reset" class="button button-lg button-danger button-space">🧹 รีเซ็ท</button>
<button name="toggle" type="button" class="button button-lg button-warning button-space" onclick="document.getElementsByName('formSubmit')[0].disabled = false;">🔁</button>
</div>
</form>
<script>
document.onreadystatechange = () => {
if (document.readyState === "complete") {
let select = document.getElementById("restaurantList");
//$(select).multiselect('refresh');
let options = Array.from(select.options);
options.sort(function (a, b) {
return a.text.trim().localeCompare(b.text.trim());
});
select.innerHTML = "";
for (let option of options) {
option.innerHTML = " " + option.innerHTML; //add space before text option
select.appendChild(option);
}
$(select).multiselect('rebuild');
$('[data-toggle="tooltip"]').tooltip();
document.getElementById('assignRider').action = currentActionUrl;
//document.getElementById('assignRider').action = testActionUrl;
}
};
$('#restaurantList').multiselect({
enableFiltering: true,
enableCaseInsensitiveFiltering: true,
filterPlaceholder: 'ชื่อร้าน',
nonSelectedText: 'เลือกร้าน',
includeSelectAllOption: false
});
$('#add-to-textbox').click(function () {
let selectedOptions = $('#restaurantList option:selected');
let index = 0;
let orderNumber = "ออเดอร์#" + createOrderNumber();
$('#textareas').empty(); // Clear the existing textareas
selectedOptions.each(function () {
let label = $(this).text().trim();
let nameID = 'restaurantArea' + index;
// Create elements
let labelElement = $('<label for="' + nameID + '">' + label + '</label>');
let textarea = $('<textarea id="' + nameID + '" name="' + nameID + '" rows="5" cols="20" maxlength="900"></textarea>');
let fileInput = $('<input type="file" id="image' + index + '" name="image' + index + '" multiple>'); // Create file input element
let div = $('<div class="label-textarea"></div>');
// Append label and file input to the first column, textarea to the second
let firstColumn = $('<div class="first-column"></div>');
firstColumn.append(labelElement);
firstColumn.append(fileInput);
let secondColumn = $('<div class="second-column"></div>');
secondColumn.append(textarea);
div.append(firstColumn);
div.append(secondColumn);
// Append the div to the textareas container
$('#textareas').append(div);
// Pre-fill the textarea with the label and order number
document.getElementById(nameID).value = label + '\r\n' + orderNumber + '\r\n';
index++;
});
});
$('form').on('reset', function () {
setTimeout(function () {
$('select').multiselect('refresh');
$('#textareas').empty(); // Clear the dynamically added textareas
document.getElementsByName('formSubmit')[0].disabled = false;
document.getElementById('photo').src = "";
document.getElementById("imageName").value = "";
document.getElementById('imageBase64').value = "";
document.getElementById('photo').style.display = 'none';
}, 500);
});
window.addEventListener('pageshow', function (event) {
if (event.persisted) {
document.getElementById('dialog-sky').style.display = 'none';
document.getElementById('dialog-overlay').style.display = 'none';
}
});
function insertAtCursor(id, myValue) {
myField = document.getElementById(id);
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
//MOZILLA and others
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
myField.selectionStart = startPos + myValue.length;
myField.selectionEnd = startPos + myValue.length;
} else {
myField.value += myValue;
}
}
function createOrderNumber() {
let date = new Date();
let hours = date.getHours();
let minutes = date.getMinutes();
let seconds = date.getSeconds();
// Calculate the number of seconds since midnight
let totalSeconds = (hours * 3600) + (minutes * 60) + seconds;
// Convert to a string and pad with leading zeros if necessary
let orderNumber = totalSeconds.toString().padStart(5, '0');
return orderNumber;
}
function getChosenRiderName() {
const selectedRadio = document.querySelector('input[name="rider"]:checked');
if (selectedRadio) {
const value = selectedRadio.value;
const name = value.split("|")[0];
return name;
} else {
return ""; // Or an empty string, depending on your preference
}
}
function validateForm() {
// Flag to track if validation has failed
let validationFailed = false;
// Variable to store total character count across all textareas
let totalCharCount = 0;
// Get all static and dynamically generated textareas
let allTextareas = document.querySelectorAll('textarea');
// Loop through each textarea and add its character length to totalCharCount
allTextareas.forEach(function (textarea) {
totalCharCount += textarea.value.length;
});
// Validate Rider selection
if (!$('input[name="rider"]:checked').length) {
$('#lblRider_0')[0].scrollIntoView({ behavior: "smooth", block: "center" });
swalShowError('ระบุไรเดอร์');
return false;
}
// Check and validate #detailArea based on conditions
const restaurantCount = $('#restaurantList option:selected').length;
const textAreaCount = $('#textareas')[0].childElementCount;
let isDetailAreaRequired = true;
if ((restaurantCount > 0 || textAreaCount > 0) && (restaurantCount === textAreaCount)) {
isDetailAreaRequired = false;
}
if (isDetailAreaRequired && $('#detailArea').val().trim() === "") {
$('#detailArea')[0].scrollIntoView({ behavior: "smooth", block: "center" });
swalShowError('ระบุรายละเอียดงาน');
return false;
}
// Validate Address Area
if ($('#address').val().trim() === "") {
$('#address')[0].scrollIntoView({ behavior: "smooth", block: "center" });
swalShowError('ระบุสถานที่จัดส่ง');
return false;
}
// Check if total characters exceed 900
if (totalCharCount > 900) {
swalShowError('ข้อความทั้งหมดต้องไม่เกิน 900 ตัวอักษร ' + '(' + totalCharCount + ')');
return false; // Prevent form submission
}
if ($('#restaurantList option:selected').length !== $('#textareas')[0].childElementCount) {
$('#add-to-textbox')[0].scrollIntoView({ behavior: "smooth", block: "center" });
swalShowError('ลบร้านหรือกดเพิ่มร้าน');
return false;
}
if (($('#restaurantList option:selected').length > 0) || ($('#textareas')[0].childElementCount > 0)) {
if ($('input[name="notify"]:checked').val() === undefined) {
$('#lblNotify_0')[0].scrollIntoView({ behavior: "smooth", block: "center" });
swalShowError('ระบุวิธีการแจ้งเตือน');
return false;
}
}
if ($('input[name="notify"]:checked').val() !== undefined) {
if (($('#restaurantList option:selected').length === 0) || ($('#textareas')[0].childElementCount === 0)) {
$('#add-to-textbox')[0].scrollIntoView({ behavior: "smooth", block: "center" });
swalShowError('ระบุร้านที่ต้องการแจ้งเตือน');
return false;
}
}
$('#textareas textarea[id^="restaurantArea"]').each(function () {
let value = $(this).val();
let regex = /(?<=\d{5}\s)[\s\S]*/gm;
let match = value.match(regex);
// Find the associated label text
let label = $('label[for="' + $(this).attr('id') + '"]').text();
if (!match || match[0].trim().length === 0) {
$(this)[0].scrollIntoView({ behavior: "smooth", block: "center" });
swalShowError('ระบุรายการสินค้าร้าน' + label);
validationFailed = true;
}
// If matched and not empty, do nothing
});
// If validation failed, prevent form submission
if (validationFailed) {
return false; // Stop form submission
}
return true; // Allow form submission if validation passes
}
document.getElementById('fileInput').addEventListener('change', mergeImagesVertically);
document.getElementById('assignRider').addEventListener('submit', handleFormSubmit);
async function handleFormSubmit(event) {
event.preventDefault(); // Always prevent the default form submission
document.getElementsByName('formSubmit')[0].disabled = true;
if (!validateForm()) {
document.getElementsByName('formSubmit')[0].disabled = false;
return false;
}
document.getElementById('dialog-sky').style.display = 'block';
document.getElementById('dialog-overlay').style.display = 'block';
document.getElementById("imageName").value = "Admin-" + getChosenRiderName() + createOrderNumber();
document.getElementById('assignRider').submit();
}
</script>
</body>
</html>