-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqr.html
More file actions
1290 lines (1173 loc) · 56.2 KB
/
qr.html
File metadata and controls
1290 lines (1173 loc) · 56.2 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
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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>إنشاء رمز QR ديناميكي - MEQR</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script src="https://cdn.jsdelivr.net/npm/qrcode@1.5.1/build/qrcode.min.js"></script>
<style>
:root {
--primary: #2F6BFF;
--primary-dark: #0E374A;
--secondary: #00C853;
--background: #FFFFFF;
--card-bg: #F2F4F8;
--text: #333333;
--text-light: #777777;
--border: #E0E0E0;
--shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
--radius: 12px;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background-color: var(--background);
color: var(--text);
overflow-x: hidden;
padding: 20px;
}
.top-bar {
height: 60px;
background: linear-gradient(135deg, var(--primary), var(--primary-dark));
color: white;
padding: 0 16px;
display: flex;
align-items: center;
justify-content: space-between;
z-index: 1000;
box-shadow: var(--shadow);
border-radius: var(--radius);
margin-bottom: 20px;
}
.back-btn {
background: none;
border: none;
color: white;
font-size: 1.2rem;
cursor: pointer;
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
}
.back-btn:hover {
background-color: rgba(255, 255, 255, 0.1);
}
.page-title {
font-size: 1.3rem;
font-weight: 700;
flex: 1;
text-align: center;
}
.card {
background-color: var(--background);
border-radius: var(--radius);
box-shadow: var(--shadow);
padding: 20px;
margin-bottom: 20px;
transition: transform 0.3s ease;
}
.card:hover {
transform: translateY(-3px);
}
.card-title {
font-size: 1.2rem;
font-weight: 700;
margin-bottom: 16px;
color: var(--primary-dark);
display: flex;
align-items: center;
}
.card-title i {
margin-left: 10px;
}
.type-category {
margin-bottom: 25px;
}
.category-title {
font-size: 1.1rem;
font-weight: 700;
color: var(--primary-dark);
margin-bottom: 15px;
padding-bottom: 8px;
border-bottom: 2px solid var(--primary);
}
.qr-type-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 12px;
}
.qr-type {
background-color: var(--card-bg);
border-radius: var(--radius);
padding: 15px 8px;
text-align: center;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
flex-direction: column;
align-items: center;
}
.qr-type:hover, .qr-type.selected {
background-color: var(--primary);
color: white;
transform: scale(1.05);
}
.qr-type i {
font-size: 1.8rem;
margin-bottom: 8px;
}
.qr-type p {
font-size: 0.85rem;
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
margin-bottom: 8px;
font-weight: 600;
color: var(--primary-dark);
}
.form-control {
width: 100%;
padding: 12px 15px;
border: 1px solid var(--border);
border-radius: var(--radius);
font-size: 1rem;
transition: border-color 0.3s ease;
direction: rtl; /* Added for RTL text input */
text-align: right; /* Added for RTL text input */
}
.form-control:focus {
border-color: var(--primary);
outline: none;
box-shadow: 0 0 0 3px rgba(47, 107, 255, 0.2);
}
.checkbox-group {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.checkbox-group input {
margin-left: 10px;
}
.btn {
display: inline-block;
background-color: var(--primary);
color: white;
border: none;
border-radius: var(--radius);
padding: 14px 24px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
text-align: center;
width: 100%;
margin-top: 10px;
}
.btn:hover {
background-color: var(--primary-dark);
transform: translateY(-2px);
}
.btn-secondary {
background-color: var(--card-bg);
color: var(--text);
}
.btn-secondary:hover {
background-color: #e0e0e0;
}
.btn-small {
padding: 8px 15px;
font-size: 0.9rem;
width: auto;
}
.qr-preview-container {
text-align: center;
padding: 20px;
background-color: var(--card-bg);
border-radius: var(--radius);
margin-bottom: 20px;
}
#qr-preview {
max-width: 200px;
margin: 0 auto 20px;
display: block;
border: 1px solid var(--border); /* Added border for preview */
}
.customization-options {
display: grid;
grid-template-columns: repeat(2, 1fr); /* Changed to 2 columns for better spacing */
gap: 15px;
margin-bottom: 20px;
}
.color-option {
height: 40px;
border-radius: var(--radius);
cursor: pointer;
border: 2px solid transparent;
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
transition: all 0.2s ease;
}
.color-option.active {
border-color: var(--text);
box-shadow: 0 0 0 3px var(--primary); /* Highlight active color */
transform: scale(1.05);
}
.page {
display: none;
}
.page.active {
display: block;
animation: fadeIn 0.4s ease;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.dynamic-item {
background: #f8f9fa;
padding: 15px;
border-radius: var(--radius);
margin-bottom: 15px;
border: 1px solid #e9ecef;
}
.form-row {
display: flex;
gap: 15px;
margin-bottom: 15px;
}
.form-row .form-group {
flex: 1;
margin-bottom: 0;
}
.file-upload {
position: relative;
display: inline-block;
width: 100%;
}
.file-upload input {
position: absolute;
left: 0;
top: 0;
opacity: 0;
width: 100%;
height: 100%;
cursor: pointer;
z-index: 10; /* Ensure it's clickable */
}
.file-upload-label {
display: block;
padding: 12px 15px;
background-color: var(--card-bg);
border: 1px dashed var(--border);
border-radius: var(--radius);
text-align: center;
cursor: pointer;
transition: all 0.3s ease;
}
.file-upload-label:hover {
background-color: #e6e9ee;
border-color: var(--primary);
}
.file-upload-label i {
margin-left: 8px;
}
.file-name {
display: block;
margin-top: 5px;
font-size: 0.85rem;
color: var(--text-light);
}
.toast {
position: fixed;
bottom: 30px;
left: 50%;
transform: translateX(-50%);
background-color: var(--primary);
color: white;
padding: 12px 24px;
border-radius: var(--radius);
box-shadow: var(--shadow);
z-index: 1000;
animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards; /* Use forwards to keep final state */
opacity: 0; /* Start hidden */
}
@keyframes toastIn {
from { opacity: 0; transform: translateX(-50%) translateY(20px); }
to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes toastOut {
from { opacity: 1; transform: translateX(-50%) translateY(0); }
to { opacity: 0; transform: translateX(-50%) translateY(20px); }
}
@media (max-width: 768px) {
.qr-type-grid, .customization-options {
grid-template-columns: repeat(2, 1fr);
}
body {
padding: 10px;
}
.top-bar {
margin-bottom: 10px;
}
.card {
padding: 15px;
}
}
@media (max-width: 480px) {
.qr-type-grid, .customization-options {
grid-template-columns: 1fr;
}
.card-title {
font-size: 1.1rem;
}
.form-control {
padding: 10px;
}
.btn {
padding: 12px 20px;
font-size: 0.9rem;
}
}
</style>
</head>
<body>
<div class="top-bar">
<button class="back-btn" id="back-button">
<i class="fas fa-arrow-right"></i>
</button>
<div class="page-title" id="page-title">إنشاء رمز QR جديد</div>
<div style="width: 40px;"></div> </div>
<div id="create-page" class="page active">
<div class="card">
<h3 class="card-title"><i class="fas fa-qrcode"></i> اختر نوع المحتوى</h3>
<div class="type-category">
<div class="category-title">الروابط</div>
<div class="qr-type-grid">
<div class="qr-type" data-type="url">
<i class="fas fa-link"></i>
<p>رابط URL</p>
</div>
<div class="qr-type" data-type="appstore">
<i class="fas fa-mobile-alt"></i>
<p>متجر التطبيقات</p>
</div>
<div class="qr-type" data-type="custom-url">
<i class="fas fa-pencil-ruler"></i>
<p>رابط مخصص</p>
</div>
<div class="qr-type" data-type="list-links">
<i class="fas fa-list"></i>
<p>قائمة الروابط</p>
</div>
<div class="qr-type" data-type="payment">
<i class="fas fa-money-bill-wave"></i>
<p>دفع</p>
</div>
</div>
</div>
<div class="type-category">
<div class="category-title">التواصل</div>
<div class="qr-type-grid">
<div class="qr-type" data-type="email">
<i class="fas fa-envelope"></i>
<p>البريد الإلكتروني</p>
</div>
<div class="qr-type" data-type="sms">
<i class="fas fa-sms"></i>
<p>رسالة SMS</p>
</div>
<div class="qr-type" data-type="whatsapp">
<i class="fab fa-whatsapp"></i>
<p>واتساب</p>
</div>
<div class="qr-type" data-type="phone">
<i class="fas fa-phone-alt"></i>
<p>مكالمة هاتفية</p>
</div>
<div class="qr-type" data-type="vcard">
<i class="fas fa-address-card"></i>
<p>بطاقة اتصال</p>
</div>
</div>
</div>
<div class="type-category">
<div class="category-title">الوسائط</div>
<div class="qr-type-grid">
<div class="qr-type" data-type="pdf">
<i class="fas fa-file-pdf"></i>
<p>ملف PDF</p>
</div>
<div class="qr-type" data-type="image">
<i class="fas fa-image"></i>
<p>صورة</p>
</div>
<div class="qr-type" data-type="audio">
<i class="fas fa-music"></i>
<p>صوت</p>
</div>
<div class="qr-type" data-type="video">
<i class="fas fa-video"></i>
<p>فيديو</p>
</div>
</div>
</div>
<div class="type-category">
<div class="category-title">الشبكات</div>
<div class="qr-type-grid">
<div class="qr-type" data-type="wifi">
<i class="fas fa-wifi"></i>
<p>واي فاي</p>
</div>
<div class="qr-type" data-type="social">
<i class="fas fa-hashtag"></i>
<p>وسائل التواصل</p>
</div>
</div>
</div>
<div class="type-category">
<div class="category-title">أخرى</div>
<div class="qr-type-grid">
<div class="qr-type" data-type="text">
<i class="fas fa-font"></i>
<p>نص</p>
</div>
<div class="qr-type" data-type="map">
<i class="fas fa-map-marker-alt"></i>
<p>خريطة</p>
</div>
<div class="qr-type" data-type="booking">
<i class="fas fa-calendar-check"></i>
<p>حجز موعد</p>
</div>
<div class="qr-type" data-type="crypto">
<i class="fab fa-bitcoin"></i>
<p>عملة رقمية</p>
</div>
</div>
</div>
</div>
</div>
<div id="create-detail-page" class="page">
</div>
<script>
// App State
const appState = {
currentPage: 'create',
currentQrType: null,
qrData: {}, // Stores data for the current QR being created
savedQrs: [] // Would store saved QR data (requires backend for persistence)
};
// QR Types and their configurations
const qrTypes = {
'url': {
name: 'رابط URL',
icon: 'fas fa-link',
fields: [
{ type: 'text', name: 'url', label: 'الرابط', placeholder: 'https://example.com', required: true }
],
generateContent: (data) => data.url || ''
},
'text': {
name: 'نص',
icon: 'fas fa-font',
fields: [
{ type: 'textarea', name: 'text', label: 'النص', placeholder: 'أدخل النص هنا...', required: true }
],
generateContent: (data) => data.text || ''
},
'wifi': {
name: 'واي فاي',
icon: 'fas fa-wifi',
fields: [
{ type: 'text', name: 'ssid', label: 'اسم الشبكة (SSID)', placeholder: 'اسم شبكة الواي فاي', required: true },
{ type: 'select', name: 'encryption', label: 'نوع التشفير', options: ['WPA/WPA2', 'WEP', 'لا يوجد'], required: true, value: 'WPA/WPA2' },
{ type: 'text', name: 'password', label: 'كلمة المرور', placeholder: 'كلمة مرور الواي فاي', required: true }
],
generateContent: (data) => `WIFI:S:${data.ssid || ''};T:${data.encryption || 'WPA/WPA2'};P:${data.password || ''};;`
},
'pdf': {
name: 'ملف PDF',
icon: 'fas fa-file-pdf',
fields: [
{ type: 'file', name: 'pdf', label: 'رفع ملف PDF', accept: '.pdf', required: true, placeholder: 'لم يتم اختيار ملف' }
],
generateContent: (data) => data.fileUrl || 'Please upload PDF' // Placeholder, real impl needs backend
},
'appstore': {
name: 'متجر التطبيقات',
icon: 'fas fa-mobile-alt',
fields: [
{ type: 'text', name: 'ios', label: 'رابط App Store', placeholder: 'https://apps.apple.com/...' },
{ type: 'text', name: 'android', label: 'رابط Google Play', placeholder: 'https://play.google.com/...' }
],
generateContent: (data) => {
if (data.ios && data.android) return `https://linktree.com/app?ios=${encodeURIComponent(data.ios)}&android=${encodeURIComponent(data.android)}`;
if (data.ios) return data.ios;
if (data.android) return data.android;
return 'No app links provided';
}
},
'email': {
name: 'البريد الإلكتروني',
icon: 'fas fa-envelope',
fields: [
{ type: 'email', name: 'to', label: 'المستلم', placeholder: 'example@domain.com', required: true },
{ type: 'text', name: 'subject', label: 'الموضوع', placeholder: 'موضوع البريد الإلكتروني' },
{ type: 'textarea', name: 'body', label: 'نص الرسالة', placeholder: 'محتوى البريد الإلكتروني...' }
],
generateContent: (data) => `mailto:${data.to || ''}?subject=${encodeURIComponent(data.subject || '')}&body=${encodeURIComponent(data.body || '')}`
},
'whatsapp': {
name: 'واتساب',
icon: 'fab fa-whatsapp',
fields: [
{ type: 'tel', name: 'phone', label: 'رقم الهاتف (بما في ذلك رمز الدولة)', placeholder: '+966XXXXXXXXX', required: true },
{ type: 'text', name: 'message', label: 'الرسالة (اختياري)', placeholder: 'رسالة واتساب...' }
],
generateContent: (data) => `https://wa.me/${data.phone || ''}${data.message ? `?text=${encodeURIComponent(data.message)}` : ''}`
},
'phone': {
name: 'مكالمة هاتفية',
icon: 'fas fa-phone-alt',
fields: [
{ type: 'tel', name: 'number', label: 'رقم الهاتف', placeholder: '+966XXXXXXXXX', required: true }
],
generateContent: (data) => `tel:${data.number || ''}`
},
'sms': {
name: 'رسالة SMS',
icon: 'fas fa-sms',
fields: [
{ type: 'tel', name: 'number', label: 'رقم الهاتف', placeholder: '+966XXXXXXXXX', required: true },
{ type: 'text', name: 'message', label: 'الرسالة', placeholder: 'نص الرسالة...' }
],
generateContent: (data) => `sms:${data.number || ''}${data.message ? `?body=${encodeURIComponent(data.message)}` : ''}`
},
'vcard': {
name: 'بطاقة اتصال',
icon: 'fas fa-address-card',
fields: [
{ type: 'text', name: 'name', label: 'الاسم', placeholder: 'الاسم الكامل', required: true },
{ type: 'tel', name: 'phone', label: 'رقم الهاتف', placeholder: '+966XXXXXXXXX' },
{ type: 'email', name: 'email', label: 'البريد الإلكتروني', placeholder: 'example@domain.com' },
{ type: 'text', name: 'company', label: 'الشركة', placeholder: 'اسم الشركة' },
{ type: 'text', name: 'title', label: 'المسمى الوظيفي', placeholder: 'المسمى الوظيفي' }
],
generateContent: (data) => {
let vCard = 'BEGIN:VCARD\nVERSION:3.0\n';
if (data.name) vCard += `FN:${data.name}\n`;
if (data.phone) vCard += `TEL:${data.phone}\n`;
if (data.email) vCard += `EMAIL:${data.email}\n`;
if (data.company) vCard += `ORG:${data.company}\n`;
if (data.title) vCard += `TITLE:${data.title}\n`;
vCard += 'END:VCARD';
return vCard;
}
},
'map': {
name: 'خريطة',
icon: 'fas fa-map-marker-alt',
fields: [
{ type: 'text', name: 'address', label: 'العنوان', placeholder: 'العنوان الكامل (أو اترك فارغاً للإحداثيات)' },
{ type: 'number', name: 'latitude', label: 'خط العرض', placeholder: '00.0000', step: 'any' },
{ type: 'number', name: 'longitude', label: 'خط الطول', placeholder: '00.0000', step: 'any' }
],
generateContent: (data) => {
if (data.address) {
return `https://maps.google.com/?q=${encodeURIComponent(data.address)}`;
} else if (data.latitude && data.longitude) {
return `https://maps.google.com/?q=${data.latitude},${data.longitude}`;
}
return 'No map data provided';
}
},
'audio': {
name: 'صوت',
icon: 'fas fa-music',
fields: [
{ type: 'file', name: 'audio', label: 'رفع ملف صوتي', accept: '.mp3,.wav', required: true, placeholder: 'لم يتم اختيار ملف' }
],
generateContent: (data) => data.fileUrl || 'Please upload audio' // Placeholder, real impl needs backend
},
'video': {
name: 'فيديو',
icon: 'fas fa-video',
fields: [
{ type: 'text', name: 'url', label: 'رابط الفيديو (YouTube, Vimeo, etc.)', placeholder: 'https://youtube.com/watch?v=...', required: true }
],
generateContent: (data) => data.url || ''
},
'social': {
name: 'وسائل التواصل',
icon: 'fas fa-hashtag',
fields: [
{ type: 'text', name: 'facebook', label: 'فيسبوك', placeholder: 'https://facebook.com/...' },
{ type: 'text', name: 'twitter', label: 'تويتر (X)', placeholder: 'https://twitter.com/...' },
{ type: 'text', name: 'instagram', label: 'إنستغرام', placeholder: 'https://instagram.com/...' },
{ type: 'text', name: 'linkedin', label: 'لينكد إن', placeholder: 'https://linkedin.com/...' },
{ type: 'text', name: 'tiktok', label: 'تيك توك', placeholder: 'https://tiktok.com/...' }
],
generateContent: (data) => {
let socialLinks = [];
if (data.facebook) socialLinks.push(`Facebook: ${data.facebook}`);
if (data.twitter) socialLinks.push(`Twitter: ${data.twitter}`);
if (data.instagram) socialLinks.push(`Instagram: ${data.instagram}`);
if (data.linkedin) socialLinks.push(`LinkedIn: ${data.linkedin}`);
if (data.tiktok) socialLinks.push(`TikTok: ${data.tiktok}`);
return socialLinks.join('\n') || 'No social links provided';
}
},
'booking': {
name: 'حجز موعد',
icon: 'fas fa-calendar-check',
fields: [
{ type: 'text', name: 'title', label: 'عنوان الحجز', placeholder: 'عنوان الحجز', required: true },
{ type: 'text', name: 'description', label: 'الوصف', placeholder: 'وصف الحجز...' },
{ type: 'datetime-local', name: 'start', label: 'تاريخ ووقت البدء', required: true },
{ type: 'datetime-local', name: 'end', label: 'تاريخ ووقت الانتهاء' },
{ type: 'text', name: 'location', label: 'الموقع', placeholder: 'الموقع (اختياري)' }
],
generateContent: (data) => {
// iCalendar format (simplified)
let icsContent = 'BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//MEQR//NONSGML v1.0//EN\nBEGIN:VEVENT\n';
icsContent += `SUMMARY:${data.title || 'Event'}\n`;
if (data.description) icsContent += `DESCRIPTION:${data.description}\n`;
if (data.location) icsContent += `LOCATION:${data.location}\n`;
if (data.start) icsContent += `DTSTART:${new Date(data.start).toISOString().replace(/[-:]|\.\d{3}/g, '')}\n`;
if (data.end) icsContent += `DTEND:${new Date(data.end).toISOString().replace(/[-:]|\.\d{3}/g, '')}\n`;
icsContent += 'END:VEVENT\nEND:VCALENDAR';
return icsContent;
}
},
'crypto': {
name: 'عملة رقمية',
icon: 'fab fa-bitcoin',
fields: [
{ type: 'select', name: 'currency', label: 'العملة', options: ['Bitcoin', 'Ethereum', 'Litecoin', 'Dogecoin', 'USDT'], required: true, value: 'Bitcoin' },
{ type: 'text', name: 'address', label: 'عنوان المحفظة', placeholder: '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', required: true },
{ type: 'number', name: 'amount', label: 'المبلغ', placeholder: '0.00', step: 'any' }
],
generateContent: (data) => {
let content = '';
switch (data.currency) {
case 'Bitcoin': content = 'bitcoin:'; break;
case 'Ethereum': content = 'ethereum:'; break;
case 'Litecoin': content = 'litecoin:'; break;
case 'Dogecoin': content = 'dogecoin:'; break;
case 'USDT': content = 'erc20:'; break; // Placeholder for ERC20 USDT
}
content += data.address;
if (data.amount) content += `?amount=${data.amount}`;
return content;
}
},
'payment': {
name: 'دفع',
icon: 'fas fa-money-bill-wave',
fields: [
{ type: 'text', name: 'url', label: 'رابط الدفع (Stripe, PayPal.me, etc.)', placeholder: 'https://paypal.me/yourname', required: true },
{ type: 'number', name: 'amount', label: 'المبلغ (اختياري)', placeholder: '0.00', step: '0.01' },
{ type: 'select', name: 'currency', label: 'العملة', options: ['SAR', 'USD', 'EUR', 'AED'], value: 'SAR' }
],
generateContent: (data) => {
let url = data.url || '';
if (data.amount && data.currency) {
// This part is highly dependent on the payment gateway's URL parameters
// For PayPal.me, it's typically: https://paypal.me/yourname/amountcurrency
if (url.includes('paypal.me')) {
url = `${url.split('?')[0]}/${data.amount}${data.currency}`;
} else {
// Generic approach, might not work for all gateways
url += (url.includes('?') ? '&' : '?') + `amount=${data.amount}¤cy=${data.currency}`;
}
}
return url;
}
},
'custom-url': {
name: 'رابط مخصص',
icon: 'fas fa-pencil-ruler',
fields: [
{ type: 'text', name: 'default_url', label: 'الرابط الافتراضي', placeholder: 'https://example.com', required: true },
{ type: 'text', name: 'name', label: 'اسم الرمز (لإدارة القواعد)', placeholder: 'حملة صيف 2025', required: true },
{ type: 'dynamic', name: 'rules', label: 'قواعد إعادة التوجيه (تتطلب خادمًا)', fields: [
{ type: 'select', name: 'condition_type', label: 'نوع الشرط', options: ['الموقع الجغرافي', 'الوقت', 'اللغة', 'نوع الجهاز'], required: true, value: 'الموقع الجغرافي' },
{ type: 'text', name: 'condition_value', label: 'قيمة الشرط (مثل: SA, 09:00-17:00, ar, mobile)', placeholder: 'SA أو 09:00-17:00', required: true },
{ type: 'text', name: 'redirect_url', label: 'رابط إعادة التوجيه', placeholder: 'https://alternative.com', required: true }
]}
],
generateContent: (data) => {
// For a real dynamic QR code, this would point to a backend service
// Example: https://yourdomain.com/qr/dynamic_id
// The backend would then handle the redirection based on 'rules'
// For this frontend-only demo, we'll just show the default URL.
let rulesText = (data.rules || []).map(rule =>
`${rule.condition_type}: ${rule.condition_value} -> ${rule.redirect_url}`
).join('\n');
return `Default URL: ${data.default_url}\n(Dynamic rules for "${data.name}" require backend implementation)\n${rulesText}`;
}
},
'list-links': {
name: 'قائمة الروابط',
icon: 'fas fa-list',
fields: [
{ type: 'text', name: 'title', label: 'عنوان القائمة', placeholder: 'روابط مفيدة', required: true },
{ type: 'dynamic', name: 'links', label: 'الروابط', fields: [
{ type: 'text', name: 'link_title', label: 'عنوان الرابط', placeholder: 'الرابط الأول', required: true },
{ type: 'text', name: 'link_url', label: 'الرابط', placeholder: 'https://...', required: true }
]}
],
generateContent: (data) => {
// This would ideally point to a hosted webpage generated by your backend
// showing a list of links, e.g., https://yourdomain.com/qr/list/list_id
let linksText = (data.links || []).map(link =>
`${link.link_title || 'No Title'}: ${link.link_url || 'No URL'}`
).join('\n');
return `QR Title: ${data.title}\nLinks:\n${linksText}`;
}
}
};
// DOM Elements
const pages = {
create: document.getElementById('create-page'),
createDetail: document.getElementById('create-detail-page')
};
const backButton = document.getElementById('back-button');
const pageTitleElement = document.getElementById('page-title');
const qrTypesElements = document.querySelectorAll('.qr-type');
// Initial setup on page load
document.addEventListener('DOMContentLoaded', function() {
setupEventListeners();
navigateTo('create'); // Start on the create page
});
function setupEventListeners() {
// Select QR Type
qrTypesElements.forEach(type => {
type.addEventListener('click', () => {
// Remove 'selected' class from previous selection
qrTypesElements.forEach(el => el.classList.remove('selected'));
// Add 'selected' class to current selection
type.classList.add('selected');
appState.currentQrType = type.dataset.type;
// Reset qrData for new QR creation
appState.qrData = {};
loadCreateDetailPage(appState.currentQrType);
});
});
// Back button functionality
backButton.addEventListener('click', () => {
// Clear selected type when going back to type selection
qrTypesElements.forEach(el => el.classList.remove('selected'));
navigateTo('create');
});
}
// Page Navigation
function navigateTo(page) {
// Hide current active page
Object.values(pages).forEach(p => p.classList.remove('active'));
// Show the new page
pages[page].classList.add('active');
appState.currentPage = page;
// Update page title and back button icon
updatePageTitleAndIcon();
}
// Update Page Title and Back Button Icon
function updatePageTitleAndIcon() {
if (appState.currentPage === 'create') {
pageTitleElement.textContent = 'إنشاء رمز QR جديد';
backButton.innerHTML = '<i class="fas fa-arrow-right"></i>'; // Or 'fas fa-home' if it leads to dashboard
} else if (appState.currentPage === 'createDetail' && appState.currentQrType) {
pageTitleElement.textContent = qrTypes[appState.currentQrType].name;
backButton.innerHTML = '<i class="fas fa-arrow-right"></i>';
}
}
// Load QR Detail Page based on type
function loadCreateDetailPage(type) {
const typeData = qrTypes[type];
if (!typeData) return;
let formHTML = `
<div class="card">
<h3 class="card-title"><i class="${typeData.icon}"></i> ${typeData.name}</h3>
<form id="qr-form">
`;
// Add form fields
typeData.fields.forEach(field => {
if (['text', 'email', 'tel', 'number', 'url', 'datetime-local'].includes(field.type)) {
formHTML += `
<div class="form-group">
<label for="${field.name}">${field.label}${field.required ? ' *' : ''}</label>
<input type="${field.type}" id="${field.name}" name="${field.name}"
class="form-control" placeholder="${field.placeholder || ''}"
${field.required ? 'required' : ''} value="${appState.qrData[field.name] || field.value || ''}"
${field.step ? `step="${field.step}"` : ''}>
</div>
`;
}
else if (field.type === 'textarea') {
formHTML += `
<div class="form-group">
<label for="${field.name}">${field.label}${field.required ? ' *' : ''}</label>
<textarea id="${field.name}" name="${field.name}"
class="form-control" placeholder="${field.placeholder || ''}"
rows="4" ${field.required ? 'required' : ''}>${appState.qrData[field.name] || field.value || ''}</textarea>
</div>
`;
}
else if (field.type === 'select') {
let optionsHTML = '';
field.options.forEach(option => {
const selected = (option === (appState.qrData[field.name] || field.value)) ? 'selected' : '';
optionsHTML += `<option value="${option}" ${selected}>${option}</option>`;
});
formHTML += `
<div class="form-group">
<label for="${field.name}">${field.label}${field.required ? ' *' : ''}</label>
<select id="${field.name}" name="${field.name}" class="form-control" ${field.required ? 'required' : ''}>
${optionsHTML}
</select>
</div>
`;
}
else if (field.type === 'file') {
formHTML += `
<div class="form-group">
<label for="${field.name}">${field.label}${field.required ? ' *' : ''}</label>
<div class="file-upload">
<input type="file" id="${field.name}" name="${field.name}"
accept="${field.accept || '*'}" ${field.required ? 'required' : ''}>
<div class="file-upload-label">
<i class="fas fa-upload"></i> <span id="${field.name}-filename">${appState.qrData[`${field.name}_filename`] || field.placeholder}</span>
</div>
</div>
</div>
`;
}
else if (field.type === 'dynamic') {
// For dynamic fields, we check if there's existing data or add one default item
const dynamicItems = appState.qrData[field.name] || [{}];
formHTML += `
<div class="form-group">
<label>${field.label}</label>
<div id="${field.name}-container">
${dynamicItems.map((item, index) => generateDynamicItemHTML(field.fields, item, field.name, index)).join('')}
</div>
<button type="button" class="btn btn-small" id="add-${field.name}-item">+ إضافة عنصر</button>
</div>
`;
}
});
formHTML += `
<button type="submit" class="btn">إنشاء رمز QR</button>
</form>
</div>
`;
// Add QR Preview and Customization
formHTML += `
<div class="card">
<h3 class="card-title"><i class="fas fa-eye"></i> معاينة الرمز</h3>
<div class="qr-preview-container">
<canvas id="qr-preview" width="200" height="200"></canvas>
<div id="qr-name-display">رمز ${typeData.name}</div>
</div>
<div class="customization-options">
<div class="color-option ${appState.qrData.color === '#2F6BFF' || !appState.qrData.color ? 'active' : ''}" style="background-color: #2F6BFF;" data-color="#2F6BFF"></div>
<div class="color-option ${appState.qrData.color === '#00C853' ? 'active' : ''}" style="background-color: #00C853;" data-color="#00C853"></div>
<div class="color-option ${appState.qrData.color === '#FF6B6B' ? 'active' : ''}" style="background-color: #FF6B6B;" data-color="#FF6B6B"></div>
<div class="color-option ${appState.qrData.color === '#9B59B6' ? 'active' : ''}" style="background-color: #9B59B6;" data-color="#9B59B6"></div>
</div>
<button class="btn" id="download-btn"><i class="fas fa-download"></i> تنزيل الرمز</button>
<button class="btn btn-secondary" id="share-btn"><i class="fas fa-share-alt"></i> مشاركة</button>
</div>
`;
pages.createDetail.innerHTML = formHTML;
navigateTo('createDetail');
// Setup event listeners for the new page
setupDetailPageEvents(type);
}
// Generate HTML for a single dynamic item
function generateDynamicItemHTML(fields, itemData = {}, parentName, index) {
let html = '<div class="dynamic-item">';
fields.forEach(field => {
const itemId = `${parentName}-${field.name}-${index}`;
const fieldValue = itemData[field.name] || field.value || '';
if (['text', 'email', 'url', 'number', 'tel'].includes(field.type)) {
html += `
<div class="form-group">
<label for="${itemId}">${field.label}${field.required ? ' *' : ''}</label>
<input type="${field.type}" id="${itemId}" name="${field.name}"
class="form-control dynamic-input" placeholder="${field.placeholder || ''}"
value="${fieldValue}" ${field.required ? 'required' : ''}>
</div>
`;
} else if (field.type === 'select') {
let optionsHTML = '';
field.options.forEach(option => {
const selected = (option === fieldValue) ? 'selected' : '';
optionsHTML += `<option value="${option}" ${selected}>${option}</option>`;
});
html += `
<div class="form-group">
<label for="${itemId}">${field.label}${field.required ? ' *' : ''}</label>
<select id="${itemId}" name="${field.name}" class="form-control dynamic-input" ${field.required ? 'required' : ''}>
${optionsHTML}
</select>