-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdashboard.html
More file actions
3592 lines (3331 loc) · 152 KB
/
dashboard.html
File metadata and controls
3592 lines (3331 loc) · 152 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="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TSC Bridge — Dashboard</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet">
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect x='8' y='16' width='48' height='36' rx='4' fill='%23141620' stroke='%232563eb' stroke-width='2.5'/%3E%3Crect x='14' y='22' width='36' height='8' rx='2' fill='%230a0b10' stroke='%232563eb' stroke-width='1.5'/%3E%3Ccircle cx='46' cy='25' r='2' fill='%2334d399'/%3E%3C/svg%3E">
<style>
:root {
--primary: #2563eb;
--primary-hover: #1d4ed8;
--primary-light: rgba(37,99,235,0.06);
--surface: #fff;
--surface-2: #f8f9fb;
--text: #1a1d2e;
--text-dim: #64748b;
--text-muted: #94a3b8;
--border: #e2e8f0;
--green: #16a34a;
--red: #dc2626;
--font-mono: 'SF Mono','JetBrains Mono','Cascadia Code','Consolas',monospace;
}
*,*::before,*::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; font-size: 13px; color: var(--text); background: var(--surface-2); }
/* === FULL-HEIGHT APP SHELL === */
.app-shell { display: flex; flex-direction: column; height: 100vh; }
/* Header — compact */
.app-header {
background: var(--surface); border-bottom: 1px solid var(--border);
padding: 6px 16px; display: flex; align-items: center; justify-content: space-between;
flex-shrink: 0; z-index: 10;
}
.app-header .brand { display: flex; align-items: center; gap: 8px; }
.app-header .brand .brand-icon {
width: 24px; height: 24px; background: var(--primary); border-radius: 5px;
display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 10px;
}
.app-header .brand img { height: 24px; border-radius: 5px; }
.app-header .brand h1 { font-size: 13px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.header-controls { display: flex; align-items: center; gap: 6px; }
.header-controls select { font-size: 12px; padding: 2px 24px 2px 8px; height: 28px; max-width: 160px; border-color: var(--border); }
.header-controls .badge { font-size: 10px; padding: 3px 6px; }
/* Tab nav — slim */
.tab-nav {
background: var(--surface); border-bottom: 1px solid var(--border);
padding: 0 16px; display: flex; gap: 0; flex-shrink: 0;
}
.tab-nav .nav-link {
padding: 8px 14px; font-size: 12px; font-weight: 600;
color: var(--text-dim); border: none; background: none;
border-bottom: 2px solid transparent; cursor: pointer;
white-space: nowrap; display: flex; align-items: center; gap: 5px;
transition: all 0.12s;
}
.tab-nav .nav-link:hover { color: var(--text); }
.tab-nav .nav-link.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-nav .nav-link .bi { font-size: 13px; }
/* Content area — fills remaining space */
.app-content { flex: 1; overflow: hidden; position: relative; }
.tab-panel { display: none; height: 100%; overflow-y: auto; padding: 12px 16px; }
.tab-panel.active { display: flex; flex-direction: column; }
/* === COMPACT COMPONENTS === */
.section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); margin: 0 0 8px; }
.card { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); overflow: visible; }
.card-header { font-weight: 600; font-size: 12px; background: var(--surface-2); padding: 8px 12px; }
.card-body { padding: 10px 12px; overflow: visible; }
.table { font-size: 12px; margin: 0; }
.table th { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-dim); padding: 6px 8px; }
.table td { padding: 6px 8px; vertical-align: middle; }
.btn-sm { font-size: 11px; padding: 3px 8px; }
.form-control-sm, .form-select-sm { font-size: 12px; padding: 3px 8px; height: 28px; }
.form-label { font-size: 11px; font-weight: 600; color: var(--text-dim); margin-bottom: 2px; }
/* Drop zone */
#excelDropZone { transition: all 0.2s; }
#excelDropZone.drag-over { border-color: var(--primary) !important; background: var(--primary-light); }
/* Column chips for mapping */
.col-chip {
display: inline-block; padding: 1px 6px; font-size: 10px; font-weight: 500;
background: #f1f5f9; border: 1px solid var(--border); border-radius: 4px;
cursor: pointer; transition: all 0.1s; font-family: var(--font-mono);
}
.col-chip:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
/* Designer — fills tab panel height */
#tab-designer.active { padding: 0; gap: 0; }
.designer-wrap { display: flex; flex: 1; overflow: hidden; background: var(--surface); border-top: 1px solid var(--border); }
.designer-top-bar {
display: flex; align-items: center; justify-content: space-between;
padding: 6px 12px; background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.designer-toolbar {
width: 44px; background: var(--surface-2); border-right: 1px solid var(--border);
display: flex; flex-direction: column; align-items: center; padding: 6px 0; gap: 2px; flex-shrink: 0;
}
.designer-toolbar button {
width: 32px; height: 32px; border: none; background: none; border-radius: 6px;
display: flex; align-items: center; justify-content: center;
font-size: 14px; color: var(--text-dim); cursor: pointer;
}
.designer-toolbar button:hover { background: var(--primary-light); color: var(--primary); }
.designer-canvas-wrap {
flex: 1; display: flex; align-items: center; justify-content: center;
padding: 12px; background: #f1f5f9; overflow: auto; position: relative;
}
.designer-canvas-wrap canvas { cursor: crosshair; box-shadow: 0 1px 8px rgba(0,0,0,0.08); border-radius: 2px; }
.designer-props {
width: 240px; border-left: 1px solid var(--border); background: var(--surface);
padding: 10px; overflow-y: auto; font-size: 12px; flex-shrink: 0;
}
.designer-props label { font-weight: 600; font-size: 10px; text-transform: uppercase; color: var(--text-dim); margin-bottom: 1px; }
.designer-props .form-control, .designer-props .form-select { font-size: 12px; padding: 2px 6px; height: 26px; }
.designer-props textarea.form-control { height: auto; }
.designer-tspl {
background: #1e293b; color: #94a3b8; padding: 6px 12px; font-family: var(--font-mono);
font-size: 10px; max-height: 80px; overflow-y: auto; white-space: pre-wrap;
flex-shrink: 0; border-top: 1px solid var(--border);
}
.designer-actions { padding: 4px 12px; background: var(--surface); border-top: 1px solid var(--border); display: flex; gap: 4px; flex-shrink: 0; }
/* Batch wizard — compact */
.wizard-steps { display: flex; gap: 0; margin-bottom: 10px; }
.wizard-step {
flex: 1; text-align: center; padding: 8px; font-size: 11px; font-weight: 600;
color: var(--text-muted); border-bottom: 2px solid var(--border); cursor: pointer;
}
.wizard-step.active { color: var(--primary); border-bottom-color: var(--primary); }
.wizard-step.done { color: var(--green); border-bottom-color: var(--green); }
.wizard-panel { display: none; }
.wizard-panel.active { display: block; }
/* Template cards */
.template-card {
border: 1px solid var(--border); border-radius: 8px; padding: 10px;
cursor: pointer; transition: all 0.12s; background: var(--surface); font-size: 12px;
}
.template-card:hover { border-color: var(--primary); }
.template-card.selected { border-color: var(--primary); background: var(--primary-light); }
/* Toast */
.toast-container { position: fixed; bottom: 12px; right: 12px; z-index: 9999; }
/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
/* Utility */
.gap-1 { gap: 4px !important; }
.gap-2 { gap: 6px !important; }
</style>
</head>
<body>
<div class="app-shell">
<!-- ==================== HEADER ==================== -->
<header class="app-header">
<div class="brand">
<div class="brand-icon" id="brandIcon">TB</div>
<img id="brandLogo" src="" alt="" style="display:none;">
<h1 id="brandName">TSC Bridge</h1>
</div>
<div class="header-controls">
<select id="headerPrinter" class="form-select form-select-sm" onchange="onPrinterChange(this.value)" title="Impresora">
<option value="">Sin impresoras</option>
</select>
<select id="headerPreset" class="form-select form-select-sm" onchange="onPresetChange(this.value)" title="Preset de etiqueta">
<option value="">Sin preset</option>
</select>
<span class="badge bg-primary" id="dpiBadge">203 DPI</span>
<span class="badge bg-secondary" id="versionBadge">v--</span>
</div>
</header>
<!-- ==================== TAB NAV ==================== -->
<nav class="tab-nav" id="tabNav">
<button class="nav-link active" data-tab="printers"><i class="bi bi-printer"></i> Impresoras</button>
<button class="nav-link" data-tab="designer"><i class="bi bi-pencil-square"></i> Diseñar</button>
<button class="nav-link" data-tab="batch"><i class="bi bi-grid-3x3-gap"></i> Batch</button>
<button class="nav-link" data-tab="templates"><i class="bi bi-file-earmark-text"></i> Templates</button>
<button class="nav-link" data-tab="config"><i class="bi bi-gear"></i> Config</button>
</nav>
<!-- ==================== CONTENT ==================== -->
<div class="app-content">
<!-- ========== TAB 1: IMPRESORAS ========== -->
<div class="tab-panel active" id="tab-printers">
<div class="d-flex justify-content-between align-items-center mb-2">
<span class="section-title">Impresoras</span>
<button class="btn btn-sm btn-outline-primary" onclick="discoverPrinters()"><i class="bi bi-arrow-clockwise me-1"></i>Escanear</button>
</div>
<div class="card" style="flex:1;overflow:auto;">
<table class="table table-hover mb-0" id="printerTable">
<thead class="table-light" style="position:sticky;top:0;">
<tr><th>Nombre</th><th>Tipo</th><th>DPI</th><th>Estado</th><th class="text-end">Acciones</th></tr>
</thead>
<tbody id="printerTableBody">
<tr><td colspan="5" class="text-center text-muted py-3">Cargando...</td></tr>
</tbody>
</table>
</div>
<div class="d-flex gap-2 align-items-center mt-2" style="flex-shrink:0;">
<input type="text" id="manualIP" class="form-control form-control-sm" placeholder="IP:puerto" style="max-width:180px;">
<button class="btn btn-sm btn-outline-primary" onclick="addManualPrinter()">+ Manual</button>
<div id="manualPrintersList" class="d-flex gap-1 flex-wrap" style="flex:1;"></div>
<div class="d-flex gap-2 ms-auto align-items-center">
<div class="form-check form-switch mb-0"><input class="form-check-input" type="checkbox" id="shareToggle" onchange="toggleShare(this.checked)"><label class="form-check-label" style="font-size:11px;">USB Share</label></div>
<div class="form-check form-switch mb-0"><input class="form-check-input" type="checkbox" id="autostartToggle" onchange="toggleAutostart(this.checked)"><label class="form-check-label" style="font-size:11px;">Autostart</label></div>
</div>
</div>
</div>
<!-- ========== TAB 2: DISENAR ========== -->
<div class="tab-panel" id="tab-designer">
<div class="designer-top-bar">
<div class="d-flex gap-2 align-items-center">
<span class="section-title" style="margin:0;">Diseñador</span>
<select id="designerStandard" class="form-select form-select-sm" style="width:auto;height:24px;font-size:11px;padding:0 20px 0 6px;" onchange="applyStandardPreset()">
<option value="">Sin estandar</option>
<option value="gafete">Gafete</option>
<option value="gs1-128">GS1-128</option>
<option value="iso-15223">ISO 15223</option>
</select>
<div id="standardWarnings" style="display:contents;"></div>
</div>
<div class="d-flex gap-1">
<button class="btn btn-sm btn-outline-secondary" onclick="toggleLabelConfig()" title="Configurar etiqueta"><i class="bi bi-gear"></i></button>
<button class="btn btn-sm btn-primary" onclick="showVariableInputModal('print')"><i class="bi bi-printer"></i> Imprimir</button>
<button class="btn btn-sm btn-outline-primary" onclick="showVariableInputModal('preview')"><i class="bi bi-eye"></i></button>
<button class="btn btn-sm btn-outline-secondary" onclick="Designer.saveLocal()"><i class="bi bi-save"></i></button>
<button class="btn btn-sm btn-outline-secondary" onclick="Designer.exportJSON()"><i class="bi bi-filetype-json"></i></button>
<button class="btn btn-sm btn-outline-secondary" onclick="Designer.importJSON()"><i class="bi bi-upload"></i></button>
<input type="file" id="importJSONInput" accept=".json" style="display:none;" onchange="Designer.handleImportJSON(event)">
</div>
</div>
<!-- Label Configurator -->
<div id="labelConfigPanel" style="display:none;background:var(--surface);border-bottom:1px solid var(--border);padding:8px 16px;flex-shrink:0;">
<div class="d-flex gap-4 align-items-end flex-wrap">
<div>
<label class="form-label">Tamano etiqueta</label>
<div class="d-flex gap-1 align-items-center">
<input type="number" id="cfgLabelW" class="form-control form-control-sm" style="width:65px;" value="30" step="1" min="10" max="200" onchange="applyLabelConfig()">
<span style="font-size:11px;color:var(--text-muted);">x</span>
<input type="number" id="cfgLabelH" class="form-control form-control-sm" style="width:65px;" value="22" step="1" min="5" max="200" onchange="applyLabelConfig()">
<span style="font-size:11px;color:var(--text-muted);">mm</span>
</div>
</div>
<div>
<label class="form-label">Borde etiqueta</label>
<select id="cfgLabelBorder" class="form-select form-select-sm" style="width:auto;" onchange="applyLabelConfig()">
<option value="none">Sin borde</option>
<option value="simple">Simple</option>
<option value="double">Doble línea</option>
<option value="thick">Grueso</option>
<option value="rounded">Redondeado</option>
<option value="shadow">Con sombra</option>
<option value="inset">Doble inset</option>
<option value="ornate">Ornamental</option>
<option value="deco">Art Déco</option>
<option value="ticket">Ticket / Cupón</option>
<option value="dashed">Línea cortada</option>
<option value="certificate">Certificado</option>
<option value="filigree">Filigrana</option>
<option value="dotted">Punteado</option>
</select>
</div>
<div>
<label class="form-label">Grosor borde</label>
<input type="number" id="cfgBorderWidth" class="form-control form-control-sm" style="width:55px;" value="2" min="1" max="10" step="1" onchange="applyLabelConfig()">
</div>
<div>
<label class="form-label">Radio esquina</label>
<input type="number" id="cfgBorderRadius" class="form-control form-control-sm" style="width:55px;" value="0" min="0" max="20" step="1" onchange="applyLabelConfig()">
</div>
<div>
<label class="form-label">Margen interno</label>
<input type="number" id="cfgPadding" class="form-control form-control-sm" style="width:55px;" value="2" min="0" max="20" step="0.5" onchange="applyLabelConfig()">
</div>
<div class="d-flex gap-1">
<button class="btn btn-sm btn-outline-primary" onclick="previewLabelBorder()"><i class="bi bi-eye me-1"></i>Preview</button>
</div>
</div>
</div>
<div class="designer-wrap">
<!-- Left toolbar -->
<div class="designer-toolbar">
<button onclick="Designer.addElement('text')" title="Texto (T)"><i class="bi bi-fonts"></i></button>
<button onclick="Designer.addElement('barcode')" title="Barcode (B)"><i class="bi bi-upc-scan"></i></button>
<button onclick="Designer.addElement('qrcode')" title="QR Code (Q)"><i class="bi bi-qr-code"></i></button>
<button onclick="Designer.addElement('line')" title="Linea (L)"><i class="bi bi-dash-lg"></i></button>
<button onclick="Designer.addElement('rectangle')" title="Rectangulo (R)"><i class="bi bi-square"></i></button>
<button onclick="Designer.addElement('image')" title="Imagen (I)"><i class="bi bi-image"></i></button>
<button onclick="Designer.addElement('anticopy')" title="Patron anti-fotocopia"><i class="bi bi-shield-lock"></i></button>
<hr style="width:80%;margin:4px 0;border-color:var(--border);">
<button onclick="Designer.deleteSelected()" title="Eliminar seleccionado"><i class="bi bi-trash text-danger"></i></button>
<button onclick="Designer.toggleGrid()" title="Toggle grid" id="btnGrid"><i class="bi bi-grid-3x3"></i></button>
<button onclick="Designer.autoFitElements()" title="Auto-ajustar al lienzo"><i class="bi bi-aspect-ratio"></i></button>
</div>
<!-- Center canvas -->
<div class="designer-canvas-wrap">
<canvas id="designerCanvas" width="600" height="440"></canvas>
</div>
<!-- Right properties -->
<div class="designer-props" id="designerProps">
<div id="propsEmpty" class="text-center text-muted py-5">
<i class="bi bi-cursor" style="font-size:24px;"></i>
<p class="mt-2">Selecciona un elemento<br>o agrega uno desde la barra</p>
</div>
<div id="propsPanel" style="display:none;">
<div class="mb-2">
<label>Tipo</label>
<input type="text" id="propType" class="form-control form-control-sm" readonly>
</div>
<div class="row g-2 mb-2">
<div class="col-6"><label>X (mm)</label><input type="number" id="propX" class="form-control form-control-sm" step="0.5" onchange="Designer.updateFromProps()"></div>
<div class="col-6"><label>Y (mm)</label><input type="number" id="propY" class="form-control form-control-sm" step="0.5" onchange="Designer.updateFromProps()"></div>
</div>
<div class="row g-2 mb-2">
<div class="col-6"><label>Ancho (mm)</label><input type="number" id="propW" class="form-control form-control-sm" step="0.5" onchange="Designer.updateFromProps()"></div>
<div class="col-6"><label>Alto (mm)</label><input type="number" id="propH" class="form-control form-control-sm" step="0.5" onchange="Designer.updateFromProps()"></div>
</div>
<div class="mb-2" id="propContentWrap">
<label>Contenido</label>
<textarea id="propContent" class="form-control form-control-sm" rows="2" onchange="Designer.updateFromProps()"></textarea>
<small class="text-muted">Usa {variable} para campos dinamicos</small>
</div>
<div class="row g-2 mb-2" id="propFontWrap">
<div class="col-6">
<label>Fuente TSPL</label>
<select id="propFont" class="form-select form-select-sm" onchange="Designer.updateFromProps()">
<option value="1">1 (8x12)</option>
<option value="2">2 (12x20)</option>
<option value="3" selected>3 (16x24)</option>
<option value="4">4 (24x32)</option>
<option value="5">5 (32x48)</option>
</select>
</div>
<div class="col-6">
<label>Multiplicador</label>
<select id="propFontMult" class="form-select form-select-sm" onchange="Designer.updateFromProps()">
<option value="1">1x</option><option value="2">2x</option>
<option value="3">3x</option><option value="4">4x</option>
<option value="5">5x</option><option value="6">6x</option>
<option value="7">7x</option><option value="8">8x</option>
</select>
</div>
</div>
<div class="row g-2 mb-2">
<div class="col-6">
<label>Rotacion</label>
<select id="propRotation" class="form-select form-select-sm" onchange="Designer.updateFromProps()">
<option value="0">0</option><option value="90">90</option>
<option value="180">180</option><option value="270">270</option>
</select>
</div>
<div class="col-6" id="propAlignWrap">
<label>Alineacion</label>
<select id="propAlign" class="form-select form-select-sm" onchange="Designer.updateFromProps()">
<option value="left">Izquierda</option>
<option value="center">Centro</option>
<option value="right">Derecha</option>
</select>
</div>
</div>
<div class="row g-2 mb-2" id="propStrokeWrap">
<div class="col-6">
<label>Grosor (dots)</label>
<input type="number" id="propStrokeWidth" class="form-control form-control-sm" value="2" min="1" max="20" step="1" onchange="Designer.updateFromProps()">
</div>
<div class="col-6">
<label>Borde</label>
<select id="propBorder" class="form-select form-select-sm" onchange="Designer.updateFromProps()">
<option value="none">Sin borde</option>
<option value="solid">Solido</option>
<option value="dashed">Punteado</option>
<option value="double">Doble</option>
</select>
</div>
</div>
<div id="propDataWrap" class="mb-2" style="display:none;">
<label>Campo de datos</label>
<select id="propDataField" class="form-select form-select-sm" onchange="Designer.insertDataField()">
<option value="">Insertar {variable}...</option>
</select>
<small class="text-muted">Inserta un campo que se reemplaza en batch</small>
</div>
<div id="propAnticopyWrap" style="display:none;" class="mb-2">
<label>Texto anti-fotocopia</label>
<input type="text" id="propAnticopyText" class="form-control form-control-sm" value="COPIA" onchange="Designer.updateFromProps()">
<div class="row g-2 mt-1">
<div class="col-6">
<label>Densidad</label>
<select id="propAnticopyDensity" class="form-select form-select-sm" onchange="Designer.updateFromProps()">
<option value="light">Ligera</option>
<option value="medium" selected>Media</option>
<option value="heavy">Densa</option>
</select>
</div>
<div class="col-6">
<label>Angulo</label>
<select id="propAnticopyAngle" class="form-select form-select-sm" onchange="Designer.updateFromProps()">
<option value="45">45°</option>
<option value="30">30°</option>
<option value="60">60°</option>
</select>
</div>
</div>
</div>
<div id="propBarcodeWrap" style="display:none;" class="mb-2">
<label>Tipo Barcode</label>
<select id="propBarcodeType" class="form-select form-select-sm" onchange="Designer.updateFromProps()">
<option value="128">Code 128</option>
<option value="EAN13">EAN-13</option>
<option value="39">Code 39</option>
<option value="93">Code 93</option>
</select>
</div>
<!-- QR Builder -->
<div id="propQRWrap" style="display:none;">
<label>Tipo QR</label>
<select id="propQRType" class="form-select form-select-sm mb-2" onchange="Designer.updateQRType()">
<option value="free">Texto libre</option>
<option value="vcard">vCard</option>
<option value="url">URL</option>
<option value="wifi">WiFi</option>
</select>
<div id="qrFreeWrap"><small class="text-muted">Edita el contenido arriba</small></div>
<div id="qrVcardWrap" style="display:none;">
<input type="text" class="form-control form-control-sm mb-1" id="qrFN" placeholder="Nombre {nombre}" onchange="Designer.updateQRFields()">
<input type="text" class="form-control form-control-sm mb-1" id="qrLN" placeholder="Apellido {apellido}" onchange="Designer.updateQRFields()">
<input type="text" class="form-control form-control-sm mb-1" id="qrTel" placeholder="Telefono {tel}" onchange="Designer.updateQRFields()">
<input type="text" class="form-control form-control-sm mb-1" id="qrEmail" placeholder="Email {email}" onchange="Designer.updateQRFields()">
<input type="text" class="form-control form-control-sm mb-1" id="qrOrg" placeholder="Empresa {org}" onchange="Designer.updateQRFields()">
<input type="text" class="form-control form-control-sm" id="qrTitle" placeholder="Cargo {cargo}" onchange="Designer.updateQRFields()">
</div>
<div id="qrUrlWrap" style="display:none;">
<input type="text" class="form-control form-control-sm" id="qrURLPattern" placeholder="https://example.com/{id}" onchange="Designer.updateQRFields()">
</div>
<div id="qrWifiWrap" style="display:none;">
<input type="text" class="form-control form-control-sm mb-1" id="qrSSID" placeholder="SSID" onchange="Designer.updateQRFields()">
<input type="text" class="form-control form-control-sm mb-1" id="qrPass" placeholder="Password" onchange="Designer.updateQRFields()">
<select id="qrSecurity" class="form-select form-select-sm" onchange="Designer.updateQRFields()">
<option value="WPA">WPA/WPA2</option>
<option value="WEP">WEP</option>
<option value="">Sin seguridad</option>
</select>
</div>
</div>
</div>
</div>
</div>
<div class="designer-tspl" id="tsplPreview">-- TSPL --</div>
</div>
<!-- ========== TAB 3: BATCH ========== -->
<div class="tab-panel" id="tab-batch">
<span class="section-title">Impresion por Lote</span>
<!-- Wizard steps -->
<div class="wizard-steps">
<div class="wizard-step active" data-step="1" onclick="goToStep(1)">1. Subir Excel</div>
<div class="wizard-step" data-step="2" onclick="goToStep(2)">2. Plantilla</div>
<div class="wizard-step" data-step="3" onclick="goToStep(3)">3. Mapeo</div>
<div class="wizard-step" data-step="4" onclick="goToStep(4)">4. Ejecutar</div>
</div>
<!-- Step 1: Upload Excel -->
<div class="wizard-panel active" id="batchStep1">
<div class="card">
<div class="card-body text-center py-4" id="excelDropZone" style="border:2px dashed var(--border);border-radius:8px;cursor:pointer;transition:all .2s;" onclick="openFileUpload('excel')">
<div style="width:56px;height:56px;border-radius:12px;background:linear-gradient(135deg,#dcfce7,#bbf7d0);margin:0 auto 10px;display:flex;align-items:center;justify-content:center;">
<i class="bi bi-cloud-arrow-up" style="font-size:26px;color:var(--green);"></i>
</div>
<h6 class="mb-1" style="font-size:13px;font-weight:600;">Arrastra tu archivo aqui</h6>
<p class="text-muted mb-3" style="font-size:11px;">o haz clic para seleccionar</p>
<div class="d-flex gap-2 justify-content-center" style="font-size:11px;">
<span class="badge bg-light text-dark border" style="font-weight:500;">.xlsx</span>
<span class="badge bg-light text-dark border" style="font-weight:500;">.xls</span>
<span class="badge bg-light text-dark border" style="font-weight:500;">.csv</span>
<span class="badge bg-light text-dark border" style="font-weight:500;">.pdf</span>
</div>
<input type="file" id="excelFile" accept=".xlsx,.xls,.csv,.pdf" style="display:none;" onchange="handleFileSelected(event)">
<input type="file" id="pdfFile" accept=".pdf" style="display:none;" onchange="handlePdfUpload(event)">
<div id="uploadProgress" style="display:none;margin-top:12px;">
<div class="progress" style="height:4px;"><div class="progress-bar" style="width:0%"></div></div>
<p class="text-muted mt-1" style="font-size:11px;" id="uploadFileName">Cargando...</p>
</div>
</div>
</div>
<div id="excelPreview" class="mt-3" style="display:none;">
<h6>Vista previa <span class="badge bg-secondary" id="excelRowCount">0</span> filas</h6>
<div class="table-responsive">
<table class="table table-sm table-bordered" id="excelPreviewTable"></table>
</div>
<button class="btn btn-primary" onclick="goToStep(2)">Siguiente <i class="bi bi-arrow-right"></i></button>
</div>
</div>
<!-- Step 2: Select Template -->
<div class="wizard-panel" id="batchStep2">
<div class="d-flex justify-content-between align-items-center mb-3">
<h6 class="mb-0">Seleccionar Plantilla</h6>
<button class="btn btn-sm btn-outline-secondary" onclick="loadAllTemplatesForBatch()"><i class="bi bi-arrow-clockwise me-1"></i>Recargar</button>
</div>
<div class="row g-3" id="batchTemplateGrid">
<div class="col-12 text-center text-muted py-4">Cargando plantillas...</div>
</div>
<div class="mt-3">
<button class="btn btn-outline-secondary me-2" onclick="goToStep(1)"><i class="bi bi-arrow-left me-1"></i>Anterior</button>
<button class="btn btn-primary" onclick="goToStep(3)" id="btnNextStep3" disabled>Siguiente <i class="bi bi-arrow-right"></i></button>
</div>
</div>
<!-- Step 3: Map Columns -->
<div class="wizard-panel" id="batchStep3">
<h6 class="mb-3">Mapeo de Campos</h6>
<div id="mappingContainer"></div>
<div id="mappingPreview" class="mt-3" style="display:none;">
<h6>Vista previa de mapeo (primeras 4 filas)</h6>
<div class="table-responsive"><table class="table table-sm table-bordered" id="mappingPreviewTable"></table></div>
</div>
<div class="mt-3">
<button class="btn btn-outline-secondary me-2" onclick="goToStep(2)"><i class="bi bi-arrow-left me-1"></i>Anterior</button>
<button class="btn btn-primary" onclick="goToStep(4)">Siguiente <i class="bi bi-arrow-right"></i></button>
</div>
</div>
<!-- Step 4: Execute -->
<div class="wizard-panel" id="batchStep4">
<div class="card">
<div class="card-body">
<h6><i class="bi bi-play-circle me-2"></i>Ejecutar Impresion</h6>
<div class="row g-3 mb-3">
<div class="col-auto">
<label class="form-label">Copias por etiqueta</label>
<input type="number" id="batchCopies" class="form-control form-control-sm" value="1" min="1" style="width:80px;">
</div>
<div class="col-auto">
<label class="form-label">Modo</label>
<select id="batchMode" class="form-select form-select-sm" style="width:auto;">
<option value="tspl">TSPL (texto)</option>
<option value="raster">Raster (bitmap)</option>
</select>
</div>
</div>
<div class="d-flex gap-2">
<button class="btn btn-primary" onclick="executeBatch('print')"><i class="bi bi-printer me-1"></i>Imprimir TSPL</button>
<button class="btn btn-outline-success" onclick="executeBatch('pdf')"><i class="bi bi-filetype-pdf me-1"></i>Generar PDF</button>
<button class="btn btn-outline-secondary" onclick="executeBatch('preview')"><i class="bi bi-eye me-1"></i>Vista previa TSPL</button>
</div>
<div id="batchProgress" class="mt-3" style="display:none;">
<div class="progress" style="height:6px;">
<div class="progress-bar progress-bar-striped progress-bar-animated" id="batchProgressBar" style="width:0%"></div>
</div>
<small class="text-muted" id="batchProgressText">Procesando...</small>
</div>
<div id="batchResult" class="mt-3" style="display:none;"></div>
<div id="batchTsplPreview" class="mt-3" style="display:none;">
<h6>TSPL Generado</h6>
<pre class="bg-dark text-light p-3 rounded" style="max-height:300px;overflow:auto;font-size:12px;" id="batchTsplCode"></pre>
</div>
</div>
</div>
<div class="mt-3">
<button class="btn btn-outline-secondary" onclick="goToStep(3)"><i class="bi bi-arrow-left me-1"></i>Anterior</button>
</div>
</div>
</div>
<!-- ========== TAB 4: TEMPLATES ========== -->
<div class="tab-panel" id="tab-templates">
<div class="d-flex justify-content-between align-items-center mb-2">
<span class="section-title">Plantillas</span>
<button class="btn btn-sm btn-outline-primary" onclick="loadTemplates()"><i class="bi bi-arrow-clockwise"></i></button>
</div>
<!-- Server templates -->
<div class="mb-4">
<div class="d-flex justify-content-between align-items-center mb-2">
<h6 class="mb-0"><i class="bi bi-cloud me-2"></i>Plantillas del Servidor</h6>
<span class="badge bg-secondary" id="serverTemplateCount">0</span>
</div>
<div id="serverTemplatesNotConnected" class="card" style="display:none;">
<div class="card-body text-center py-4">
<i class="bi bi-cloud-slash" style="font-size:32px;color:var(--text-muted);"></i>
<p class="text-muted mt-2 mb-2">No conectado al servidor</p>
<button class="btn btn-sm btn-primary" onclick="switchTab('config')">Conectar</button>
</div>
</div>
<div class="row g-3" id="serverTemplatesGrid"></div>
</div>
<!-- Local templates -->
<div>
<div class="d-flex justify-content-between align-items-center mb-2">
<h6 class="mb-0"><i class="bi bi-hdd me-2"></i>Plantillas Locales</h6>
<span class="badge bg-secondary" id="localTemplateCount">0</span>
</div>
<div class="row g-3" id="localTemplatesGrid"></div>
</div>
</div>
<!-- ========== TAB 5: CONFIG ========== -->
<div class="tab-panel" id="tab-config">
<span class="section-title">Configuracion</span>
<!-- Account -->
<div class="card mb-3">
<div class="card-header"><i class="bi bi-person-circle me-2"></i>Cuenta</div>
<div class="card-body">
<div class="row g-3">
<div class="col-md-8">
<label class="form-label">URL del Servidor</label>
<input type="text" id="cfgApiUrl" class="form-control form-control-sm" readonly>
</div>
<div class="col-md-4 d-flex align-items-end gap-2">
<span class="badge" id="cfgAuthBadge">--</span>
</div>
</div>
<div class="row g-3 mt-1">
<div class="col-md-6">
<small class="text-muted">Whitelabel: <strong id="cfgWLName">--</strong></small>
</div>
<div class="col-md-6 text-end">
<button class="btn btn-sm btn-outline-primary me-1" onclick="reconnectAuth()"><i class="bi bi-arrow-repeat me-1"></i>Reconectar</button>
<button class="btn btn-sm btn-outline-danger" onclick="logoutAuth()"><i class="bi bi-box-arrow-right me-1"></i>Cerrar sesion</button>
</div>
</div>
</div>
</div>
<!-- Printing -->
<div class="card mb-3">
<div class="card-header"><i class="bi bi-printer me-2"></i>Impresion</div>
<div class="card-body">
<div class="row g-3">
<div class="col-md-6">
<label class="form-label">Preset por defecto</label>
<select id="cfgDefaultPreset" class="form-select form-select-sm" onchange="saveDefaultPreset(this.value)"></select>
</div>
<div class="col-md-6">
<label class="form-label">Impresora por defecto</label>
<select id="cfgDefaultPrinter" class="form-select form-select-sm" onchange="saveDefaultPrinter(this.value)"></select>
</div>
</div>
<div class="mt-3">
<label class="form-label">DPI por impresora</label>
<div id="cfgDPITable"></div>
</div>
</div>
</div>
<!-- System -->
<div class="card mb-3">
<div class="card-header"><i class="bi bi-cpu me-2"></i>Sistema</div>
<div class="card-body">
<div class="row g-3">
<div class="col-md-4">
<label class="form-label">Puerto HTTP</label>
<input type="number" id="cfgPort" class="form-control form-control-sm" readonly>
</div>
<div class="col-md-4">
<div class="form-check form-switch mt-4">
<input class="form-check-input" type="checkbox" id="cfgNetScan">
<label class="form-check-label">Escaneo de red</label>
</div>
</div>
<div class="col-md-4">
<label class="form-label">Intervalo scan (s)</label>
<input type="number" id="cfgNetInterval" class="form-control form-control-sm" min="10" max="300">
</div>
</div>
<div class="row g-3 mt-1">
<div class="col-md-4">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="cfgShareEnabled">
<label class="form-check-label">Compartir USB</label>
</div>
</div>
<div class="col-md-4">
<label class="form-label">Puerto Share</label>
<input type="number" id="cfgSharePort" class="form-control form-control-sm">
</div>
<div class="col-md-4 d-flex align-items-end">
<button class="btn btn-sm btn-primary" onclick="saveSystemConfig()"><i class="bi bi-check-lg me-1"></i>Guardar</button>
</div>
</div>
</div>
</div>
</div>
</div><!-- /app-content -->
</div><!-- /app-shell -->
<!-- ==================== SETUP WIZARD MODAL ==================== -->
<div class="modal fade" id="setupWizard" data-bs-backdrop="static" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><i class="bi bi-gear me-2"></i>Configurar TSC Bridge</h5>
</div>
<div class="modal-body">
<!-- Login method tabs -->
<ul class="nav nav-tabs mb-3" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="tab-password" data-bs-toggle="tab" data-bs-target="#setup-password-pane" type="button" role="tab">
<i class="bi bi-person-lock me-1"></i>Usuario y contraseña
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="tab-apikey" data-bs-toggle="tab" data-bs-target="#setup-apikey-pane" type="button" role="tab">
<i class="bi bi-key me-1"></i>API Key
</button>
</li>
</ul>
<div class="tab-content">
<!-- Password login pane -->
<div class="tab-pane fade show active" id="setup-password-pane" role="tabpanel">
<div class="mb-3">
<label class="form-label">URL del servidor</label>
<input type="url" id="setup-pwd-url" class="form-control" placeholder="https://latam.paygateway-api.com/api">
</div>
<div class="mb-3">
<label class="form-label">White-label ID</label>
<input type="number" id="setup-pwd-wl" class="form-control" value="20">
</div>
<div class="mb-3">
<label class="form-label">Email</label>
<input type="email" id="setup-pwd-email" class="form-control" placeholder="tu@email.com">
</div>
<div class="mb-3">
<label class="form-label">Contraseña</label>
<input type="password" id="setup-pwd-password" class="form-control">
</div>
<small class="text-muted"><i class="bi bi-info-circle me-1"></i>Solo el dueño de la tienda puede conectar. Usuarios staff no tienen permiso.</small>
</div>
<!-- API Key pane -->
<div class="tab-pane fade" id="setup-apikey-pane" role="tabpanel">
<div class="mb-3">
<label class="form-label">URL del servidor</label>
<input type="url" id="setup-url" class="form-control" placeholder="https://latam.paygateway-api.com/api">
</div>
<div class="mb-3">
<label class="form-label">API Key</label>
<input type="text" id="setup-key" class="form-control">
</div>
<div class="mb-3">
<label class="form-label">API Secret</label>
<input type="password" id="setup-secret" class="form-control">
</div>
<div class="mb-3">
<label class="form-label">White-label ID (opcional)</label>
<input type="number" id="setup-wl" class="form-control" value="20">
</div>
</div>
</div>
<div id="setup-error" class="alert alert-danger d-none mt-3"></div>
<div id="setup-success" class="alert alert-success d-none mt-3"></div>
</div>
<div class="modal-footer">
<button class="btn btn-primary" id="setup-connect-btn" onclick="setupConnectDispatch()"><i class="bi bi-plug me-1"></i>Conectar</button>
<button class="btn btn-secondary" data-bs-dismiss="modal">Omitir</button>
</div>
</div>
</div>
</div>
<!-- ==================== TEMPLATE PREVIEW MODAL ==================== -->
<div class="modal fade" id="templatePreviewModal" tabindex="-1">
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="previewModalTitle">Vista Previa</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body text-center" id="previewModalBody">
<div class="spinner-border text-primary" role="status"></div>
</div>
</div>
</div>
</div>
<!-- ==================== VARIABLE INPUT MODAL ==================== -->
<div class="modal fade" id="variableInputModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><i class="bi bi-input-cursor-text me-2"></i>Datos de la etiqueta</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body" id="variableInputBody"></div>
<div class="modal-footer">
<button class="btn btn-secondary" data-bs-dismiss="modal">Cancelar</button>
<button class="btn btn-outline-secondary" id="btnPreviewVars"><i class="bi bi-eye me-1"></i>Preview</button>
<button class="btn btn-primary" id="btnPrintVars"><i class="bi bi-printer me-1"></i>Imprimir</button>
</div>
</div>
</div>
</div>
<!-- ==================== TOAST CONTAINER ==================== -->
<div class="toast-container" id="toast-container"></div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
'use strict';
// ===================== GLOBAL STATE =====================
const AppState = {
printers: [],
selectedPrinter: '',
selectedPreset: '',
dpi: 203,
printerDPI: {},
authState: {},
config: {},
presets: [],
localTemplates: [],
backendTemplates: [],
// Designer
designerElements: [],
designerSelected: null,
// Batch
batchRows: [],
batchColumns: [],
batchStep: 1,
batchTemplate: null,
batchMappings: {},
};
// ===================== API HELPER =====================
async function api(method, path, body, opts = {}) {
const fetchOpts = { method, headers: {} };
if (body && !(body instanceof FormData)) {
fetchOpts.headers['Content-Type'] = 'application/json';
fetchOpts.body = JSON.stringify(body);
} else if (body instanceof FormData) {
fetchOpts.body = body;
}
const res = await fetch(path, fetchOpts);
if (opts.raw) return res;
if (!res.ok) {
const text = await res.text();
throw new Error(text);
}
const ct = res.headers.get('content-type') || '';
if (ct.includes('application/json')) return res.json();
if (ct.includes('image/')) return res.blob();
return res.text();
}
// ===================== TOAST =====================
function showToast(message, type = 'success') {
const container = document.getElementById('toast-container');
const bgClass = type === 'error' ? 'text-bg-danger' : type === 'warning' ? 'text-bg-warning' : 'text-bg-success';
const toast = document.createElement('div');
toast.className = `toast align-items-center ${bgClass} border-0 show`;
toast.setAttribute('role', 'alert');
toast.innerHTML = `<div class="d-flex"><div class="toast-body">${message}</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button></div>`;
container.appendChild(toast);
setTimeout(() => { toast.classList.remove('show'); setTimeout(() => toast.remove(), 300); }, 3500);
}
// ===================== TAB SWITCHING =====================
function switchTab(tabId) {
document.querySelectorAll('.tab-nav .nav-link').forEach(btn => btn.classList.toggle('active', btn.dataset.tab === tabId));
document.querySelectorAll('.tab-panel').forEach(p => p.classList.toggle('active', p.id === 'tab-' + tabId));
if (tabId === 'designer') Designer.init('designerCanvas');
if (tabId === 'templates') loadTemplates();
if (tabId === 'batch') loadAllTemplatesForBatch();
}
document.getElementById('tabNav').addEventListener('click', e => {
const btn = e.target.closest('[data-tab]');
if (btn) switchTab(btn.dataset.tab);
});
// ===================== HEADER CONTROLS =====================
function populatePrinterSelector() {
const sel = document.getElementById('headerPrinter');
sel.innerHTML = '';
if (AppState.printers.length === 0) {
sel.innerHTML = '<option value="">Sin impresoras</option>';
return;
}
AppState.printers.forEach(p => {
const opt = document.createElement('option');
opt.value = p.name;
opt.textContent = p.name + (p.online === false ? ' (offline)' : '');
opt.selected = p.name === AppState.selectedPrinter;
sel.appendChild(opt);
});
}
function populatePresetSelector() {
const sel = document.getElementById('headerPreset');
sel.innerHTML = '';
AppState.presets.forEach(p => {
const opt = document.createElement('option');
opt.value = p.id;
opt.textContent = p.name;
opt.selected = p.id === AppState.selectedPreset;
sel.appendChild(opt);
});
}
function onPrinterChange(name) {
AppState.selectedPrinter = name;
updateDPIBadge();
}
function onPresetChange(id) {
AppState.selectedPreset = id;
const preset = AppState.presets.find(p => p.id === id);
if (preset) {
Designer.labelW = preset.label_width || 30;
Designer.labelH = preset.label_height || 22;
Designer.resizeCanvas();
Designer.render();
}
}
function updateDPIBadge() {
const dpi = AppState.printerDPI[AppState.selectedPrinter] || AppState.dpi || 203;
AppState.dpi = dpi;
document.getElementById('dpiBadge').textContent = dpi + ' DPI';
}
function updateAuthBadge() {
const badge = document.getElementById('cfgAuthBadge');
const s = AppState.authState;
if (s.connected) {
badge.className = 'badge bg-success';
badge.textContent = 'Conectado';
} else if (s.configured) {
badge.className = 'badge bg-warning';
badge.textContent = 'Desconectado';
} else {
badge.className = 'badge bg-secondary';
badge.textContent = 'No configurado';
}
}
// ===================== INIT =====================
async function init() {
try {
// Fetch status
const status = await api('GET', '/status');
AppState.printers = status.printers || [];
AppState.printerDPI = status.printer_dpi || {};
AppState.dpi = status.default_dpi || 203;
document.getElementById('versionBadge').textContent = 'v' + (status.version || '?');
// Config
const config = await api('GET', '/config');
AppState.config = config;
AppState.selectedPrinter = config.default_printer || (AppState.printers.length ? AppState.printers[0].name : '');
AppState.selectedPreset = config.default_preset || '';
// Presets
const presetsRes = await api('GET', '/presets');
AppState.presets = presetsRes.presets || [];
// Auth state
try {
const auth = await api('GET', '/auth/state');
AppState.authState = auth;
updateAuthBadge();
} catch(e) {
AppState.authState = { configured: false, connected: false };
}
// Whitelabel
try {
const wl = await api('GET', '/whitelabel');
if (wl.name && wl.name !== 'TSC Bridge') {
document.getElementById('brandName').textContent = wl.name;
}
if (wl.logo_url) {
document.getElementById('brandLogo').src = wl.logo_url;
document.getElementById('brandLogo').style.display = '';
document.getElementById('brandIcon').style.display = 'none';