Repository navigation
Expand file tree
/
Copy pathbase.html
More file actions
1090 lines (1012 loc) · 60.4 KB
/
Copy pathbase.html
File metadata and controls
1090 lines (1012 loc) · 60.4 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="{{ current_language_code or 'en' }}" dir="{{ 'rtl' if is_rtl else 'ltr' }}">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
<title>{% block title %}{{ app_name }}{% endblock %}</title>
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta name="app-timezone" content="{{ timezone }}">
<meta name="description" content="Professional time tracking and project management">
<meta name="theme-color" content="#4F46E5">
<!-- Open Graph / Social Media -->
<meta property="og:type" content="website">
<meta property="og:title" content="{% block og_title %}{{ app_name }} - Professional Time Tracking{% endblock %}">
<meta property="og:description" content="{% block og_description %}Professional time tracking and project management application{% endblock %}">
<meta property="og:image" content="{% block og_image %}{{ url_for('static', filename='images/og-image.png', _external=True) }}{% endblock %}">
<meta property="og:url" content="{{ request.url }}">
<meta property="og:site_name" content="{{ app_name }}">
<!-- Twitter Card -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="{% block twitter_title %}{{ app_name }} - Professional Time Tracking{% endblock %}">
<meta name="twitter:description" content="{% block twitter_description %}Professional time tracking and project management application{% endblock %}">
<meta name="twitter:image" content="{% block twitter_image %}{{ url_for('static', filename='images/og-image.png', _external=True) }}{% endblock %}">
{% include 'partials/_head.html' %}
{% block extra_css %}{% endblock %}
{% block extra_head %}{% endblock %}
</head>
<body class="font-sans antialiased bg-background-light dark:bg-background-dark text-text-light dark:text-text-dark{% if is_admin_user %} fab-dock-admin{% endif %}"{% if current_user.is_authenticated %} data-authenticated="true"{% endif %}>
<script nonce="{{ csp_nonce() }}">
// Sidebar collapsed ASAP
(function(){ try { if (localStorage.getItem('sidebar-collapsed') === 'true') { document.documentElement.classList.add('sidebar-collapsed'); } } catch(_) {} })();
</script>
<a href="#mainContentAnchor" class="sr-only focus:not-sr-only focus-ring absolute left-2 top-2 z-[1000] px-3 py-2 bg-card-light dark:bg-card-dark border border-border-light dark:border-border-dark rounded">{{ _('Skip to content') }}</a>
<div id="appShell" class="flex min-h-screen">
<!-- Sidebar -->
{% include 'partials/_sidebar.html' %}
<!-- Main content: pb for mobile bottom nav + safe-area -->
<div id="mainContent" class="flex-1 flex flex-col min-h-screen min-w-0 transition-all duration-200 ease-in-out md:ml-64 md:pb-0 pb-16">
<!-- Header -->
{% include 'partials/_topbar.html' %}
<!-- Offline Indicator -->
{% include 'components/offline_indicator.html' %}
<!-- Chat User Selector (widget shell lives in #fabDock below) -->
{% if is_module_enabled('team_chat') %}
{% include 'components/chat_user_selector.html' %}
{% endif %}
<!-- Flash Messages (hidden, converted to toasts by toast-notifications.js) -->
<div id="flash-messages-container" class="hidden">
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert {% if category == 'success' %}alert-success{% elif category == 'error' %}alert-danger{% elif category == 'warning' %}alert-warning{% else %}alert-info{% endif %}" data-toast-message="{{ message }}" data-toast-type="{{ category }}"></div>
{% endfor %}
{% endif %}
{% endwith %}
</div>
{# Support monetization: single channel via user menu → support modal (banner removed). #}
<!-- Main page content: full width of column; inner pages may use their own max-w-* -->
<div class="flex-1 flex flex-col min-w-0 w-full">
<main id="mainContentAnchor" class="flex-1 min-h-0 min-w-0 w-full p-4 sm:p-6 overflow-x-hidden">
{% block content %}{% endblock %}
</main>
{% if current_user.is_authenticated %}
<p class="text-center text-xs text-text-muted-light dark:text-text-muted-dark px-4 pb-2 w-full shrink-0">{{ _('Built by an independent developer') }}</p>
{% endif %}
</div>
</div>
{% if current_user.is_authenticated %}
<meta name="idle-timeout-minutes" content="{{ settings.idle_timeout_minutes if settings else 30 }}">
<meta name="idle-unanswered-action" content="{{ settings.idle_unanswered_action if settings and settings.idle_unanswered_action else 'review' }}">
<meta name="vapid-public-key" content="{{ config.VAPID_PUBLIC_KEY if config.VAPID_PUBLIC_KEY else '' }}">
<meta name="long-entry-threshold-hours" content="8">
{% endif %}
{% if is_admin_user %}
<div id="adminVersionUpdateRoot" class="hidden fixed bottom-20 right-4 z-[60] max-w-sm w-[min(24rem,calc(100vw-2rem))] rounded-xl border border-border-light dark:border-border-dark bg-card-light dark:bg-card-dark shadow-xl" role="region" aria-label="{{ _('Software update') }}">
<div class="p-4 sm:p-5">
<div class="flex items-start gap-3">
<span class="text-2xl shrink-0" aria-hidden="true">🚀</span>
<div class="min-w-0 flex-1">
<h2 id="adminVersionUpdateTitle" class="text-sm font-semibold text-text-light dark:text-text-dark"></h2>
<p id="adminVersionUpdatePublished" class="mt-1 text-xs text-text-muted-light dark:text-text-muted-dark"></p>
<div id="adminVersionUpdateNotes" class="mt-2 text-sm text-text-light dark:text-text-dark whitespace-pre-wrap break-words max-h-40 overflow-y-auto"></div>
<button type="button" id="adminVersionUpdateReadMore" class="hidden mt-1 text-xs text-primary hover:underline">{{ _('Read more') }}</button>
</div>
<button type="button" id="adminVersionUpdateClose" class="shrink-0 p-1 rounded-md text-text-muted-light hover:bg-background-light dark:text-text-muted-dark dark:hover:bg-background-dark" aria-label="{{ _('Close') }}">×</button>
</div>
<div class="mt-4 flex flex-wrap gap-2">
<a id="adminVersionUpdateViewRelease" href="#" target="_blank" rel="noopener noreferrer" class="inline-flex items-center justify-center px-3 py-1.5 rounded-lg bg-primary text-white text-sm font-medium hover:bg-primary-dark">{{ _('View Release') }}</a>
<button type="button" id="adminVersionUpdateDismiss" class="inline-flex items-center justify-center px-3 py-1.5 rounded-lg border border-border-light dark:border-border-dark text-sm">{{ _('Dismiss') }}</button>
<button type="button" id="adminVersionUpdateDismissVersion" class="inline-flex items-center justify-center px-3 py-1.5 rounded-lg border border-border-light dark:border-border-dark text-sm">{{ _("Don't show again for this version") }}</button>
</div>
</div>
</div>
{% endif %}
{% if current_user.is_authenticated %}
<script nonce="{{ csp_nonce() }}">
window.__TT_SYSTEM_INSTANCE_ID = {{ (system_instance_id or '')|tojson }};
window.__TT_SUPPORT_PURCHASE_URL = {{ (support_purchase_url or '')|tojson }};
</script>
{% endif %}
{% if current_user.is_authenticated and support_ui_json %}
<script nonce="{{ csp_nonce() }}" type="application/json" id="support-ui-bootstrap">{{ support_ui_json|safe }}</script>
{% include 'components/support_modal.html' %}
{% endif %}
{% if current_user.is_authenticated %}
{# Actions FAB on mobile only (CSS). Desktop: topbar timer + Ctrl+K. Chat/AI via tools overflow. #}
<div id="fabDock"
class="{% if is_admin_user %}fab-dock--admin{% endif %}"
role="region"
aria-label="{{ _('Quick actions dock') }}"
data-dashboard-url="{{ url_for('main.dashboard') }}"
data-manual-entry-url="{{ url_for('timer.manual_entry') }}"
data-new-task-url="{{ url_for('tasks.create_task') }}"
data-new-project-url="/projects/create"
data-new-client-url="/clients/create"
data-reports-url="/reports/">
<div id="unifiedActionsRoot" role="group" aria-label="{{ _('Actions') }}">
<div id="unifiedActionsMenu" class="hidden rounded-xl border border-border-light dark:border-border-dark bg-card-light dark:bg-card-dark shadow-2xl py-1 text-left" role="menu" aria-hidden="true">
<button type="button" class="unified-actions__item flex w-full items-center gap-3 px-3 py-2.5 text-sm text-text-light dark:text-text-dark hover:bg-background-light dark:hover:bg-background-dark text-left" data-action="start" role="menuitem">
<span class="w-5 text-center text-primary" aria-hidden="true"><i class="fas fa-play text-xs"></i></span>
<span>{{ _('Start Timer') }}</span>
</button>
<button type="button" class="unified-actions__item flex w-full items-center gap-3 px-3 py-2.5 text-sm text-text-light dark:text-text-dark hover:bg-background-light dark:hover:bg-background-dark text-left" data-action="log" role="menuitem">
<span class="w-5 text-center" aria-hidden="true"><i class="fas fa-clock text-xs"></i></span>
<span>{{ _('Log Time') }}</span>
</button>
<button type="button" class="unified-actions__item flex w-full items-center gap-3 px-3 py-2.5 text-sm text-text-light dark:text-text-dark hover:bg-background-light dark:hover:bg-background-dark text-left" data-action="task" role="menuitem">
<span class="w-5 text-center" aria-hidden="true"><i class="fas fa-tasks text-xs"></i></span>
<span>{{ _('New Task') }}</span>
</button>
<div class="my-1 border-t border-border-light dark:border-border-dark"></div>
<button type="button" class="unified-actions__item flex w-full items-center gap-3 px-3 py-2.5 text-sm text-text-light dark:text-text-dark hover:bg-background-light dark:hover:bg-background-dark text-left" data-action="project" role="menuitem">
<span class="w-5 text-center" aria-hidden="true"><i class="fas fa-folder-plus text-xs"></i></span>
<span>{{ _('New Project') }}</span>
</button>
<button type="button" class="unified-actions__item flex w-full items-center gap-3 px-3 py-2.5 text-sm text-text-light dark:text-text-dark hover:bg-background-light dark:hover:bg-background-dark text-left" data-action="client" role="menuitem">
<span class="w-5 text-center" aria-hidden="true"><i class="fas fa-user-plus text-xs"></i></span>
<span>{{ _('New Client') }}</span>
</button>
<button type="button" class="unified-actions__item flex w-full items-center gap-3 px-3 py-2.5 text-sm text-text-light dark:text-text-dark hover:bg-background-light dark:hover:bg-background-dark text-left" data-action="reports" role="menuitem">
<span class="w-5 text-center" aria-hidden="true"><i class="fas fa-chart-line text-xs"></i></span>
<span>{{ _('Reports') }}</span>
</button>
</div>
<button type="button" id="unifiedActionsFab" class="flex h-14 w-14 shrink-0 items-center justify-center rounded-full bg-primary text-white shadow-lg hover:bg-primary-dark focus:outline-none focus:ring-2 focus:ring-primary/50" aria-expanded="false" aria-haspopup="true" aria-controls="unifiedActionsMenu" title="{{ _('Actions') }}">
<i class="fas fa-bolt text-xl" aria-hidden="true"></i>
<span class="sr-only">{{ _('Actions') }}</span>
</button>
</div>
{% if is_module_enabled('team_chat') %}
{% include 'components/persistent_chat_widget.html' %}
{% endif %}
{% if ai_enabled %}
<div id="aiHelperRoot" class="shrink-0 relative z-[70]">
<button type="button" id="aiHelperFab" data-ai-helper-open class="flex h-14 w-14 shrink-0 items-center justify-center rounded-full bg-primary text-white shadow-lg hover:bg-primary-dark focus:outline-none focus:ring-2 focus:ring-primary/50" aria-label="{{ _('Open AI Helper') }}" title="{{ _('AI Helper') }}">
<i class="fas fa-wand-magic-sparkles text-xl" aria-hidden="true"></i>
<span class="sr-only">{{ _('AI Helper') }}</span>
</button>
</div>
</div>
<div id="aiHelperBackdrop" class="hidden fixed inset-0 z-[80] bg-black/30" data-ai-helper-close></div>
<section id="aiHelperDrawer" class="hidden fixed inset-y-0 right-0 z-[90] w-full max-w-xl bg-card-light dark:bg-card-dark border-l border-border-light dark:border-border-dark shadow-2xl flex flex-col" aria-label="{{ _('AI Helper') }}" role="dialog" aria-modal="true">
<header class="p-4 border-b border-border-light dark:border-border-dark flex items-start justify-between gap-4">
<div>
<h2 class="text-lg font-semibold text-text-light dark:text-text-dark">{{ _('AI Helper') }}</h2>
<p id="aiHelperProvider" class="text-xs text-text-muted-light dark:text-text-muted-dark">{{ _('Ask about your tracked work, summaries, gaps, and next actions.') }}</p>
</div>
<button type="button" data-ai-helper-close class="p-2 rounded-lg hover:bg-background-light dark:hover:bg-background-dark" aria-label="{{ _('Close') }}">×</button>
</header>
<div class="p-4 border-b border-border-light dark:border-border-dark">
<details class="text-sm">
<summary class="cursor-pointer font-medium text-text-light dark:text-text-dark">{{ _('Context included') }}</summary>
<pre id="aiHelperContext" class="mt-2 max-h-44 overflow-auto whitespace-pre-wrap rounded-lg bg-background-light dark:bg-background-dark p-3 text-xs text-text-muted-light dark:text-text-muted-dark">{{ _('Loading context preview...') }}</pre>
</details>
</div>
<div id="aiHelperMessages" class="flex-1 overflow-y-auto p-4 space-y-3"></div>
<div id="aiHelperActions" class="hidden border-t border-border-light dark:border-border-dark p-4 space-y-2"></div>
<form id="aiHelperForm" class="border-t border-border-light dark:border-border-dark p-4 space-y-3">
<textarea id="aiHelperPrompt" rows="3" class="form-input w-full" placeholder="{{ _('Ask: What did I work on this week? Draft a time entry from these notes...') }}"></textarea>
<div class="flex items-center justify-between gap-3">
<p id="aiHelperStatus" class="text-xs text-text-muted-light dark:text-text-muted-dark"></p>
<button type="submit" class="px-4 py-2 bg-primary text-white rounded-lg hover:bg-primary-dark">{{ _('Send') }}</button>
</div>
</form>
</section>
{% else %}
</div>
{% endif %}
{% endif %}
</div>
<script src="{{ url_for('static', filename='vendor/animejs/anime.min.js') }}"></script>
<script src="{{ url_for('static', filename='vendor/flatpickr/flatpickr.min.js') }}"></script>
<script src="{{ asset_url('core-a1') }}"></script>
{# Source fallbacks when dist bundles are not rebuilt yet (confirm/unsaved live in core-a1 after build). #}
<script src="{{ static_url('js/confirm-dialog.js') }}"></script>
<script src="{{ static_url('js/unsaved-changes.js') }}"></script>
{% if current_user.is_authenticated and support_ui_json %}
<script src="{{ asset_url('core-support', fallback='support-ui.js') }}"></script>
{% endif %}
<script src="{{ asset_url('core-a2') }}"></script>
<!-- Floating timer bar, idle tracking: authenticated users only -->
{% if current_user.is_authenticated %}
<script src="{{ asset_url('core-auth') }}"></script>
<!-- Real-time @mention notifications -->
<script src="{{ url_for('static', filename='vendor/socketio/socket.io.min.js') }}"></script>
<script nonce="{{ csp_nonce() }}">
(function(){
var uid = {{ current_user.id }};
if (!uid || typeof io === 'undefined') return;
try {
var socket = io();
socket.on('connect', function(){ socket.emit('join_user_room', { user_id: uid }); });
document.addEventListener('visibilitychange', function(){
if (document.visibilityState !== 'visible') return;
if (socket.disconnected) {
try { socket.connect(); } catch (e) {}
}
});
socket.on('user_mentioned', function(data){
if (!data) return;
var title = data.title || '{{ _('New mention') }}';
var msg = data.message || '{{ _('You were mentioned in a comment') }}';
if (window.toastManager && typeof window.toastManager.info === 'function') {
window.toastManager.info(msg, title);
} else if (typeof showToast === 'function') {
try { showToast(msg, 'info'); } catch (e) {}
}
});
// Server-side idle timeout (#722): show "Still working?" even when
// local idle detection did not fire (e.g. tab throttled).
socket.on('idle_timeout', function(data){
try {
if (typeof window.__ttShowIdlePrompt === 'function') {
var stopTs = Date.now() - 30 * 60 * 1000;
var meta = document.querySelector('meta[name="idle-timeout-minutes"]');
var mins = meta ? parseInt(meta.getAttribute('content'), 10) : 30;
if (!isNaN(mins) && mins >= 1) stopTs = Date.now() - mins * 60 * 1000;
window.__ttShowIdlePrompt(stopTs, data && data.idle_notified_at);
} else if (window.toastManager && data) {
window.toastManager.warning(data.message || 'Still working?', data.title || 'Idle timer');
}
} catch (e) {}
});
// The prompt was answered on another device (or expired
// server-side): dismiss locally and refresh the timer UI.
socket.on('idle_prompt_resolved', function(data){
try {
if (window.__ttDismissIdlePrompt) window.__ttDismissIdlePrompt();
if (data && data.stopped) {
if (window.__ttOnIdleAutoStop) window.__ttOnIdleAutoStop();
// Skip toast when this tab answered — respondIdle already toasted.
var localAnswer = window.__ttIdleLocalAnswerPending && window.__ttIdleLocalAnswerPending();
if (!localAnswer) {
var msg = (window.i18n && window.i18n.messages && window.i18n.messages.timerStoppedInactivity) || 'Timer stopped due to inactivity';
if (window.toastManager && window.toastManager.warning) {
window.toastManager.warning(msg, '', 5000);
}
}
} else {
document.dispatchEvent(new CustomEvent('tt:timer-status-changed'));
}
} catch (e) {}
});
// Grace expired elsewhere (tab closed): timer keeps running and is
// flagged for review — show the review banner in any open tab.
socket.on('timer_needs_review', function(data){
try { window.__ttShowNeedsReview && window.__ttShowNeedsReview(); } catch (e) {}
});
// Server auto-stopped due to unanswered idle prompt (auto_stop mode).
socket.on('timer_stopped', function(data){
try {
if (data && data.reason === 'idle_auto_stop') {
if (window.__ttOnIdleAutoStop) window.__ttOnIdleAutoStop();
var msg = (data && data.message) || (window.i18n && window.i18n.messages && window.i18n.messages.timerStoppedInactivity) || 'Timer stopped due to inactivity';
if (window.toastManager && window.toastManager.warning) {
window.toastManager.warning(msg, '', 5000);
}
}
} catch (e) {}
});
} catch (e) {
console.error('Mention socket init failed', e);
}
})();
</script>
{% if ai_enabled %}
<script src="{{ asset_url('core-ai') }}"></script>
{% endif %}
{% endif %}
{% if is_admin_user %}
<script src="{{ asset_url('core-admin') }}"></script>
{% endif %}
<script nonce="{{ csp_nonce() }}">window.__BASE_INIT__={timerStatus:"{{ url_for('timer.timer_status') }}",stopTimer:"{{ url_for('timer.stop_timer') }}",dashboard:"{{ url_for('main.dashboard') }}",manualEntry:"{{ url_for('timer.manual_entry') }}",newTask:"{{ url_for('tasks.create_task') }}"};</script>
<script src="{{ asset_url('core-c') }}"></script>
<script nonce="{{ csp_nonce() }}">
// Sidebar collapse logic with persisted state
(function(){
const appShell = document.getElementById('appShell');
const sidebar = document.getElementById('sidebar');
const main = document.getElementById('mainContent');
const collapseBtn = document.getElementById('sidebarCollapseBtn');
const desktopBtn = document.getElementById('desktopSidebarBtn');
const mobileBtn = document.getElementById('mobileSidebarBtn');
let flyout;
function applyCollapsed(isCollapsed){
// Toggle a class on the shell and documentElement (early script uses documentElement) so both stay in sync
const icon = document.getElementById('sidebarCollapseIcon');
if (isCollapsed){
appShell.classList.add('sidebar-collapsed');
document.documentElement.classList.add('sidebar-collapsed');
sidebar.classList.add('w-16');
sidebar.classList.remove('w-64');
// Adjust main content margin for collapsed sidebar
main.classList.remove('md:ml-64');
main.classList.add('md:ml-16');
icon && icon.classList.remove('fa-angles-left');
icon && icon.classList.add('fa-angles-right');
} else {
appShell.classList.remove('sidebar-collapsed');
document.documentElement.classList.remove('sidebar-collapsed');
sidebar.classList.remove('w-16');
sidebar.classList.add('w-64');
// Adjust main content margin for expanded sidebar
main.classList.remove('md:ml-16');
main.classList.add('md:ml-64');
icon && icon.classList.remove('fa-angles-right');
icon && icon.classList.add('fa-angles-left');
}
}
function toggleDesktopSidebar() {
const nowCollapsed = !appShell.classList.contains('sidebar-collapsed');
applyCollapsed(nowCollapsed);
try { localStorage.setItem('sidebar-collapsed', String(nowCollapsed)); } catch(_) {}
}
// Initialize from storage
try {
const saved = localStorage.getItem('sidebar-collapsed');
applyCollapsed(saved === 'true');
} catch(_) {}
// Desktop toggle (sidebar header + topbar expand)
collapseBtn && collapseBtn.addEventListener('click', toggleDesktopSidebar);
desktopBtn && desktopBtn.addEventListener('click', toggleDesktopSidebar);
// Mobile toggle with backdrop and proper close handlers
let backdrop = null;
function createBackdrop() {
if (!backdrop) {
backdrop = document.createElement('div');
backdrop.id = 'sidebarBackdrop';
backdrop.className = 'fixed inset-0 bg-black/50 z-40 md:hidden';
backdrop.style.display = 'none';
document.body.appendChild(backdrop);
// Close sidebar when clicking backdrop
backdrop.addEventListener('click', closeMobileSidebar);
}
return backdrop;
}
function openMobileSidebar() {
const isSmallScreen = window.innerWidth < 768; // md breakpoint
if (!isSmallScreen) return;
sidebar.classList.remove('hidden');
sidebar.style.zIndex = '50';
const bd = createBackdrop();
bd.style.display = 'block';
}
function closeMobileSidebar() {
sidebar.classList.add('hidden');
sidebar.style.zIndex = '10';
if (backdrop) {
backdrop.style.display = 'none';
}
}
function isSmallScreen() {
return window.innerWidth < 768; // md breakpoint
}
// Mobile toggle button
mobileBtn && mobileBtn.addEventListener('click', function(e){
e.stopPropagation();
if (sidebar.classList.contains('hidden')) {
openMobileSidebar();
} else {
closeMobileSidebar();
}
});
// Close sidebar when clicking outside (on small screens)
document.addEventListener('click', function(e) {
if (!isSmallScreen()) return;
if (sidebar.classList.contains('hidden')) return;
// Don't close if clicking inside sidebar or on mobile button
const clickedInside = sidebar.contains(e.target);
const clickedMobileBtn = mobileBtn && mobileBtn.contains(e.target);
if (!clickedInside && !clickedMobileBtn) {
closeMobileSidebar();
}
});
// Close sidebar when clicking on navigation links only (on small screens).
// Do not close when clicking dropdown toggles (section headings) so the user can expand and then select a sub-item.
if (sidebar) {
const menuLinks = sidebar.querySelectorAll('a[href]');
menuLinks.forEach(link => {
link.addEventListener('click', function(e) {
if (!isSmallScreen()) return;
const href = (this.getAttribute('href') || '').trim();
if (!href || href === '#') return;
// Small delay to allow navigation to start
setTimeout(() => {
closeMobileSidebar();
}, 100);
});
});
}
// Handle window resize - close sidebar if window becomes large
let resizeTimeout;
window.addEventListener('resize', function() {
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(function() {
if (!isSmallScreen() && !sidebar.classList.contains('hidden')) {
// Window is now large, ensure sidebar is visible (not hidden)
sidebar.classList.remove('hidden');
if (backdrop) {
backdrop.style.display = 'none';
}
} else if (isSmallScreen() && !sidebar.classList.contains('hidden')) {
// Still small screen, ensure backdrop is shown if sidebar is open
const bd = createBackdrop();
if (!sidebar.classList.contains('hidden')) {
bd.style.display = 'block';
}
}
}, 150);
});
// Preserve sidebar scroll position across page navigations
(function() {
const SIDEBAR_SCROLL_KEY = 'sidebar-scroll-position';
const LAST_URL_KEY = 'last-navigation-url';
// Save sidebar scroll position before navigation
function saveSidebarScroll() {
if (sidebar && !isSmallScreen()) {
try {
const scrollTop = sidebar.scrollTop;
localStorage.setItem(SIDEBAR_SCROLL_KEY, String(scrollTop));
localStorage.setItem(LAST_URL_KEY, window.location.pathname);
} catch(e) {
// Ignore localStorage errors
}
}
}
// Restore sidebar scroll position after page load
function restoreSidebarScroll() {
if (sidebar && !isSmallScreen()) {
try {
const savedScroll = localStorage.getItem(SIDEBAR_SCROLL_KEY);
const lastUrl = localStorage.getItem(LAST_URL_KEY);
const currentUrl = window.location.pathname;
// Only restore if we're on the same section (admin pages, etc.)
// This prevents restoring scroll when navigating to completely different sections
if (savedScroll && lastUrl && currentUrl) {
// Check if we're navigating within the same section
const sameSection = (
(lastUrl.startsWith('/admin') && currentUrl.startsWith('/admin')) ||
(lastUrl.startsWith('/projects') && currentUrl.startsWith('/projects')) ||
(lastUrl.startsWith('/timer') && currentUrl.startsWith('/timer')) ||
(lastUrl.startsWith('/reports') && currentUrl.startsWith('/reports'))
);
if (sameSection) {
// Small delay to ensure DOM is ready
setTimeout(() => {
sidebar.scrollTop = parseInt(savedScroll, 10) || 0;
}, 50);
}
}
} catch(e) {
// Ignore localStorage errors
}
}
}
// Save scroll position when clicking navigation links
if (sidebar) {
const navLinks = sidebar.querySelectorAll('a[href]');
navLinks.forEach(link => {
link.addEventListener('click', function() {
saveSidebarScroll();
});
});
}
// Restore scroll position on page load
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', restoreSidebarScroll);
} else {
restoreSidebarScroll();
}
})();
// Prevent unwanted scroll-to-top on navigation
(function() {
const MAIN_SCROLL_KEY = 'main-content-scroll-position';
const NAVIGATION_TYPE_KEY = 'navigation-type';
// Use browser's scroll restoration if available
if ('scrollRestoration' in history) {
history.scrollRestoration = 'manual';
}
// Save main content scroll position before navigation
function saveMainScroll() {
try {
const scrollY = window.scrollY || window.pageYOffset || document.documentElement.scrollTop;
localStorage.setItem(MAIN_SCROLL_KEY, String(scrollY));
// Mark as programmatic navigation (not back/forward)
sessionStorage.setItem(NAVIGATION_TYPE_KEY, 'navigate');
} catch(e) {
// Ignore storage errors
}
}
// Restore main content scroll position after page load
function restoreMainScroll() {
try {
const navType = sessionStorage.getItem(NAVIGATION_TYPE_KEY);
const savedScroll = localStorage.getItem(MAIN_SCROLL_KEY);
// Only restore scroll for back/forward navigation or same-section navigation
// For fresh navigations, let browser handle it naturally
if (navType === 'back-forward' && savedScroll) {
// Restore scroll position for back/forward navigation
setTimeout(() => {
window.scrollTo(0, parseInt(savedScroll, 10) || 0);
}, 0);
} else if (navType === 'navigate' && savedScroll) {
// For same-section navigation, restore scroll
const lastUrl = localStorage.getItem('last-navigation-url');
const currentUrl = window.location.pathname;
if (lastUrl && currentUrl) {
const sameSection = (
(lastUrl.startsWith('/admin') && currentUrl.startsWith('/admin')) ||
(lastUrl.startsWith('/projects') && currentUrl.startsWith('/projects')) ||
(lastUrl.startsWith('/timer') && currentUrl.startsWith('/timer')) ||
(lastUrl.startsWith('/reports') && currentUrl.startsWith('/reports'))
);
if (sameSection) {
setTimeout(() => {
window.scrollTo(0, parseInt(savedScroll, 10) || 0);
}, 50);
}
}
}
// Clear navigation type after processing
sessionStorage.removeItem(NAVIGATION_TYPE_KEY);
} catch(e) {
// Ignore storage errors
}
}
// Detect back/forward navigation
window.addEventListener('popstate', function() {
try {
sessionStorage.setItem(NAVIGATION_TYPE_KEY, 'back-forward');
} catch(e) {
// Ignore storage errors
}
});
// Save scroll position when clicking navigation links
document.addEventListener('click', function(e) {
const link = e.target.closest('a[href]');
if (link && link.href && !link.target && !link.hasAttribute('download')) {
const href = link.getAttribute('href');
// Only handle internal links
if (href && !href.startsWith('#') && !/^(javascript|data|vbscript):/i.test(href) && !href.startsWith('mailto:') && !href.startsWith('tel:')) {
try {
const url = new URL(href, window.location.origin);
// Only save if it's a same-origin navigation
if (url.origin === window.location.origin) {
saveMainScroll();
}
} catch(e) {
// If URL parsing fails, try to save anyway for relative URLs
if (href.startsWith('/')) {
saveMainScroll();
}
}
}
}
});
// Restore scroll position on page load
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', restoreMainScroll);
} else {
restoreMainScroll();
}
})();
// Flyout submenu when collapsed
function hideFlyout(){
if (flyout){ flyout.classList.add('hidden'); flyout.innerHTML=''; }
}
function ensureFlyout(){
if (!flyout){
flyout = document.createElement('div');
flyout.id = 'sidebarFlyout';
flyout.className = 'hidden fixed z-50 bg-card-light/95 dark:bg-card-dark/95 border border-border-light dark:border-border-dark rounded-2xl shadow-2xl p-2';
document.body.appendChild(flyout);
document.addEventListener('click', (e) => {
if (!flyout || flyout.classList.contains('hidden')) return;
const inside = flyout.contains(e.target);
const trigger = e.target.closest('[data-dropdown]');
if (!inside && !trigger) hideFlyout();
});
window.addEventListener('resize', hideFlyout);
window.addEventListener('scroll', function(e) {
if (flyout && !flyout.classList.contains('hidden') && (e.target === flyout || flyout.contains(e.target)))
return;
hideFlyout();
}, true);
}
}
function showFlyout(triggerBtn, listId){
ensureFlyout();
const list = document.getElementById(listId);
if (!list) return;
flyout.innerHTML = '';
const title = document.createElement('div');
title.className = 'flyout-title';
title.textContent = (triggerBtn.getAttribute('title') || triggerBtn.textContent || '').trim();
flyout.appendChild(title);
const ul = document.createElement('ul');
ul.className = 'space-y-1';
list.querySelectorAll('a').forEach((a) => {
const li = document.createElement('li');
const link = a.cloneNode(true);
const isActive = a.classList.contains('text-primary') || a.classList.contains('font-semibold') || a.getAttribute('aria-current') === 'page';
link.className = 'flyout-link text-text-light dark:text-text-dark';
if (isActive) link.classList.add('is-active');
li.appendChild(link);
ul.appendChild(li);
});
flyout.appendChild(ul);
const rect = triggerBtn.getBoundingClientRect();
const sbRect = sidebar.getBoundingClientRect();
const left = Math.min(sbRect.right + 12, window.innerWidth - flyout.offsetWidth - 12);
const top = Math.min(Math.max(12, rect.top), window.innerHeight - flyout.offsetHeight - 12);
flyout.style.left = left + 'px';
flyout.style.top = top + 'px';
flyout.classList.remove('hidden');
}
sidebar.addEventListener('click', function(e){
const btn = e.target.closest('[data-dropdown]');
if (!btn) return;
const listId = btn.getAttribute('data-dropdown');
const isCollapsed = appShell.classList.contains('sidebar-collapsed') || document.documentElement.classList.contains('sidebar-collapsed');
if (isCollapsed){
e.preventDefault();
e.stopPropagation();
showFlyout(btn, listId);
}
});
})();
</script>
<!-- Keyboard Shortcuts Help Modal -->
{% include 'components/keyboard_shortcuts_help.html' %}
<!-- Global Command Palette Modal (script must load after markup) -->
{% include 'partials/_command_palette.html' %}
<script src="{{ asset_url('command-palette') }}"></script>
<script nonce="{{ csp_nonce() }}">
var themeToggleDarkIcon = document.getElementById('theme-toggle-dark-icon');
var themeToggleLightIcon = document.getElementById('theme-toggle-light-icon');
var themeToggleSystemIcon = document.getElementById('theme-toggle-system-icon');
var themeToggleBtn = document.getElementById('theme-toggle');
var themeDropdown = document.getElementById('themeDropdown');
function getEffectiveTheme() {
var stored = localStorage.getItem('color-theme');
if (stored === 'system' || !stored) {
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}
return stored;
}
function updateThemeIcon() {
var stored = localStorage.getItem('color-theme') || 'system';
themeToggleDarkIcon.classList.add('hidden');
themeToggleLightIcon.classList.add('hidden');
if (themeToggleSystemIcon) themeToggleSystemIcon.classList.add('hidden');
if (stored === 'system') {
if (themeToggleSystemIcon) themeToggleSystemIcon.classList.remove('hidden');
else if (getEffectiveTheme() === 'dark') themeToggleDarkIcon.classList.remove('hidden');
else themeToggleLightIcon.classList.remove('hidden');
} else if (stored === 'dark') {
themeToggleDarkIcon.classList.remove('hidden');
} else {
themeToggleLightIcon.classList.remove('hidden');
}
}
function applyTheme(theme) {
if (theme === 'system') {
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
} else if (theme === 'dark') {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
var fpDark = document.getElementById('flatpickr-dark-theme');
if (fpDark) fpDark.media = document.documentElement.classList.contains('dark') ? 'all' : 'none';
updateThemeIcon();
}
updateThemeIcon();
if (themeToggleBtn && themeDropdown) {
themeToggleBtn.addEventListener('click', function(e) {
e.stopPropagation();
themeDropdown.classList.toggle('hidden');
themeToggleBtn.setAttribute('aria-expanded', themeDropdown.classList.contains('hidden') ? 'false' : 'true');
});
document.addEventListener('click', function() {
themeDropdown.classList.add('hidden');
themeToggleBtn.setAttribute('aria-expanded', 'false');
});
themeDropdown.addEventListener('click', function(e) { e.stopPropagation(); });
}
document.querySelectorAll('.theme-option').forEach(function(btn) {
btn.addEventListener('click', function() {
var newTheme = this.getAttribute('data-theme');
localStorage.setItem('color-theme', newTheme);
applyTheme(newTheme);
if (themeDropdown) themeDropdown.classList.add('hidden');
{% if current_user.is_authenticated %}
fetch('/api/theme', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-CSRFToken': '{{ csrf_token() }}' },
body: JSON.stringify({ theme: newTheme })
}).then(function(r) { return r.ok ? r.json() : r.json().then(function(d) { throw new Error(d.error || 'Failed'); }); })
.then(function(d) { if (d.success) console.log('Theme saved:', d.theme); })
.catch(function(err) { console.error('Theme save failed:', err); });
{% endif %}
});
});
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', function() {
if (localStorage.getItem('color-theme') === 'system') applyTheme('system');
});
function toggleDropdown(id, event) {
if (event) {
event.stopPropagation(); // Prevent event bubbling for nested dropdowns
}
const dropdown = document.getElementById(id);
const isCurrentlyHidden = dropdown.classList.contains('hidden');
// Define nested dropdowns and their parent dropdowns
// All admin submenus should keep the parent adminDropdown open
// pdfDropdown is directly under adminDropdown so it opens without needing System Settings open
const nestedDropdowns = {
'pdfDropdown': 'adminDropdown',
'adminUserMgmtDropdown': 'adminDropdown',
'adminSettingsDropdown': 'adminDropdown',
'adminSecurityDropdown': 'adminDropdown',
'adminIntegrationsDropdown': 'adminDropdown',
'adminDataDropdown': 'adminDropdown',
'adminMaintenanceDropdown': 'adminDropdown',
'reportsDropdown': 'financeDropdown' // Reports is nested under Finance
};
// Prevent parent dropdowns from closing when clicking inside nested dropdowns
// Add click handlers to nested dropdowns to stop propagation
if (id in nestedDropdowns) {
const nestedDropdown = document.getElementById(id);
if (nestedDropdown) {
// Remove existing handler if any to avoid duplicates
nestedDropdown.removeEventListener('click', nestedDropdown._stopPropagationHandler);
// Add new handler
nestedDropdown._stopPropagationHandler = function(e) {
e.stopPropagation();
};
nestedDropdown.addEventListener('click', nestedDropdown._stopPropagationHandler);
}
}
// If this is a nested dropdown, don't close its parent
const parentDropdown = nestedDropdowns[id];
// Special handling for reportsDropdown: keep it open if already open and on a reports page
if (id === 'reportsDropdown' && !isCurrentlyHidden) {
// Check if we're on a reports page by checking the current URL
const currentPath = window.location.pathname;
const isReportsPage = currentPath.includes('/reports/') || currentPath.includes('/scheduled') || currentPath.includes('/builder');
if (isReportsPage) {
// Don't close if we're on a reports page
return;
}
}
// Close all other top-level dropdowns in the sidebar (accordion behavior)
// Note: Nested dropdowns (like pdfDropdown) are not in this list, so they work independently
const allSidebarDropdowns = ['workDropdown', 'financeDropdown', 'adminDropdown', 'crmDropdown', 'toolsDropdown'];
// Build a list of all ancestor dropdowns that should stay open
const ancestorsToKeepOpen = [];
if (parentDropdown) {
ancestorsToKeepOpen.push(parentDropdown);
// Check if parent has a grandparent
const grandparent = nestedDropdowns[parentDropdown];
if (grandparent) {
ancestorsToKeepOpen.push(grandparent);
}
}
allSidebarDropdowns.forEach(dropdownId => {
// Don't close if this dropdown is an ancestor of the nested dropdown being opened
if (ancestorsToKeepOpen.includes(dropdownId)) {
return;
}
// Don't close adminDropdown if clicking on any of its submenus
if (dropdownId === 'adminDropdown' && parentDropdown === 'adminDropdown') {
return;
}
// Don't close financeDropdown if clicking on reportsDropdown
if (dropdownId === 'financeDropdown' && parentDropdown === 'financeDropdown') {
return;
}
if (dropdownId !== id) {
const otherDropdown = document.getElementById(dropdownId);
if (otherDropdown) {
otherDropdown.classList.add('hidden');
// Rotate chevron back for closed dropdowns
const otherBtn = document.querySelector(`[data-dropdown="${dropdownId}"]`);
if (otherBtn) {
const otherChevron = otherBtn.querySelector('.fa-chevron-down');
if (otherChevron) {
otherChevron.style.transform = 'rotate(0deg)';
}
}
}
}
});
// Toggle the clicked dropdown
if (isCurrentlyHidden) {
dropdown.classList.remove('hidden');
// If this is a nested dropdown, ensure all ancestor dropdowns are open
if (parentDropdown) {
// Open the direct parent
const parent = document.getElementById(parentDropdown);
if (parent) {
parent.classList.remove('hidden');
}
// Check if parent has a grandparent and open it too
const grandparent = nestedDropdowns[parentDropdown];
if (grandparent) {
const grandparentDropdown = document.getElementById(grandparent);
if (grandparentDropdown) {
grandparentDropdown.classList.remove('hidden');
}
}
}
} else {
dropdown.classList.add('hidden');
}
// Rotate chevron icon for visual feedback
const btn = document.querySelector(`[data-dropdown="${id}"]`);
if (btn) {
const chevron = btn.querySelector('.fa-chevron-down');
if (chevron) {
chevron.style.transition = 'transform 0.2s ease';
chevron.style.transform = isCurrentlyHidden ? 'rotate(180deg)' : 'rotate(0deg)';
}
}
}
// Delegated event listeners (replaces inline onclick handlers)
document.addEventListener('click', function(e) {
// Handle dropdown toggles via data-dropdown attribute
var dropdownBtn = e.target.closest('[data-dropdown]');
if (dropdownBtn) {
toggleDropdown(dropdownBtn.getAttribute('data-dropdown'), e);
return;
}
// Prevent propagation for links/elements inside dropdown menus
var noPropEl = e.target.closest('[data-no-propagation]');
if (noPropEl) {
e.stopPropagation();
}
});
// Prevent parent dropdowns from closing when clicking inside nested dropdowns
// This handles clicks on links and other elements inside nested dropdowns
document.addEventListener('click', function(e) {
// Check if the click is inside a nested dropdown
const clickedInsideNested = e.target.closest('#pdfDropdown') ||
e.target.closest('#reportsDropdown') ||
e.target.closest('#adminUserMgmtDropdown') ||
e.target.closest('#adminSecurityDropdown') ||
e.target.closest('#adminIntegrationsDropdown') ||
e.target.closest('#adminDataDropdown') ||
e.target.closest('#adminMaintenanceDropdown');
if (clickedInsideNested) {
// Find the parent dropdown and keep it open
const nestedDropdowns = {
'pdfDropdown': 'adminDropdown',
'adminUserMgmtDropdown': 'adminDropdown',
'adminSettingsDropdown': 'adminDropdown',
'adminSecurityDropdown': 'adminDropdown',
'adminIntegrationsDropdown': 'adminDropdown',
'adminDataDropdown': 'adminDropdown',
'adminMaintenanceDropdown': 'adminDropdown',
'reportsDropdown': 'financeDropdown'
};
// Find which nested dropdown was clicked
let clickedDropdownId = null;
for (const [nestedId, parentId] of Object.entries(nestedDropdowns)) {
if (e.target.closest('#' + nestedId)) {
clickedDropdownId = nestedId;
break;
}
}
if (clickedDropdownId && nestedDropdowns[clickedDropdownId]) {
const parentId = nestedDropdowns[clickedDropdownId];
const parentDropdown = document.getElementById(parentId);
if (parentDropdown) {
parentDropdown.classList.remove('hidden');
}
// Also keep adminDropdown open if parent is adminSettingsDropdown
if (parentId === 'adminSettingsDropdown') {
const adminDropdown = document.getElementById('adminDropdown');
if (adminDropdown) {
adminDropdown.classList.remove('hidden');
}
}
}
}
}, true); // Use capture phase to catch events early
</script>
<!-- Enhanced UI Scripts -->
<script src="{{ url_for('static', filename='vendor/chartjs/chart.umd.js') }}"></script>
<script src="{{ asset_url('core-d') }}"></script>
<!-- Onboarding: onboarding.js = core tour runner + restartTour(); onboarding-enhanced.js = enhanced steps/tooltips. Use restartTour() or window.onboardingManager to restart tour. -->
<!-- Shared utilities (must load before keyboard shortcuts) -->
{% if keyboard_shortcuts_config %}
<script nonce="{{ csp_nonce() }}">window.__KEYBOARD_SHORTCUTS_CONFIG__ = {{ keyboard_shortcuts_config | tojson }};</script>
{% endif %}
<!-- Advanced Features -->
<script src="{{ asset_url('core-e') }}"></script>
<script nonce="{{ csp_nonce() }}">
// ttConfirm / ttAlert loaded from confirm-dialog.js (core-a1 bundle).
function closeAllMenus(){
try { document.querySelectorAll('.bulk-menu').forEach(m => m.classList.add('hidden')); } catch(_) {}
}
function openMenu(triggerEl, menuId){
try{
const menu = document.getElementById(menuId);