domma-cms 0.55.1 → 0.69.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +194 -3
- package/README.md +18 -14
- package/admin/css/admin.css +1 -1
- package/admin/css/contacts.css +1 -0
- package/admin/dist/domma/domma-tools.css +3 -3
- package/admin/dist/domma/domma-tools.min.js +3 -3
- package/admin/index.html +1 -0
- package/admin/js/api.js +1 -1
- package/admin/js/app.js +4 -4
- package/admin/js/lib/analytics-shape.js +1 -0
- package/admin/js/lib/contacts-arrange.js +1 -0
- package/admin/js/lib/help-popover.js +1 -0
- package/admin/js/lib/notes-arrange.js +1 -0
- package/admin/js/lib/page-picker.js +1 -0
- package/admin/js/lib/plugin-accent.js +1 -0
- package/admin/js/lib/plugin-chrome.js +1 -0
- package/admin/js/lib/shortcode-context-menu.js +2 -2
- package/admin/js/lib/sidebar-grouping.js +1 -1
- package/admin/js/lib/sidebar-grouping.test.js +1 -1
- package/admin/js/lib/sidebar-renderer.js +4 -4
- package/admin/js/lib/slideover-resizable.js +1 -0
- package/admin/js/lib/todo-arrange.js +1 -0
- package/admin/js/lib/tool-kit.js +1 -0
- package/admin/js/templates/analytics.html +138 -0
- package/admin/js/templates/contacts.html +156 -0
- package/admin/js/templates/context-menu-editor.html +212 -0
- package/admin/js/templates/context-menus.html +16 -0
- package/admin/js/templates/notes.html +137 -0
- package/admin/js/templates/plugin-code.html +1 -1
- package/admin/js/templates/plugin-marketplace.html +17 -4
- package/admin/js/templates/plugins.html +13 -7
- package/{plugins/site-search/admin/templates/site-search.html → admin/js/templates/search.html} +50 -4
- package/admin/js/templates/settings.html +16 -97
- package/admin/js/templates/theme.html +211 -0
- package/admin/js/templates/todo.html +113 -0
- package/admin/js/views/analytics.js +62 -0
- package/admin/js/views/contacts.js +174 -0
- package/admin/js/views/context-menu-editor.js +55 -0
- package/admin/js/views/context-menus.js +5 -0
- package/admin/js/views/form-editor.js +7 -7
- package/admin/js/views/index.js +1 -1
- package/admin/js/views/notes.js +104 -0
- package/admin/js/views/plugin-marketplace.js +1 -1
- package/admin/js/views/plugins.js +28 -24
- package/admin/js/views/search.js +1 -0
- package/admin/js/views/settings.js +3 -3
- package/admin/js/views/theme.js +1 -0
- package/admin/js/views/todo.js +96 -0
- package/bin/cli.js +6 -10
- package/bin/lib/plugin-version.js +28 -0
- package/bin/update.js +27 -2
- package/config/menus/admin-sidebar.json +129 -23
- package/config/plugins.json +5 -5
- package/config/search.json +13 -0
- package/config/server.json +3 -1
- package/package.json +14 -10
- package/plugins/_lib/admin/mail/compose-window.js +914 -0
- package/plugins/_lib/admin/mail/contacts.js +301 -0
- package/plugins/_lib/admin/mail/diagnostics-section.js +133 -0
- package/plugins/_lib/admin/mail/folder-tree.js +254 -0
- package/plugins/_lib/admin/mail/identity.js +480 -0
- package/plugins/_lib/admin/mail/image-senders-section.js +131 -0
- package/plugins/_lib/admin/mail/keyboard.js +136 -0
- package/plugins/_lib/admin/mail/mail.css +1 -0
- package/plugins/_lib/admin/mail/mail.html +71 -0
- package/plugins/_lib/admin/mail/panes.js +253 -0
- package/plugins/_lib/admin/mail/reader-view.js +4473 -0
- package/plugins/_lib/admin/mail/resizable.js +26 -0
- package/plugins/_lib/admin/mail/rules.js +343 -0
- package/plugins/_lib/admin/mail/scheduling.js +203 -0
- package/plugins/_lib/admin/mail/section-kit.js +277 -0
- package/plugins/_lib/admin/mail/templates.js +238 -0
- package/plugins/_lib/admin/mail/threads.js +200 -0
- package/plugins/_lib/admin/mail/vacation.js +269 -0
- package/plugins/_lib/admin/ui/help.css +1 -0
- package/plugins/_lib/admin/ui/help.js +174 -0
- package/plugins/_lib/admin/ui/resizable.js +151 -0
- package/plugins/_lib/dataStore.js +117 -0
- package/plugins/_lib/mail/accounts.js +919 -0
- package/plugins/_lib/mail/bodyTokens.js +101 -0
- package/plugins/_lib/mail/compose.js +256 -0
- package/plugins/_lib/mail/defaults.js +57 -0
- package/plugins/_lib/mail/diagnostics.js +154 -0
- package/plugins/_lib/mail/envelope.js +161 -0
- package/plugins/_lib/mail/folders.js +192 -0
- package/plugins/_lib/mail/handoff.js +274 -0
- package/plugins/_lib/mail/imapPool.js +293 -0
- package/plugins/_lib/mail/mbox.js +74 -0
- package/plugins/_lib/mail/pollSchedule.js +79 -0
- package/plugins/_lib/mail/poller.js +135 -0
- package/plugins/_lib/mail/priority.js +138 -0
- package/plugins/_lib/mail/readRoutes.js +680 -0
- package/plugins/_lib/mail/render.js +291 -0
- package/plugins/_lib/mail/ruleRunner.js +152 -0
- package/plugins/_lib/mail/scheduler.js +254 -0
- package/plugins/_lib/mail/secretbox.js +229 -0
- package/plugins/_lib/mail/send.js +396 -0
- package/plugins/_lib/mail/store.js +1022 -0
- package/plugins/_lib/mail/sync.js +292 -0
- package/plugins/_lib/mail/syncPlan.js +126 -0
- package/plugins/_lib/mail/syncSelection.js +82 -0
- package/plugins/_lib/mail/unsubscribe.js +183 -0
- package/plugins/_lib/mail/vacationRunner.js +114 -0
- package/plugins/_lib/mail/write.js +473 -0
- package/plugins/_lib/schemaSync.js +83 -0
- package/plugins/_template/admin/css/index.css +0 -0
- package/plugins/_template/admin/templates/index.html +4 -4
- package/plugins/_template/admin/views/index.js +7 -0
- package/plugins/blog/CLAUDE.md +237 -0
- package/plugins/blog/admin/css/index.css +178 -0
- package/plugins/blog/admin/templates/blog.html +35 -41
- package/plugins/blog/admin/templates/categories.html +19 -6
- package/plugins/blog/admin/templates/comments.html +26 -9
- package/plugins/blog/admin/templates/post-editor.html +63 -40
- package/plugins/blog/admin/templates/settings.html +3 -9
- package/plugins/blog/admin/views/blog.js +288 -159
- package/plugins/blog/admin/views/categories.js +212 -206
- package/plugins/blog/admin/views/comments.js +207 -158
- package/plugins/blog/admin/views/kit.js +372 -0
- package/plugins/blog/admin/views/post-editor.js +306 -39
- package/plugins/blog/admin/views/settings-cog.js +56 -0
- package/plugins/blog/admin/views/settings.js +16 -84
- package/plugins/blog/blocks/blog-card-compact.css +17 -0
- package/plugins/blog/blocks/blog-card-compact.html +8 -0
- package/plugins/blog/blocks/blog-card-row.css +22 -0
- package/plugins/blog/blocks/blog-card-row.html +11 -0
- package/plugins/blog/blocks/blog-card.css +35 -0
- package/plugins/blog/blocks/blog-card.html +16 -0
- package/plugins/blog/blocks/blog-post-classic.css +15 -0
- package/plugins/blog/blocks/blog-post-classic.html +28 -0
- package/plugins/blog/blocks/blog-post-feature.css +20 -0
- package/plugins/blog/blocks/blog-post-feature.html +30 -0
- package/plugins/blog/blocks/blog-post-minimal.css +10 -0
- package/plugins/blog/blocks/blog-post-minimal.html +23 -0
- package/plugins/blog/blocks/blog-post-sidebar.css +22 -0
- package/plugins/blog/blocks/blog-post-sidebar.html +36 -0
- package/plugins/blog/collections/categories/schema.json +7 -6
- package/plugins/blog/collections/comments/schema.json +11 -10
- package/plugins/blog/collections/posts/schema.json +16 -13
- package/plugins/blog/config.js +6 -0
- package/plugins/blog/lib/layouts.js +304 -0
- package/plugins/blog/lib/page.js +158 -0
- package/plugins/blog/lib/render.js +119 -0
- package/plugins/blog/lib/samples.js +234 -0
- package/plugins/blog/plugin.js +259 -26
- package/plugins/blog/plugin.json +21 -73
- package/plugins/blog/plugin.public.js +217 -0
- package/plugins/blog/public/blog.css +177 -0
- package/plugins/blog/public/blog.js +586 -0
- package/plugins/blog/public/samples/aurora.svg +7 -0
- package/plugins/blog/public/samples/dusk.svg +7 -0
- package/plugins/blog/public/samples/ember.svg +7 -0
- package/plugins/blog/public/samples/harbour.svg +7 -0
- package/plugins/blog/public/samples/meadow.svg +7 -0
- package/plugins/blog/public/samples/rosewood.svg +7 -0
- package/plugins/blog/templates/index.html +9 -8
- package/plugins/blog/templates/post.html +4 -17
- package/plugins/blog/tests/layouts.test.js +97 -0
- package/plugins/blog/tests/public.test.js +71 -0
- package/plugins/free-tier.lock.json +74 -0
- package/plugins/mail-reader/CLAUDE.md +78 -0
- package/plugins/mail-reader/admin/views/mail.js +19 -0
- package/plugins/mail-reader/config.js +7 -0
- package/plugins/mail-reader/plugin.js +48 -0
- package/plugins/mail-reader/plugin.json +34 -0
- package/public/css/forms.css +1 -1
- package/public/css/search.css +1 -0
- package/public/css/site.css +1 -1
- package/public/css/theme-switcher.css +1 -0
- package/public/js/analytics.js +1 -0
- package/public/js/collection-context.js +2 -2
- package/public/js/context-menus.js +1 -0
- package/public/js/form-logic-engine.js +1 -1
- package/public/js/forms.js +2 -2
- package/public/js/search.js +1 -0
- package/public/js/site.js +1 -1
- package/public/js/theme-switcher.js +1 -0
- package/scripts/build.js +77 -4
- package/scripts/copy-domma.js +48 -0
- package/scripts/run-tests.mjs +92 -0
- package/scripts/seed.js +1996 -0
- package/{plugins/analytics/plugin.js → server/routes/api/analytics.js} +89 -41
- package/server/routes/api/collections.js +34 -0
- package/server/routes/api/contacts.js +506 -0
- package/server/routes/api/context-menus.js +104 -0
- package/server/routes/api/dashboard.js +8 -2
- package/server/routes/api/forms.js +42 -3
- package/{plugins/notes/plugin.js → server/routes/api/notes.js} +61 -17
- package/server/routes/api/notifications.js +69 -19
- package/server/routes/api/plugin-marketplace.js +78 -23
- package/server/routes/api/plugins.js +198 -9
- package/server/routes/api/search.js +43 -0
- package/server/routes/api/theme.js +69 -0
- package/server/routes/api/todo.js +178 -0
- package/server/routes/public.js +42 -7
- package/server/server.js +135 -1
- package/server/services/adapters/FileAdapter.js +6 -1
- package/server/services/collections.js +13 -3
- package/server/services/content.js +26 -0
- package/server/services/contextMenus.js +477 -0
- package/server/services/managerClient.js +72 -136
- package/server/services/markdown.js +124 -10
- package/server/services/permissionRegistry.js +74 -0
- package/server/services/pluginEntitlement.js +171 -0
- package/server/services/pluginEnvelope.js +242 -0
- package/server/services/pluginFiles.js +52 -11
- package/server/services/pluginInstaller.js +246 -26
- package/server/services/pluginScaffold.js +5 -0
- package/server/services/plugins.js +340 -7
- package/server/services/presetCollections.js +344 -0
- package/server/services/promoted-plugins-migration.js +254 -0
- package/server/services/publicCors.js +46 -0
- package/server/services/renderer.js +224 -22
- package/server/services/roles.js +1 -1
- package/server/services/search-migration.js +82 -0
- package/server/services/search.js +413 -0
- package/server/services/sidebar-migration.js +1 -0
- package/server/services/sidebarBadges.js +37 -0
- package/server/services/siteGitignore.js +307 -0
- package/server/services/themeSettings.js +580 -0
- package/server/services/users.js +8 -0
- package/server/templates/page.html +4 -2
- package/plugins/analytics/admin/templates/analytics.html +0 -61
- package/plugins/analytics/admin/views/analytics.js +0 -176
- package/plugins/analytics/config.js +0 -14
- package/plugins/analytics/plugin.json +0 -57
- package/plugins/analytics/public/inject-body.html +0 -60
- package/plugins/analytics/public/inject-head.html +0 -1
- package/plugins/blog/templates/author.html +0 -9
- package/plugins/blog/templates/category.html +0 -9
- package/plugins/blog/templates/tag.html +0 -9
- package/plugins/contacts/admin/templates/contacts.html +0 -126
- package/plugins/contacts/admin/views/contacts.js +0 -710
- package/plugins/contacts/collections/user-contact-groups/schema.json +0 -35
- package/plugins/contacts/collections/user-contacts/schema.json +0 -71
- package/plugins/contacts/config.js +0 -6
- package/plugins/contacts/data/contacts.json +0 -20
- package/plugins/contacts/plugin.js +0 -291
- package/plugins/contacts/plugin.json +0 -33
- package/plugins/demo-viewer/config.js +0 -4
- package/plugins/demo-viewer/plugin.js +0 -36
- package/plugins/demo-viewer/plugin.json +0 -9
- package/plugins/invoice/admin/templates/editor.html +0 -129
- package/plugins/invoice/admin/templates/index.html +0 -43
- package/plugins/invoice/admin/templates/issuers.html +0 -5
- package/plugins/invoice/admin/templates/receivers.html +0 -5
- package/plugins/invoice/admin/views/editor.js +0 -267
- package/plugins/invoice/admin/views/index.js +0 -155
- package/plugins/invoice/admin/views/issuers.js +0 -23
- package/plugins/invoice/admin/views/party-view.js +0 -148
- package/plugins/invoice/admin/views/receivers.js +0 -22
- package/plugins/invoice/collections/invoice-issuers/schema.json +0 -16
- package/plugins/invoice/collections/invoice-receivers/schema.json +0 -15
- package/plugins/invoice/collections/invoices/schema.json +0 -27
- package/plugins/invoice/config.js +0 -16
- package/plugins/invoice/plugin.js +0 -283
- package/plugins/invoice/plugin.json +0 -85
- package/plugins/invoice/templates/invoice-print.html +0 -213
- package/plugins/notes/admin/templates/notes.html +0 -83
- package/plugins/notes/admin/views/notes.js +0 -281
- package/plugins/notes/collections/user-notes/schema.json +0 -54
- package/plugins/notes/config.js +0 -6
- package/plugins/notes/data/notes.json +0 -1
- package/plugins/notes/plugin.json +0 -33
- package/plugins/site-search/admin/views/site-search.js +0 -116
- package/plugins/site-search/config.js +0 -15
- package/plugins/site-search/plugin.js +0 -188
- package/plugins/site-search/plugin.json +0 -40
- package/plugins/site-search/public/inject-body.html +0 -17
- package/plugins/site-search/public/inject-head.html +0 -1
- package/plugins/site-search/public/search.css +0 -1
- package/plugins/site-search/public/search.js +0 -1
- package/plugins/surveys/admin/templates/audience.html +0 -47
- package/plugins/surveys/admin/templates/results.html +0 -58
- package/plugins/surveys/admin/templates/survey-editor.html +0 -141
- package/plugins/surveys/admin/templates/surveys.html +0 -25
- package/plugins/surveys/admin/views/audience.js +0 -301
- package/plugins/surveys/admin/views/results.js +0 -172
- package/plugins/surveys/admin/views/survey-editor.js +0 -211
- package/plugins/surveys/admin/views/surveys.js +0 -161
- package/plugins/surveys/collections/survey-contacts/schema.json +0 -13
- package/plugins/surveys/collections/survey-groups/schema.json +0 -11
- package/plugins/surveys/collections/survey-invites/schema.json +0 -16
- package/plugins/surveys/collections/surveys/schema.json +0 -23
- package/plugins/surveys/config.js +0 -8
- package/plugins/surveys/plugin.js +0 -174
- package/plugins/surveys/plugin.json +0 -65
- package/plugins/surveys/public/dist-shared.mjs +0 -1
- package/plugins/surveys/public/survey.css +0 -1
- package/plugins/surveys/public/survey.mjs +0 -1
- package/plugins/surveys/templates/survey-page.html +0 -63
- package/plugins/theme-switcher/admin/templates/theme-switcher.html +0 -86
- package/plugins/theme-switcher/admin/views/theme-switcher.js +0 -65
- package/plugins/theme-switcher/config.js +0 -10
- package/plugins/theme-switcher/plugin.js +0 -26
- package/plugins/theme-switcher/plugin.json +0 -74
- package/plugins/theme-switcher/public/inject-body.html +0 -153
- package/plugins/theme-switcher/public/inject-head.html +0 -260
- package/plugins/todo/admin/templates/todo.html +0 -158
- package/plugins/todo/admin/views/todo.js +0 -343
- package/plugins/todo/collections/todos/schema.json +0 -60
- package/plugins/todo/config.js +0 -7
- package/plugins/todo/data/todos.json +0 -1
- package/plugins/todo/plugin.js +0 -102
- package/plugins/todo/plugin.json +0 -33
|
@@ -1,710 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Contacts plugin admin view.
|
|
3
|
-
*
|
|
4
|
-
* @module contacts/admin/views/contacts
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const BASE = '/api/plugins/contacts';
|
|
8
|
-
|
|
9
|
-
async function api(url, method = 'GET', body) {
|
|
10
|
-
const opts = {method, headers: {'Authorization': 'Bearer ' + (S.get('auth_token') || '')}};
|
|
11
|
-
if (body !== undefined) {
|
|
12
|
-
opts.headers['Content-Type'] = 'application/json';
|
|
13
|
-
opts.body = JSON.stringify(body);
|
|
14
|
-
}
|
|
15
|
-
const res = await fetch(url, opts);
|
|
16
|
-
if (!res.ok) {
|
|
17
|
-
const err = await res.json().catch(() => ({error: res.statusText}));
|
|
18
|
-
throw new Error(err.error || res.statusText);
|
|
19
|
-
}
|
|
20
|
-
const text = await res.text();
|
|
21
|
-
return text ? JSON.parse(text) : {};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const contactsView = {
|
|
25
|
-
templateUrl: '/plugins/contacts/admin/templates/contacts.html',
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Mount the contacts view.
|
|
29
|
-
*
|
|
30
|
-
* @param {object} $container - Domma-wrapped container element
|
|
31
|
-
* @returns {Promise<void>}
|
|
32
|
-
*/
|
|
33
|
-
async onMount($container) {
|
|
34
|
-
// ---------------------------------------------------------------
|
|
35
|
-
// State
|
|
36
|
-
// ---------------------------------------------------------------
|
|
37
|
-
let allContacts = [];
|
|
38
|
-
let groups = [];
|
|
39
|
-
let currentEditId = null;
|
|
40
|
-
let selectedGroups = [];
|
|
41
|
-
let showFavsOnly = false;
|
|
42
|
-
let currentGroupFilter = '';
|
|
43
|
-
let contactsTable = null;
|
|
44
|
-
let selectedIds = new Set();
|
|
45
|
-
|
|
46
|
-
// ---------------------------------------------------------------
|
|
47
|
-
// Helpers
|
|
48
|
-
// ---------------------------------------------------------------
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Escape HTML special characters to prevent XSS.
|
|
52
|
-
*
|
|
53
|
-
* @param {string} str
|
|
54
|
-
* @returns {string}
|
|
55
|
-
*/
|
|
56
|
-
function esc(str) {
|
|
57
|
-
return String(str ?? '')
|
|
58
|
-
.replace(/&/g, '&')
|
|
59
|
-
.replace(/</g, '<')
|
|
60
|
-
.replace(/>/g, '>')
|
|
61
|
-
.replace(/"/g, '"');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// ---------------------------------------------------------------
|
|
65
|
-
// Data loading
|
|
66
|
-
// ---------------------------------------------------------------
|
|
67
|
-
|
|
68
|
-
async function loadGroups() {
|
|
69
|
-
try {
|
|
70
|
-
groups = await api(`${BASE}/groups`);
|
|
71
|
-
} catch {
|
|
72
|
-
groups = [];
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async function loadContacts() {
|
|
77
|
-
try {
|
|
78
|
-
const params = new URLSearchParams();
|
|
79
|
-
if (currentGroupFilter) params.set('group', currentGroupFilter);
|
|
80
|
-
if (showFavsOnly) params.set('favourites', 'true');
|
|
81
|
-
const qs = params.toString();
|
|
82
|
-
allContacts = await api(`${BASE}/contacts${qs ? '?' + qs : ''}`);
|
|
83
|
-
} catch {
|
|
84
|
-
allContacts = [];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// ---------------------------------------------------------------
|
|
89
|
-
// Stats
|
|
90
|
-
// ---------------------------------------------------------------
|
|
91
|
-
|
|
92
|
-
function updateStats() {
|
|
93
|
-
const totalEl = $container.find('#stat-total').get(0);
|
|
94
|
-
const groupsEl = $container.find('#stat-groups').get(0);
|
|
95
|
-
const favsEl = $container.find('#stat-favs').get(0);
|
|
96
|
-
if (totalEl) totalEl.textContent = allContacts.length;
|
|
97
|
-
if (groupsEl) groupsEl.textContent = groups.length;
|
|
98
|
-
if (favsEl) favsEl.textContent = allContacts.filter((c) => c.favourite).length;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// ---------------------------------------------------------------
|
|
102
|
-
// Group filter dropdown (select)
|
|
103
|
-
// ---------------------------------------------------------------
|
|
104
|
-
|
|
105
|
-
function populateGroupFilter() {
|
|
106
|
-
const sel = $container.find('#group-filter').get(0);
|
|
107
|
-
if (!sel) return;
|
|
108
|
-
const current = sel.value;
|
|
109
|
-
while (sel.options.length > 1) sel.remove(1);
|
|
110
|
-
groups.forEach((g) => {
|
|
111
|
-
const opt = document.createElement('option');
|
|
112
|
-
opt.value = g;
|
|
113
|
-
opt.textContent = g;
|
|
114
|
-
if (g === current) opt.selected = true;
|
|
115
|
-
sel.appendChild(opt);
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// ---------------------------------------------------------------
|
|
120
|
-
// Table
|
|
121
|
-
// ---------------------------------------------------------------
|
|
122
|
-
|
|
123
|
-
function buildTable() {
|
|
124
|
-
const tableEl = $container.find('#contacts-table').get(0);
|
|
125
|
-
const emptyEl = $container.find('#contacts-empty').get(0);
|
|
126
|
-
|
|
127
|
-
if (!allContacts.length) {
|
|
128
|
-
if (tableEl) tableEl.style.display = 'none';
|
|
129
|
-
if (emptyEl) emptyEl.style.display = 'block';
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (emptyEl) emptyEl.style.display = 'none';
|
|
134
|
-
if (tableEl) tableEl.style.display = '';
|
|
135
|
-
|
|
136
|
-
if (contactsTable) {
|
|
137
|
-
contactsTable.setData(allContacts);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Render functions return HTML strings - values are escaped via esc()
|
|
142
|
-
// T.create passes these through Domma's DOMPurify sanitiser
|
|
143
|
-
contactsTable = T.create('#contacts-table', {
|
|
144
|
-
data: allContacts,
|
|
145
|
-
selectable: true,
|
|
146
|
-
columns: [
|
|
147
|
-
{
|
|
148
|
-
key: 'name',
|
|
149
|
-
title: 'Name',
|
|
150
|
-
sortable: true,
|
|
151
|
-
render: (v) => `<strong>${esc(v)}</strong>`
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
key: 'email',
|
|
155
|
-
title: 'Email',
|
|
156
|
-
sortable: true,
|
|
157
|
-
render: (v) => v ? `<a href="mailto:${esc(v)}">${esc(v)}</a>` : '-'
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
key: 'phone',
|
|
161
|
-
title: 'Phone',
|
|
162
|
-
sortable: false,
|
|
163
|
-
render: (v) => esc(v) || '-'
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
key: 'groups',
|
|
167
|
-
title: 'Groups',
|
|
168
|
-
sortable: false,
|
|
169
|
-
render: (v) => {
|
|
170
|
-
if (!Array.isArray(v) || v.length === 0) return '-';
|
|
171
|
-
return v.map((g) => `<span class="badge badge-primary" style="margin-right:2px;">${esc(g)}</span>`).join('');
|
|
172
|
-
}
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
key: 'favourite',
|
|
176
|
-
title: '',
|
|
177
|
-
sortable: false,
|
|
178
|
-
render: (v) => v
|
|
179
|
-
? '<span data-icon="star" style="color:var(--dm-warning);"></span>'
|
|
180
|
-
: '<span data-icon="star" style="opacity:0.2;"></span>'
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
key: 'id',
|
|
184
|
-
title: 'Actions',
|
|
185
|
-
sortable: false,
|
|
186
|
-
render: (id) =>
|
|
187
|
-
`<button class="btn btn-sm btn-outline contact-edit-btn" data-id="${esc(id)}" style="margin-right:4px;">` +
|
|
188
|
-
`<span data-icon="edit" data-icon-size="14"></span> Edit</button>` +
|
|
189
|
-
`<button class="btn btn-sm btn-danger contact-delete-btn" data-id="${esc(id)}">` +
|
|
190
|
-
`<span data-icon="trash" data-icon-size="14"></span> Delete</button>`
|
|
191
|
-
}
|
|
192
|
-
],
|
|
193
|
-
emptyMessage: 'No contacts match your filters.'
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
// Selection change handler
|
|
197
|
-
if (contactsTable && typeof contactsTable.on === 'function') {
|
|
198
|
-
contactsTable.on('selectionChange', (rows) => {
|
|
199
|
-
selectedIds = new Set(rows.map((r) => r.id));
|
|
200
|
-
const bulkEl = $container.find('#bulk-actions').get(0);
|
|
201
|
-
const countEl = $container.find('#selected-count').get(0);
|
|
202
|
-
if (bulkEl) bulkEl.style.display = selectedIds.size > 0 ? 'inline-flex' : 'none';
|
|
203
|
-
if (countEl) countEl.textContent = selectedIds.size;
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Event delegation on table container - avoids namespaced delegation issues
|
|
208
|
-
const tableContainer = $container.find('#contacts-table').get(0);
|
|
209
|
-
if (tableContainer) {
|
|
210
|
-
tableContainer.addEventListener('click', async (e) => {
|
|
211
|
-
const editBtn = e.target.closest('.contact-edit-btn');
|
|
212
|
-
const deleteBtn = e.target.closest('.contact-delete-btn');
|
|
213
|
-
|
|
214
|
-
if (editBtn) {
|
|
215
|
-
openEditor(editBtn.dataset.id);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (deleteBtn) {
|
|
219
|
-
const id = deleteBtn.dataset.id;
|
|
220
|
-
const contact = allContacts.find((c) => c.id === id);
|
|
221
|
-
if (!contact) return;
|
|
222
|
-
const ok = await E.confirm(`Delete "${contact.name}"?`);
|
|
223
|
-
if (!ok) return;
|
|
224
|
-
try {
|
|
225
|
-
await api(`${BASE}/contacts/${id}`, 'DELETE');
|
|
226
|
-
E.toast('Contact deleted.', { type: 'success' });
|
|
227
|
-
await refresh();
|
|
228
|
-
} catch {
|
|
229
|
-
E.toast('Failed to delete contact.', { type: 'error' });
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
Domma.icons.scan();
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// ---------------------------------------------------------------
|
|
239
|
-
// Editor
|
|
240
|
-
// ---------------------------------------------------------------
|
|
241
|
-
|
|
242
|
-
function openEditor(id) {
|
|
243
|
-
currentEditId = id ?? null;
|
|
244
|
-
selectedGroups = [];
|
|
245
|
-
|
|
246
|
-
const editorEl = $container.find('#contact-editor').get(0);
|
|
247
|
-
if (!editorEl) return;
|
|
248
|
-
|
|
249
|
-
const titleEl = $container.find('#editor-title').get(0);
|
|
250
|
-
const saveLbl = $container.find('#editor-save-label').get(0);
|
|
251
|
-
const deleteBtn = $container.find('#editor-delete-btn').get(0);
|
|
252
|
-
|
|
253
|
-
if (id) {
|
|
254
|
-
const c = allContacts.find((x) => x.id === id);
|
|
255
|
-
if (!c) return;
|
|
256
|
-
if (titleEl) titleEl.textContent = 'Edit Contact';
|
|
257
|
-
if (saveLbl) saveLbl.textContent = 'Update Contact';
|
|
258
|
-
if (deleteBtn) deleteBtn.style.display = 'inline-flex';
|
|
259
|
-
|
|
260
|
-
const nameEl = $container.find('#contact-name').get(0);
|
|
261
|
-
const emailEl = $container.find('#contact-email').get(0);
|
|
262
|
-
const phoneEl = $container.find('#contact-phone').get(0);
|
|
263
|
-
const notesEl = $container.find('#contact-notes').get(0);
|
|
264
|
-
const favEl = $container.find('#contact-favourite').get(0);
|
|
265
|
-
|
|
266
|
-
if (nameEl) nameEl.value = c.name ?? '';
|
|
267
|
-
if (emailEl) emailEl.value = c.email ?? '';
|
|
268
|
-
if (phoneEl) phoneEl.value = c.phone ?? '';
|
|
269
|
-
if (notesEl) notesEl.value = c.notes ?? '';
|
|
270
|
-
if (favEl) favEl.checked = c.favourite === true;
|
|
271
|
-
selectedGroups = Array.isArray(c.groups) ? [...c.groups] : [];
|
|
272
|
-
} else {
|
|
273
|
-
if (titleEl) titleEl.textContent = 'Add Contact';
|
|
274
|
-
if (saveLbl) saveLbl.textContent = 'Save Contact';
|
|
275
|
-
if (deleteBtn) deleteBtn.style.display = 'none';
|
|
276
|
-
|
|
277
|
-
const fields = ['#contact-name', '#contact-email', '#contact-phone'];
|
|
278
|
-
fields.forEach((sel) => {
|
|
279
|
-
const el = $container.find(sel).get(0);
|
|
280
|
-
if (el) el.value = '';
|
|
281
|
-
});
|
|
282
|
-
const notesEl = $container.find('#contact-notes').get(0);
|
|
283
|
-
const favEl = $container.find('#contact-favourite').get(0);
|
|
284
|
-
if (notesEl) notesEl.value = '';
|
|
285
|
-
if (favEl) favEl.checked = false;
|
|
286
|
-
selectedGroups = [];
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
updateGroupsDisplay();
|
|
290
|
-
editorEl.style.display = '';
|
|
291
|
-
editorEl.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
function closeEditor() {
|
|
295
|
-
const editorEl = $container.find('#contact-editor').get(0);
|
|
296
|
-
if (editorEl) editorEl.style.display = 'none';
|
|
297
|
-
currentEditId = null;
|
|
298
|
-
selectedGroups = [];
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Render selected group tags inside the groups display area using DOM APIs.
|
|
303
|
-
*/
|
|
304
|
-
function updateGroupsDisplay() {
|
|
305
|
-
const display = $container.find('#contact-groups-display').get(0);
|
|
306
|
-
const placeholder = $container.find('#groups-placeholder').get(0);
|
|
307
|
-
if (!display) return;
|
|
308
|
-
|
|
309
|
-
// Remove existing tag badges
|
|
310
|
-
Array.from(display.querySelectorAll('.group-tag-badge')).forEach((el) => el.remove());
|
|
311
|
-
|
|
312
|
-
if (selectedGroups.length === 0) {
|
|
313
|
-
if (placeholder) placeholder.style.display = '';
|
|
314
|
-
} else {
|
|
315
|
-
if (placeholder) placeholder.style.display = 'none';
|
|
316
|
-
selectedGroups.forEach((g) => {
|
|
317
|
-
const span = document.createElement('span');
|
|
318
|
-
span.className = 'badge badge-primary group-tag-badge';
|
|
319
|
-
span.style.marginRight = '2px';
|
|
320
|
-
span.textContent = g; // textContent - safe, no XSS
|
|
321
|
-
display.appendChild(span);
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
async function saveContact() {
|
|
327
|
-
const nameEl = $container.find('#contact-name').get(0);
|
|
328
|
-
const name = (nameEl?.value ?? '').trim();
|
|
329
|
-
if (!name) {
|
|
330
|
-
E.toast('Name is required.', { type: 'error' });
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
const body = {
|
|
335
|
-
name,
|
|
336
|
-
email: ($container.find('#contact-email').get(0)?.value ?? '').trim(),
|
|
337
|
-
phone: ($container.find('#contact-phone').get(0)?.value ?? '').trim(),
|
|
338
|
-
notes: ($container.find('#contact-notes').get(0)?.value ?? '').trim(),
|
|
339
|
-
favourite: $container.find('#contact-favourite').get(0)?.checked === true,
|
|
340
|
-
groups: selectedGroups
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
try {
|
|
344
|
-
if (currentEditId) {
|
|
345
|
-
await api(`${BASE}/contacts/${currentEditId}`, 'PUT', body);
|
|
346
|
-
E.toast('Contact updated.', { type: 'success' });
|
|
347
|
-
} else {
|
|
348
|
-
await api(`${BASE}/contacts`, 'POST', body);
|
|
349
|
-
E.toast('Contact created.', { type: 'success' });
|
|
350
|
-
}
|
|
351
|
-
closeEditor();
|
|
352
|
-
await refresh();
|
|
353
|
-
} catch {
|
|
354
|
-
E.toast('Failed to save contact.', { type: 'error' });
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
// ---------------------------------------------------------------
|
|
359
|
-
// Groups panel
|
|
360
|
-
// ---------------------------------------------------------------
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* Render the groups management list using DOM APIs (no innerHTML for interactive elements).
|
|
364
|
-
*/
|
|
365
|
-
function renderGroupsList() {
|
|
366
|
-
const listEl = $container.find('#groups-list').get(0);
|
|
367
|
-
if (!listEl) return;
|
|
368
|
-
|
|
369
|
-
// Clear existing content safely
|
|
370
|
-
while (listEl.firstChild) listEl.removeChild(listEl.firstChild);
|
|
371
|
-
|
|
372
|
-
if (groups.length === 0) {
|
|
373
|
-
const p = document.createElement('p');
|
|
374
|
-
p.className = 'text-muted';
|
|
375
|
-
p.textContent = 'No groups yet. Add one above.';
|
|
376
|
-
listEl.appendChild(p);
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
groups.forEach((group) => {
|
|
381
|
-
const row = document.createElement('div');
|
|
382
|
-
row.style.cssText = 'display:flex;justify-content:space-between;align-items:center;' +
|
|
383
|
-
'padding:0.6rem 0.75rem;border:1px solid var(--dm-border);' +
|
|
384
|
-
'border-radius:var(--dm-radius);margin-bottom:0.4rem;';
|
|
385
|
-
|
|
386
|
-
const label = document.createElement('span');
|
|
387
|
-
label.className = 'badge badge-primary';
|
|
388
|
-
label.textContent = group; // textContent - safe
|
|
389
|
-
row.appendChild(label);
|
|
390
|
-
|
|
391
|
-
const actions = document.createElement('div');
|
|
392
|
-
actions.style.display = 'flex';
|
|
393
|
-
actions.style.gap = '0.4rem';
|
|
394
|
-
|
|
395
|
-
const editBtn = document.createElement('button');
|
|
396
|
-
editBtn.className = 'btn btn-sm btn-outline';
|
|
397
|
-
editBtn.textContent = ' Edit';
|
|
398
|
-
const editIcon = document.createElement('span');
|
|
399
|
-
editIcon.setAttribute('data-icon', 'edit');
|
|
400
|
-
editIcon.setAttribute('data-icon-size', '14');
|
|
401
|
-
editBtn.prepend(editIcon);
|
|
402
|
-
editBtn.addEventListener('click', async () => {
|
|
403
|
-
const newName = await E.prompt(`Rename group "${group}":`, { inputValue: group });
|
|
404
|
-
if (!newName || newName.trim() === group) return;
|
|
405
|
-
try {
|
|
406
|
-
await api(`${BASE}/groups/${encodeURIComponent(group)}`, 'PUT', {newName: newName.trim()});
|
|
407
|
-
E.toast('Group renamed.', { type: 'success' });
|
|
408
|
-
await refresh();
|
|
409
|
-
} catch (err) {
|
|
410
|
-
E.toast(err?.message ?? 'Failed to rename group.', { type: 'error' });
|
|
411
|
-
}
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
const delBtn = document.createElement('button');
|
|
415
|
-
delBtn.className = 'btn btn-sm btn-danger';
|
|
416
|
-
delBtn.textContent = ' Delete';
|
|
417
|
-
const delIcon = document.createElement('span');
|
|
418
|
-
delIcon.setAttribute('data-icon', 'trash');
|
|
419
|
-
delIcon.setAttribute('data-icon-size', '14');
|
|
420
|
-
delBtn.prepend(delIcon);
|
|
421
|
-
delBtn.addEventListener('click', async () => {
|
|
422
|
-
const ok = await E.confirm(`Delete group "${group}"? It will be removed from all contacts.`);
|
|
423
|
-
if (!ok) return;
|
|
424
|
-
try {
|
|
425
|
-
await api(`${BASE}/groups/${encodeURIComponent(group)}`, 'DELETE');
|
|
426
|
-
E.toast('Group deleted.', { type: 'success' });
|
|
427
|
-
await refresh();
|
|
428
|
-
} catch {
|
|
429
|
-
E.toast('Failed to delete group.', { type: 'error' });
|
|
430
|
-
}
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
actions.appendChild(editBtn);
|
|
434
|
-
actions.appendChild(delBtn);
|
|
435
|
-
row.appendChild(actions);
|
|
436
|
-
listEl.appendChild(row);
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
Domma.icons.scan();
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
// ---------------------------------------------------------------
|
|
443
|
-
// Groups dropdown inside the editor (inline custom dropdown)
|
|
444
|
-
// ---------------------------------------------------------------
|
|
445
|
-
|
|
446
|
-
function renderGroupsDropdown() {
|
|
447
|
-
const itemsEl = $container.find('#groups-dropdown-items').get(0);
|
|
448
|
-
if (!itemsEl) return;
|
|
449
|
-
while (itemsEl.firstChild) itemsEl.removeChild(itemsEl.firstChild);
|
|
450
|
-
groups.forEach((g) => {
|
|
451
|
-
const item = document.createElement('div');
|
|
452
|
-
item.style.cssText = 'padding:0.4rem 0.6rem;cursor:pointer;border-radius:var(--dm-radius);';
|
|
453
|
-
if (selectedGroups.includes(g)) {
|
|
454
|
-
item.style.background = 'var(--dm-primary-light, rgba(99,102,241,0.1))';
|
|
455
|
-
item.style.fontWeight = '600';
|
|
456
|
-
}
|
|
457
|
-
item.textContent = g; // textContent - safe
|
|
458
|
-
item.addEventListener('click', () => {
|
|
459
|
-
const idx = selectedGroups.indexOf(g);
|
|
460
|
-
if (idx === -1) {
|
|
461
|
-
selectedGroups.push(g);
|
|
462
|
-
} else {
|
|
463
|
-
selectedGroups.splice(idx, 1);
|
|
464
|
-
}
|
|
465
|
-
updateGroupsDisplay();
|
|
466
|
-
renderGroupsDropdown();
|
|
467
|
-
});
|
|
468
|
-
itemsEl.appendChild(item);
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
// ---------------------------------------------------------------
|
|
473
|
-
// Client-side search filter
|
|
474
|
-
// ---------------------------------------------------------------
|
|
475
|
-
|
|
476
|
-
function applySearch(query) {
|
|
477
|
-
if (!contactsTable) return;
|
|
478
|
-
if (!query) {
|
|
479
|
-
contactsTable.setData(allContacts);
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
const q = query.toLowerCase();
|
|
483
|
-
const filtered = allContacts.filter((c) =>
|
|
484
|
-
(c.name && c.name.toLowerCase().includes(q)) ||
|
|
485
|
-
(c.email && c.email.toLowerCase().includes(q)) ||
|
|
486
|
-
(c.phone && c.phone.includes(q))
|
|
487
|
-
);
|
|
488
|
-
contactsTable.setData(filtered);
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
// ---------------------------------------------------------------
|
|
492
|
-
// Import / Export
|
|
493
|
-
// ---------------------------------------------------------------
|
|
494
|
-
|
|
495
|
-
async function exportContacts() {
|
|
496
|
-
try {
|
|
497
|
-
const data = await api(`${BASE}/export`);
|
|
498
|
-
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
|
|
499
|
-
const url = URL.createObjectURL(blob);
|
|
500
|
-
const a = document.createElement('a');
|
|
501
|
-
a.href = url;
|
|
502
|
-
a.download = 'contacts.json';
|
|
503
|
-
document.body.appendChild(a);
|
|
504
|
-
a.click();
|
|
505
|
-
document.body.removeChild(a);
|
|
506
|
-
URL.revokeObjectURL(url);
|
|
507
|
-
E.toast('Contacts exported.', { type: 'success' });
|
|
508
|
-
} catch {
|
|
509
|
-
E.toast('Export failed.', { type: 'error' });
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
async function importContacts(file) {
|
|
514
|
-
try {
|
|
515
|
-
const text = await file.text();
|
|
516
|
-
const parsed = JSON.parse(text);
|
|
517
|
-
const contacts = Array.isArray(parsed) ? parsed : parsed.contacts;
|
|
518
|
-
if (!Array.isArray(contacts)) throw new Error('Invalid format');
|
|
519
|
-
const result = await api(`${BASE}/import`, 'POST', {contacts});
|
|
520
|
-
E.toast(`Imported ${result.imported} contact(s).`, { type: 'success' });
|
|
521
|
-
await refresh();
|
|
522
|
-
} catch {
|
|
523
|
-
E.toast('Import failed. Ensure the file is valid JSON.', { type: 'error' });
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
// ---------------------------------------------------------------
|
|
528
|
-
// Bulk delete
|
|
529
|
-
// ---------------------------------------------------------------
|
|
530
|
-
|
|
531
|
-
async function bulkDelete() {
|
|
532
|
-
if (selectedIds.size === 0) return;
|
|
533
|
-
const ok = await E.confirm(`Delete ${selectedIds.size} selected contact(s)?`);
|
|
534
|
-
if (!ok) return;
|
|
535
|
-
try {
|
|
536
|
-
await api(`${BASE}/contacts/bulk`, 'DELETE', {ids: [...selectedIds]});
|
|
537
|
-
E.toast(`${selectedIds.size} contact(s) deleted.`, { type: 'success' });
|
|
538
|
-
selectedIds.clear();
|
|
539
|
-
await refresh();
|
|
540
|
-
} catch {
|
|
541
|
-
E.toast('Bulk delete failed.', { type: 'error' });
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
// ---------------------------------------------------------------
|
|
546
|
-
// Full refresh
|
|
547
|
-
// ---------------------------------------------------------------
|
|
548
|
-
|
|
549
|
-
async function refresh() {
|
|
550
|
-
await Promise.all([loadGroups(), loadContacts()]);
|
|
551
|
-
updateStats();
|
|
552
|
-
populateGroupFilter();
|
|
553
|
-
renderGroupsList();
|
|
554
|
-
buildTable();
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
// ---------------------------------------------------------------
|
|
558
|
-
// Wire up events
|
|
559
|
-
// ---------------------------------------------------------------
|
|
560
|
-
|
|
561
|
-
// Add contact button
|
|
562
|
-
const addBtn = $container.find('#add-contact-btn').get(0);
|
|
563
|
-
if (addBtn) addBtn.addEventListener('click', () => openEditor(null));
|
|
564
|
-
|
|
565
|
-
// Editor save
|
|
566
|
-
const editorSaveBtn = $container.find('#editor-save-btn').get(0);
|
|
567
|
-
if (editorSaveBtn) editorSaveBtn.addEventListener('click', saveContact);
|
|
568
|
-
|
|
569
|
-
// Editor cancel (two cancel buttons)
|
|
570
|
-
[$container.find('#editor-cancel-btn').get(0), $container.find('#editor-cancel-btn2').get(0)]
|
|
571
|
-
.filter(Boolean)
|
|
572
|
-
.forEach((btn) => btn.addEventListener('click', closeEditor));
|
|
573
|
-
|
|
574
|
-
// Editor delete
|
|
575
|
-
const editorDeleteBtn = $container.find('#editor-delete-btn').get(0);
|
|
576
|
-
if (editorDeleteBtn) {
|
|
577
|
-
editorDeleteBtn.addEventListener('click', async () => {
|
|
578
|
-
if (!currentEditId) return;
|
|
579
|
-
const contact = allContacts.find((c) => c.id === currentEditId);
|
|
580
|
-
const ok = await E.confirm(`Delete "${contact?.name ?? 'this contact'}"?`);
|
|
581
|
-
if (!ok) return;
|
|
582
|
-
try {
|
|
583
|
-
await api(`${BASE}/contacts/${currentEditId}`, 'DELETE');
|
|
584
|
-
E.toast('Contact deleted.', { type: 'success' });
|
|
585
|
-
closeEditor();
|
|
586
|
-
await refresh();
|
|
587
|
-
} catch {
|
|
588
|
-
E.toast('Failed to delete contact.', { type: 'error' });
|
|
589
|
-
}
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
// Favourites toggle
|
|
594
|
-
const favToggle = $container.find('#fav-toggle').get(0);
|
|
595
|
-
if (favToggle) {
|
|
596
|
-
favToggle.addEventListener('click', async () => {
|
|
597
|
-
showFavsOnly = !showFavsOnly;
|
|
598
|
-
favToggle.classList.toggle('btn-warning', showFavsOnly);
|
|
599
|
-
favToggle.classList.toggle('btn-outline', !showFavsOnly);
|
|
600
|
-
await loadContacts();
|
|
601
|
-
updateStats();
|
|
602
|
-
buildTable();
|
|
603
|
-
});
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
// Group filter
|
|
607
|
-
const groupFilterSel = $container.find('#group-filter').get(0);
|
|
608
|
-
if (groupFilterSel) {
|
|
609
|
-
groupFilterSel.addEventListener('change', async () => {
|
|
610
|
-
currentGroupFilter = groupFilterSel.value;
|
|
611
|
-
await loadContacts();
|
|
612
|
-
updateStats();
|
|
613
|
-
buildTable();
|
|
614
|
-
});
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
// Search
|
|
618
|
-
const searchInput = $container.find('#contacts-search').get(0);
|
|
619
|
-
if (searchInput) {
|
|
620
|
-
let searchTimer = null;
|
|
621
|
-
searchInput.addEventListener('input', () => {
|
|
622
|
-
clearTimeout(searchTimer);
|
|
623
|
-
searchTimer = setTimeout(() => applySearch(searchInput.value.trim()), 250);
|
|
624
|
-
});
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
// Export
|
|
628
|
-
const exportBtn = $container.find('#export-btn').get(0);
|
|
629
|
-
if (exportBtn) exportBtn.addEventListener('click', exportContacts);
|
|
630
|
-
|
|
631
|
-
// Import
|
|
632
|
-
const importBtn = $container.find('#import-btn').get(0);
|
|
633
|
-
const importFile = $container.find('#import-file').get(0);
|
|
634
|
-
if (importBtn && importFile) {
|
|
635
|
-
importBtn.addEventListener('click', () => importFile.click());
|
|
636
|
-
importFile.addEventListener('change', async () => {
|
|
637
|
-
const file = importFile.files?.[0];
|
|
638
|
-
if (file) {
|
|
639
|
-
await importContacts(file);
|
|
640
|
-
importFile.value = '';
|
|
641
|
-
}
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
// Bulk delete
|
|
646
|
-
const bulkDeleteBtn = $container.find('#bulk-delete-btn').get(0);
|
|
647
|
-
if (bulkDeleteBtn) bulkDeleteBtn.addEventListener('click', bulkDelete);
|
|
648
|
-
|
|
649
|
-
// Add group
|
|
650
|
-
const addGroupBtn = $container.find('#add-group-btn').get(0);
|
|
651
|
-
const newGroupInput = $container.find('#new-group-input').get(0);
|
|
652
|
-
if (addGroupBtn) {
|
|
653
|
-
addGroupBtn.addEventListener('click', async () => {
|
|
654
|
-
const name = newGroupInput?.value?.trim();
|
|
655
|
-
if (!name) return;
|
|
656
|
-
try {
|
|
657
|
-
await api(`${BASE}/groups`, 'POST', {name});
|
|
658
|
-
if (newGroupInput) newGroupInput.value = '';
|
|
659
|
-
E.toast('Group added.', { type: 'success' });
|
|
660
|
-
await refresh();
|
|
661
|
-
} catch (err) {
|
|
662
|
-
E.toast(err?.message ?? 'Failed to add group.', { type: 'error' });
|
|
663
|
-
}
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
if (newGroupInput) {
|
|
668
|
-
newGroupInput.addEventListener('keydown', (e) => {
|
|
669
|
-
if (e.key === 'Enter') addGroupBtn?.click();
|
|
670
|
-
});
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
// Groups panel collapse toggle
|
|
674
|
-
const panelToggle = $container.find('#groups-panel-toggle').get(0);
|
|
675
|
-
const panelBody = $container.find('#groups-panel-body').get(0);
|
|
676
|
-
const chevron = $container.find('#groups-chevron').get(0);
|
|
677
|
-
if (panelToggle && panelBody) {
|
|
678
|
-
panelToggle.addEventListener('click', () => {
|
|
679
|
-
const open = panelBody.style.display !== 'none';
|
|
680
|
-
panelBody.style.display = open ? 'none' : '';
|
|
681
|
-
if (chevron) chevron.setAttribute('data-icon', open ? 'chevron-down' : 'chevron-up');
|
|
682
|
-
Domma.icons.scan();
|
|
683
|
-
});
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
// Groups picker toggle inside editor
|
|
687
|
-
const groupsDisplay = $container.find('#contact-groups-display').get(0);
|
|
688
|
-
const groupsDropdownList = $container.find('#groups-dropdown-list').get(0);
|
|
689
|
-
if (groupsDisplay && groupsDropdownList) {
|
|
690
|
-
groupsDisplay.addEventListener('click', (e) => {
|
|
691
|
-
e.stopPropagation();
|
|
692
|
-
const open = groupsDropdownList.style.display !== 'none';
|
|
693
|
-
if (!open) renderGroupsDropdown();
|
|
694
|
-
groupsDropdownList.style.display = open ? 'none' : '';
|
|
695
|
-
});
|
|
696
|
-
|
|
697
|
-
document.addEventListener('click', (e) => {
|
|
698
|
-
if (!groupsDisplay.contains(e.target) && !groupsDropdownList.contains(e.target)) {
|
|
699
|
-
groupsDropdownList.style.display = 'none';
|
|
700
|
-
}
|
|
701
|
-
});
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
// ---------------------------------------------------------------
|
|
705
|
-
// Initial load
|
|
706
|
-
// ---------------------------------------------------------------
|
|
707
|
-
await refresh();
|
|
708
|
-
Domma.icons.scan();
|
|
709
|
-
}
|
|
710
|
-
};
|