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,43 +0,0 @@
|
|
|
1
|
-
<div class="view-header d-flex align-items-center justify-content-between mb-4">
|
|
2
|
-
<h1 class="h3 mb-0"><span data-icon="file-text"></span> Invoices</h1>
|
|
3
|
-
<button id="btn-new-invoice" class="btn btn-primary">
|
|
4
|
-
<span data-icon="plus"></span> New Invoice
|
|
5
|
-
</button>
|
|
6
|
-
</div>
|
|
7
|
-
|
|
8
|
-
<div class="grid grid-cols-4 gap-3 mb-4">
|
|
9
|
-
<div class="card"><div class="card-body">
|
|
10
|
-
<div class="text-muted small">Total invoices</div>
|
|
11
|
-
<div class="h3 mb-0" id="kpi-total">-</div>
|
|
12
|
-
</div></div>
|
|
13
|
-
<div class="card"><div class="card-body">
|
|
14
|
-
<div class="text-muted small">Outstanding</div>
|
|
15
|
-
<div class="h3 mb-0" id="kpi-outstanding">-</div>
|
|
16
|
-
</div></div>
|
|
17
|
-
<div class="card"><div class="card-body">
|
|
18
|
-
<div class="text-muted small">Paid</div>
|
|
19
|
-
<div class="h3 mb-0" id="kpi-paid">-</div>
|
|
20
|
-
</div></div>
|
|
21
|
-
<div class="card"><div class="card-body">
|
|
22
|
-
<div class="text-muted small">Drafts</div>
|
|
23
|
-
<div class="h3 mb-0" id="kpi-drafts">-</div>
|
|
24
|
-
</div></div>
|
|
25
|
-
</div>
|
|
26
|
-
|
|
27
|
-
<div class="card mb-3">
|
|
28
|
-
<div class="card-body">
|
|
29
|
-
<div class="d-flex gap-2 flex-wrap">
|
|
30
|
-
<select id="filter-status" class="form-select" style="width:auto;">
|
|
31
|
-
<option value="">All statuses</option>
|
|
32
|
-
<option value="draft">Draft</option>
|
|
33
|
-
<option value="sent">Sent</option>
|
|
34
|
-
<option value="paid">Paid</option>
|
|
35
|
-
<option value="overdue">Overdue</option>
|
|
36
|
-
<option value="cancelled">Cancelled</option>
|
|
37
|
-
</select>
|
|
38
|
-
<input id="filter-search" type="search" class="form-control" style="width:240px;" placeholder="Search number or receiver…">
|
|
39
|
-
</div>
|
|
40
|
-
</div>
|
|
41
|
-
</div>
|
|
42
|
-
|
|
43
|
-
<div id="invoices-table"></div>
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
<div class="view-header d-flex align-items-center justify-content-between mb-4">
|
|
2
|
-
<h1 class="h3 mb-0"><span data-icon="briefcase"></span> Issuers</h1>
|
|
3
|
-
<button id="btn-new" class="btn btn-primary"><span data-icon="plus"></span> New Issuer</button>
|
|
4
|
-
</div>
|
|
5
|
-
<div id="party-table"></div>
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
<div class="view-header d-flex align-items-center justify-content-between mb-4">
|
|
2
|
-
<h1 class="h3 mb-0"><span data-icon="users"></span> Receivers</h1>
|
|
3
|
-
<button id="btn-new" class="btn btn-primary"><span data-icon="plus"></span> New Receiver</button>
|
|
4
|
-
</div>
|
|
5
|
-
<div id="party-table"></div>
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Invoice plugin - editor view. Create or edit a single invoice.
|
|
3
|
-
*/
|
|
4
|
-
function escapeHtml(s) {
|
|
5
|
-
return String(s ?? '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function fmt(amount, currency) {
|
|
9
|
-
try {
|
|
10
|
-
return new Intl.NumberFormat('en-GB', { style: 'currency', currency: currency || 'GBP' }).format(Number(amount) || 0);
|
|
11
|
-
} catch {
|
|
12
|
-
return `${currency || 'GBP'} ${Number(amount).toFixed(2)}`;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function round2(n) {
|
|
17
|
-
return Math.round((Number(n) + Number.EPSILON) * 100) / 100;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const BASE = '/api/plugins/invoice';
|
|
21
|
-
|
|
22
|
-
export const editorView = {
|
|
23
|
-
templateUrl: '/plugins/invoice/admin/templates/editor.html',
|
|
24
|
-
|
|
25
|
-
async onMount($container) {
|
|
26
|
-
const id = R.current?.params?.id ?? null;
|
|
27
|
-
const isEdit = Boolean(id);
|
|
28
|
-
let invoice = null;
|
|
29
|
-
let issuers = [];
|
|
30
|
-
let receivers = [];
|
|
31
|
-
let lineItems = [];
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
const [issRes, recRes] = await Promise.all([
|
|
35
|
-
H.get(`${BASE}/issuers`),
|
|
36
|
-
H.get(`${BASE}/receivers`)
|
|
37
|
-
]);
|
|
38
|
-
issuers = issRes.data ?? issRes ?? [];
|
|
39
|
-
receivers = recRes.data ?? recRes ?? [];
|
|
40
|
-
} catch {
|
|
41
|
-
E.toast('Could not load issuers / receivers.', { type: 'error' });
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (isEdit) {
|
|
45
|
-
try {
|
|
46
|
-
const res = await H.get(`${BASE}/invoices/${id}`);
|
|
47
|
-
invoice = res.data ?? res;
|
|
48
|
-
lineItems = Array.isArray(invoice.lineItems) ? [...invoice.lineItems] : [];
|
|
49
|
-
} catch {
|
|
50
|
-
E.toast('Invoice not found.', { type: 'error' });
|
|
51
|
-
R.navigate('#/plugins/invoice');
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const $title = $container.find('#editor-title');
|
|
57
|
-
const $number = $container.find('#f-number');
|
|
58
|
-
const $status = $container.find('#f-status');
|
|
59
|
-
const $issueDate = $container.find('#f-issue-date');
|
|
60
|
-
const $dueDate = $container.find('#f-due-date');
|
|
61
|
-
const $issuer = $container.find('#f-issuer');
|
|
62
|
-
const $receiver = $container.find('#f-receiver');
|
|
63
|
-
const $vatEnabled = $container.find('#f-vat-enabled');
|
|
64
|
-
const $vatRate = $container.find('#f-vat-rate');
|
|
65
|
-
const $currency = $container.find('#f-currency');
|
|
66
|
-
const $notes = $container.find('#f-notes');
|
|
67
|
-
const $print = $container.find('#btn-print');
|
|
68
|
-
const $body = $container.find('#line-items-body');
|
|
69
|
-
const $vatRow = $container.find('#vat-row');
|
|
70
|
-
const $tSubtotal = $container.find('#t-subtotal');
|
|
71
|
-
const $tVat = $container.find('#t-vat');
|
|
72
|
-
const $tVatRate = $container.find('#t-vat-rate');
|
|
73
|
-
const $tTotal = $container.find('#t-total');
|
|
74
|
-
|
|
75
|
-
function populateSelect($select, list, valueKey, labelFn, selected) {
|
|
76
|
-
const el = $select.get(0);
|
|
77
|
-
while (el.firstChild) el.removeChild(el.firstChild);
|
|
78
|
-
const placeholder = document.createElement('option');
|
|
79
|
-
placeholder.value = '';
|
|
80
|
-
placeholder.textContent = '- select -';
|
|
81
|
-
el.appendChild(placeholder);
|
|
82
|
-
for (const item of list) {
|
|
83
|
-
const opt = document.createElement('option');
|
|
84
|
-
opt.value = item[valueKey];
|
|
85
|
-
opt.textContent = labelFn(item);
|
|
86
|
-
if (item[valueKey] === selected) opt.selected = true;
|
|
87
|
-
el.appendChild(opt);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
populateSelect($issuer, issuers, 'id', (i) => i.name || '(unnamed)', invoice?.issuerId);
|
|
92
|
-
populateSelect($receiver, receivers, 'id', (r) => r.company || r.name || '(unnamed)', invoice?.receiverId);
|
|
93
|
-
|
|
94
|
-
const today = new Date().toISOString().slice(0, 10);
|
|
95
|
-
$title.text(isEdit ? `Edit Invoice ${invoice?.number ?? ''}` : 'New Invoice');
|
|
96
|
-
$number.val(invoice?.number ?? '');
|
|
97
|
-
$status.val(invoice?.status ?? 'draft');
|
|
98
|
-
$issueDate.val(invoice?.issueDate ?? today);
|
|
99
|
-
$dueDate.val(invoice?.dueDate ?? '');
|
|
100
|
-
$vatEnabled.prop('checked', invoice?.vatEnabled !== false);
|
|
101
|
-
$vatRate.val(invoice?.vatRate ?? 20);
|
|
102
|
-
$currency.val(invoice?.currency ?? 'GBP');
|
|
103
|
-
$notes.val(invoice?.notes ?? '');
|
|
104
|
-
|
|
105
|
-
if (isEdit) {
|
|
106
|
-
$print.attr('href', `${BASE}/invoices/${id}/print`).css('display', '');
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (!lineItems.length) {
|
|
110
|
-
lineItems.push({ description: '', quantity: 1, unitPrice: 0 });
|
|
111
|
-
}
|
|
112
|
-
renderLineItems();
|
|
113
|
-
recomputeTotals();
|
|
114
|
-
|
|
115
|
-
function makeCell(child) {
|
|
116
|
-
const td = document.createElement('td');
|
|
117
|
-
td.appendChild(child);
|
|
118
|
-
return td;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function renderLineItems() {
|
|
122
|
-
const body = $body.get(0);
|
|
123
|
-
while (body.firstChild) body.removeChild(body.firstChild);
|
|
124
|
-
|
|
125
|
-
lineItems.forEach((item, idx) => {
|
|
126
|
-
const tr = document.createElement('tr');
|
|
127
|
-
|
|
128
|
-
const desc = document.createElement('input');
|
|
129
|
-
desc.type = 'text';
|
|
130
|
-
desc.className = 'form-control li-desc';
|
|
131
|
-
desc.dataset.idx = idx;
|
|
132
|
-
desc.value = item.description ?? '';
|
|
133
|
-
desc.placeholder = 'Description';
|
|
134
|
-
|
|
135
|
-
const qty = document.createElement('input');
|
|
136
|
-
qty.type = 'number';
|
|
137
|
-
qty.className = 'form-control li-qty';
|
|
138
|
-
qty.dataset.idx = idx;
|
|
139
|
-
qty.min = '0';
|
|
140
|
-
qty.step = '0.01';
|
|
141
|
-
qty.value = Number(item.quantity) || 0;
|
|
142
|
-
|
|
143
|
-
const price = document.createElement('input');
|
|
144
|
-
price.type = 'number';
|
|
145
|
-
price.className = 'form-control li-price';
|
|
146
|
-
price.dataset.idx = idx;
|
|
147
|
-
price.min = '0';
|
|
148
|
-
price.step = '0.01';
|
|
149
|
-
price.value = Number(item.unitPrice) || 0;
|
|
150
|
-
|
|
151
|
-
const totalCell = document.createElement('td');
|
|
152
|
-
totalCell.style.cssText = 'text-align:right;font-variant-numeric:tabular-nums;';
|
|
153
|
-
totalCell.id = `line-total-${idx}`;
|
|
154
|
-
totalCell.textContent = '-';
|
|
155
|
-
|
|
156
|
-
const removeBtn = document.createElement('button');
|
|
157
|
-
removeBtn.type = 'button';
|
|
158
|
-
removeBtn.className = 'btn btn-sm btn-ghost li-remove';
|
|
159
|
-
removeBtn.dataset.idx = idx;
|
|
160
|
-
removeBtn.title = 'Remove';
|
|
161
|
-
removeBtn.textContent = '×';
|
|
162
|
-
|
|
163
|
-
tr.appendChild(makeCell(desc));
|
|
164
|
-
tr.appendChild(makeCell(qty));
|
|
165
|
-
tr.appendChild(makeCell(price));
|
|
166
|
-
tr.appendChild(totalCell);
|
|
167
|
-
tr.appendChild(makeCell(removeBtn));
|
|
168
|
-
body.appendChild(tr);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
updateLineTotals();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function updateLineTotals() {
|
|
175
|
-
const currency = $currency.val();
|
|
176
|
-
lineItems.forEach((item, idx) => {
|
|
177
|
-
const lineTotal = round2((Number(item.quantity) || 0) * (Number(item.unitPrice) || 0));
|
|
178
|
-
const cell = $container.find(`#line-total-${idx}`).get(0);
|
|
179
|
-
if (cell) cell.textContent = fmt(lineTotal, currency);
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function recomputeTotals() {
|
|
184
|
-
const currency = $currency.val();
|
|
185
|
-
const vatEnabled = $vatEnabled.prop('checked');
|
|
186
|
-
const vatRate = Number($vatRate.val()) || 0;
|
|
187
|
-
|
|
188
|
-
let subtotal = 0;
|
|
189
|
-
for (const item of lineItems) {
|
|
190
|
-
subtotal += (Number(item.quantity) || 0) * (Number(item.unitPrice) || 0);
|
|
191
|
-
}
|
|
192
|
-
subtotal = round2(subtotal);
|
|
193
|
-
const vat = vatEnabled ? round2(subtotal * (vatRate / 100)) : 0;
|
|
194
|
-
const total = round2(subtotal + vat);
|
|
195
|
-
|
|
196
|
-
$tSubtotal.text(fmt(subtotal, currency));
|
|
197
|
-
$tVat.text(fmt(vat, currency));
|
|
198
|
-
$tVatRate.text(vatRate);
|
|
199
|
-
$tTotal.text(fmt(total, currency));
|
|
200
|
-
$vatRow.css('display', vatEnabled ? '' : 'none');
|
|
201
|
-
updateLineTotals();
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
$body.on('input', '.li-desc', function () {
|
|
205
|
-
lineItems[Number(this.dataset.idx)].description = this.value;
|
|
206
|
-
});
|
|
207
|
-
$body.on('input', '.li-qty', function () {
|
|
208
|
-
lineItems[Number(this.dataset.idx)].quantity = Number(this.value) || 0;
|
|
209
|
-
recomputeTotals();
|
|
210
|
-
});
|
|
211
|
-
$body.on('input', '.li-price', function () {
|
|
212
|
-
lineItems[Number(this.dataset.idx)].unitPrice = Number(this.value) || 0;
|
|
213
|
-
recomputeTotals();
|
|
214
|
-
});
|
|
215
|
-
$body.on('click', '.li-remove', function () {
|
|
216
|
-
const idx = Number(this.dataset.idx);
|
|
217
|
-
lineItems.splice(idx, 1);
|
|
218
|
-
if (!lineItems.length) lineItems.push({ description: '', quantity: 1, unitPrice: 0 });
|
|
219
|
-
renderLineItems();
|
|
220
|
-
recomputeTotals();
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
$container.find('#btn-add-line').on('click', () => {
|
|
224
|
-
lineItems.push({ description: '', quantity: 1, unitPrice: 0 });
|
|
225
|
-
renderLineItems();
|
|
226
|
-
recomputeTotals();
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
$vatEnabled.on('change', recomputeTotals);
|
|
230
|
-
$vatRate.on('input', recomputeTotals);
|
|
231
|
-
$currency.on('change', recomputeTotals);
|
|
232
|
-
|
|
233
|
-
$container.find('#btn-save').on('click', async () => {
|
|
234
|
-
const issuerId = $issuer.val();
|
|
235
|
-
const receiverId = $receiver.val();
|
|
236
|
-
if (!issuerId) { E.toast('Pick an issuer.', { type: 'error' }); return; }
|
|
237
|
-
if (!receiverId) { E.toast('Pick a receiver.', { type: 'error' }); return; }
|
|
238
|
-
|
|
239
|
-
const body = {
|
|
240
|
-
number: $number.val()?.trim() || undefined,
|
|
241
|
-
status: $status.val(),
|
|
242
|
-
issueDate: $issueDate.val(),
|
|
243
|
-
dueDate: $dueDate.val() || '',
|
|
244
|
-
issuerId,
|
|
245
|
-
receiverId,
|
|
246
|
-
vatEnabled: $vatEnabled.prop('checked'),
|
|
247
|
-
vatRate: Number($vatRate.val()) || 0,
|
|
248
|
-
currency: $currency.val(),
|
|
249
|
-
notes: $notes.val() ?? '',
|
|
250
|
-
lineItems
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
try {
|
|
254
|
-
const res = isEdit
|
|
255
|
-
? await H.put(`${BASE}/invoices/${id}`, body)
|
|
256
|
-
: await H.post(`${BASE}/invoices`, body);
|
|
257
|
-
if (res.error) throw new Error(res.error);
|
|
258
|
-
E.toast(isEdit ? 'Invoice saved.' : 'Invoice created.', { type: 'success' });
|
|
259
|
-
R.navigate('#/plugins/invoice');
|
|
260
|
-
} catch (err) {
|
|
261
|
-
E.toast(err?.message ?? 'Save failed.', { type: 'error' });
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
Domma.icons.scan();
|
|
266
|
-
}
|
|
267
|
-
};
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Invoice plugin - list view.
|
|
3
|
-
*/
|
|
4
|
-
function escapeHtml(s) {
|
|
5
|
-
return String(s ?? '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const BASE = '/api/plugins/invoice';
|
|
9
|
-
|
|
10
|
-
const STATUS_BADGE = {
|
|
11
|
-
draft: 'badge-secondary',
|
|
12
|
-
sent: 'badge-info',
|
|
13
|
-
paid: 'badge-success',
|
|
14
|
-
overdue: 'badge-danger',
|
|
15
|
-
cancelled: 'badge-secondary'
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const indexView = {
|
|
19
|
-
templateUrl: '/plugins/invoice/admin/templates/index.html',
|
|
20
|
-
|
|
21
|
-
async onMount($container) {
|
|
22
|
-
let invoices = [];
|
|
23
|
-
let receivers = [];
|
|
24
|
-
let table = null;
|
|
25
|
-
|
|
26
|
-
function receiverName(id) {
|
|
27
|
-
const r = receivers.find((x) => x.id === id);
|
|
28
|
-
if (!r) return '-';
|
|
29
|
-
return r.company || r.name || id;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function fmt(amount, currency) {
|
|
33
|
-
try {
|
|
34
|
-
return new Intl.NumberFormat('en-GB', { style: 'currency', currency: currency || 'GBP' }).format(Number(amount) || 0);
|
|
35
|
-
} catch {
|
|
36
|
-
return `${currency || 'GBP'} ${Number(amount).toFixed(2)}`;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function buildTable(data) {
|
|
41
|
-
const el = $container.find('#invoices-table').get(0);
|
|
42
|
-
if (!el) return;
|
|
43
|
-
if (table) {
|
|
44
|
-
table.setData(data);
|
|
45
|
-
Domma.icons.scan(el);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
table = T.create(el, {
|
|
49
|
-
data,
|
|
50
|
-
columns: [
|
|
51
|
-
{
|
|
52
|
-
key: 'number', title: 'Number', sortable: true,
|
|
53
|
-
render: (v, row) => `<a href="#/plugins/invoice/edit/${escapeHtml(row.id)}" style="font-weight:600;">${escapeHtml(v || '-')}</a>`
|
|
54
|
-
},
|
|
55
|
-
{ key: 'receiverId', title: 'Billed To', sortable: false,
|
|
56
|
-
render: (v) => escapeHtml(receiverName(v))
|
|
57
|
-
},
|
|
58
|
-
{ key: 'issueDate', title: 'Issue Date', sortable: true,
|
|
59
|
-
render: (v) => v ? escapeHtml(D(v).format('DD MMM YYYY')) : '-'
|
|
60
|
-
},
|
|
61
|
-
{ key: 'totals', title: 'Total', sortable: false,
|
|
62
|
-
render: (totals, row) => `<span style="font-variant-numeric:tabular-nums;">${escapeHtml(fmt(totals?.total ?? 0, row.currency))}</span>`
|
|
63
|
-
},
|
|
64
|
-
{ key: 'status', title: 'Status', sortable: true,
|
|
65
|
-
render: (v) => `<span class="badge ${STATUS_BADGE[v] || 'badge-secondary'}">${escapeHtml(v || 'draft')}</span>`
|
|
66
|
-
},
|
|
67
|
-
{ key: 'id', title: 'Actions', sortable: false,
|
|
68
|
-
render: (id) => `<div style="display:flex;gap:.4rem;">
|
|
69
|
-
<button class="btn btn-sm btn-outline edit-btn" data-id="${escapeHtml(id)}"><span data-icon="edit" data-icon-size="14"></span></button>
|
|
70
|
-
<a class="btn btn-sm btn-outline" href="${BASE}/invoices/${escapeHtml(id)}/print" target="_blank" title="Print / PDF"><span data-icon="printer" data-icon-size="14"></span></a>
|
|
71
|
-
<button class="btn btn-sm btn-danger delete-btn" data-id="${escapeHtml(id)}"><span data-icon="trash" data-icon-size="14"></span></button>
|
|
72
|
-
</div>`
|
|
73
|
-
}
|
|
74
|
-
],
|
|
75
|
-
emptyMessage: 'No invoices yet. Click “New Invoice” to create your first.'
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
el.addEventListener('click', async (e) => {
|
|
79
|
-
const editBtn = e.target.closest('.edit-btn');
|
|
80
|
-
const delBtn = e.target.closest('.delete-btn');
|
|
81
|
-
if (editBtn) R.navigate('#/plugins/invoice/edit/' + editBtn.dataset.id);
|
|
82
|
-
if (delBtn) {
|
|
83
|
-
const id = delBtn.dataset.id;
|
|
84
|
-
const inv = invoices.find((x) => x.id === id);
|
|
85
|
-
const ok = await E.confirm(`Delete invoice ${inv?.number ?? ''}?`);
|
|
86
|
-
if (!ok) return;
|
|
87
|
-
try {
|
|
88
|
-
await H.delete(`${BASE}/invoices/${id}`);
|
|
89
|
-
E.toast('Invoice deleted.', { type: 'success' });
|
|
90
|
-
await reload();
|
|
91
|
-
} catch {
|
|
92
|
-
E.toast('Delete failed.', { type: 'error' });
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
Domma.icons.scan(el);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function refreshKpis() {
|
|
101
|
-
const counts = { total: invoices.length, outstanding: 0, paid: 0, drafts: 0 };
|
|
102
|
-
for (const i of invoices) {
|
|
103
|
-
if (i.status === 'paid') counts.paid++;
|
|
104
|
-
else if (i.status === 'draft') counts.drafts++;
|
|
105
|
-
else if (i.status === 'sent' || i.status === 'overdue') counts.outstanding++;
|
|
106
|
-
}
|
|
107
|
-
$container.find('#kpi-total').text(counts.total);
|
|
108
|
-
$container.find('#kpi-outstanding').text(counts.outstanding);
|
|
109
|
-
$container.find('#kpi-paid').text(counts.paid);
|
|
110
|
-
$container.find('#kpi-drafts').text(counts.drafts);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function applyFilters() {
|
|
114
|
-
const status = $container.find('#filter-status').val() || '';
|
|
115
|
-
const q = ($container.find('#filter-search').val() || '').toString().toLowerCase().trim();
|
|
116
|
-
let filtered = invoices;
|
|
117
|
-
if (status) filtered = filtered.filter((i) => i.status === status);
|
|
118
|
-
if (q) {
|
|
119
|
-
filtered = filtered.filter((i) =>
|
|
120
|
-
(i.number ?? '').toLowerCase().includes(q) ||
|
|
121
|
-
receiverName(i.receiverId).toLowerCase().includes(q)
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
buildTable(filtered);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async function reload() {
|
|
128
|
-
try {
|
|
129
|
-
const [invRes, recRes] = await Promise.all([
|
|
130
|
-
H.get(`${BASE}/invoices`),
|
|
131
|
-
H.get(`${BASE}/receivers`).catch(() => ({ data: [] }))
|
|
132
|
-
]);
|
|
133
|
-
invoices = invRes.data ?? invRes ?? [];
|
|
134
|
-
receivers = recRes.data ?? recRes ?? [];
|
|
135
|
-
} catch {
|
|
136
|
-
invoices = [];
|
|
137
|
-
receivers = [];
|
|
138
|
-
E.toast('Could not load invoices.', { type: 'error' });
|
|
139
|
-
}
|
|
140
|
-
refreshKpis();
|
|
141
|
-
applyFilters();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
$container.find('#btn-new-invoice').on('click', () => R.navigate('#/plugins/invoice/new'));
|
|
145
|
-
$container.find('#filter-status').on('change', applyFilters);
|
|
146
|
-
let timer = null;
|
|
147
|
-
$container.find('#filter-search').on('input', () => {
|
|
148
|
-
clearTimeout(timer);
|
|
149
|
-
timer = setTimeout(applyFilters, 200);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
await reload();
|
|
153
|
-
Domma.icons.scan();
|
|
154
|
-
}
|
|
155
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Invoice plugin - issuers CRUD view.
|
|
3
|
-
*/
|
|
4
|
-
import {mountPartyView} from './party-view.js?v=1';
|
|
5
|
-
|
|
6
|
-
export const issuersView = {
|
|
7
|
-
templateUrl: '/plugins/invoice/admin/templates/issuers.html',
|
|
8
|
-
onMount: ($container) => mountPartyView($container, {
|
|
9
|
-
kind: 'issuer',
|
|
10
|
-
endpoint: '/api/plugins/invoice/issuers',
|
|
11
|
-
label: 'Issuer',
|
|
12
|
-
fields: [
|
|
13
|
-
{ key: 'name', label: 'Trading Name', required: true, type: 'text' },
|
|
14
|
-
{ key: 'email', label: 'Email', type: 'text' },
|
|
15
|
-
{ key: 'phone', label: 'Phone', type: 'text' },
|
|
16
|
-
{ key: 'website', label: 'Website', type: 'text' },
|
|
17
|
-
{ key: 'vatNumber', label: 'VAT Number', type: 'text' },
|
|
18
|
-
{ key: 'logoUrl', label: 'Logo URL', type: 'text' },
|
|
19
|
-
{ key: 'address', label: 'Address', type: 'textarea' },
|
|
20
|
-
{ key: 'bankDetails', label: 'Bank Details', type: 'textarea' }
|
|
21
|
-
]
|
|
22
|
-
})
|
|
23
|
-
};
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared CRUD view for issuers and receivers.
|
|
3
|
-
* Renders a sortable table and an edit slideover driven by a fields[] config.
|
|
4
|
-
*/
|
|
5
|
-
function escapeHtml(s) {
|
|
6
|
-
return String(s ?? '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export async function mountPartyView($container, config) {
|
|
10
|
-
let parties = [];
|
|
11
|
-
let table = null;
|
|
12
|
-
|
|
13
|
-
function buildTable(data) {
|
|
14
|
-
const el = $container.find('#party-table').get(0);
|
|
15
|
-
if (!el) return;
|
|
16
|
-
if (table) {
|
|
17
|
-
table.setData(data);
|
|
18
|
-
Domma.icons.scan(el);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const cols = [
|
|
23
|
-
{ key: 'name', title: 'Name', sortable: true,
|
|
24
|
-
render: (v, row) => `<a href="#" data-id="${escapeHtml(row.id)}" class="party-edit" style="font-weight:600;">${escapeHtml(v || '(unnamed)')}</a>`
|
|
25
|
-
}
|
|
26
|
-
];
|
|
27
|
-
if (config.fields.some((f) => f.key === 'company')) {
|
|
28
|
-
cols.push({ key: 'company', title: 'Company', sortable: true, render: (v) => escapeHtml(v || '-') });
|
|
29
|
-
}
|
|
30
|
-
cols.push(
|
|
31
|
-
{ key: 'email', title: 'Email', sortable: true, render: (v) => v ? `<a href="mailto:${escapeHtml(v)}">${escapeHtml(v)}</a>` : '-' },
|
|
32
|
-
{ key: 'vatNumber', title: 'VAT', sortable: false, render: (v) => v ? `<code>${escapeHtml(v)}</code>` : '-' },
|
|
33
|
-
{ key: 'id', title: 'Actions', sortable: false,
|
|
34
|
-
render: (id) => `<div style="display:flex;gap:.4rem;">
|
|
35
|
-
<button class="btn btn-sm btn-outline party-edit" data-id="${escapeHtml(id)}"><span data-icon="edit" data-icon-size="14"></span></button>
|
|
36
|
-
<button class="btn btn-sm btn-danger party-delete" data-id="${escapeHtml(id)}"><span data-icon="trash" data-icon-size="14"></span></button>
|
|
37
|
-
</div>` }
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
table = T.create(el, { data, columns: cols, emptyMessage: `No ${config.label.toLowerCase()}s yet.` });
|
|
41
|
-
|
|
42
|
-
el.addEventListener('click', async (e) => {
|
|
43
|
-
const editEl = e.target.closest('.party-edit');
|
|
44
|
-
const delEl = e.target.closest('.party-delete');
|
|
45
|
-
if (editEl) {
|
|
46
|
-
e.preventDefault();
|
|
47
|
-
const party = parties.find((p) => p.id === editEl.dataset.id);
|
|
48
|
-
openEditor(party);
|
|
49
|
-
}
|
|
50
|
-
if (delEl) {
|
|
51
|
-
const party = parties.find((p) => p.id === delEl.dataset.id);
|
|
52
|
-
const ok = await E.confirm(`Delete ${config.label.toLowerCase()} "${party?.name ?? ''}"?`);
|
|
53
|
-
if (!ok) return;
|
|
54
|
-
try {
|
|
55
|
-
await H.delete(`${config.endpoint}/${party.id}`);
|
|
56
|
-
E.toast('Deleted.', { type: 'success' });
|
|
57
|
-
await reload();
|
|
58
|
-
} catch {
|
|
59
|
-
E.toast('Delete failed.', { type: 'error' });
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
Domma.icons.scan(el);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async function reload() {
|
|
68
|
-
try {
|
|
69
|
-
const res = await H.get(config.endpoint);
|
|
70
|
-
parties = res.data ?? res ?? [];
|
|
71
|
-
} catch {
|
|
72
|
-
parties = [];
|
|
73
|
-
E.toast(`Could not load ${config.label.toLowerCase()}s.`, { type: 'error' });
|
|
74
|
-
}
|
|
75
|
-
buildTable(parties);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function openEditor(existing) {
|
|
79
|
-
const isEdit = Boolean(existing);
|
|
80
|
-
const form = document.createElement('div');
|
|
81
|
-
form.style.cssText = 'display:flex;flex-direction:column;gap:.75rem;padding:.5rem;';
|
|
82
|
-
|
|
83
|
-
const inputs = {};
|
|
84
|
-
for (const field of config.fields) {
|
|
85
|
-
const wrap = document.createElement('div');
|
|
86
|
-
const label = document.createElement('label');
|
|
87
|
-
label.className = 'form-label';
|
|
88
|
-
label.textContent = field.label + (field.required ? ' *' : '');
|
|
89
|
-
wrap.appendChild(label);
|
|
90
|
-
|
|
91
|
-
let input;
|
|
92
|
-
if (field.type === 'textarea') {
|
|
93
|
-
input = document.createElement('textarea');
|
|
94
|
-
input.rows = 3;
|
|
95
|
-
} else {
|
|
96
|
-
input = document.createElement('input');
|
|
97
|
-
input.type = 'text';
|
|
98
|
-
}
|
|
99
|
-
input.className = 'form-control';
|
|
100
|
-
input.value = existing?.[field.key] ?? '';
|
|
101
|
-
wrap.appendChild(input);
|
|
102
|
-
form.appendChild(wrap);
|
|
103
|
-
inputs[field.key] = input;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const saveBtn = document.createElement('button');
|
|
107
|
-
saveBtn.type = 'button';
|
|
108
|
-
saveBtn.className = 'btn btn-primary mt-2';
|
|
109
|
-
saveBtn.textContent = isEdit ? 'Save changes' : 'Create';
|
|
110
|
-
form.appendChild(saveBtn);
|
|
111
|
-
|
|
112
|
-
const slideover = E.slideover({
|
|
113
|
-
title: isEdit ? `Edit ${config.label}` : `New ${config.label}`,
|
|
114
|
-
size: 'md',
|
|
115
|
-
position: 'right',
|
|
116
|
-
content: form
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
saveBtn.addEventListener('click', async () => {
|
|
120
|
-
const body = {};
|
|
121
|
-
for (const field of config.fields) {
|
|
122
|
-
body[field.key] = inputs[field.key].value;
|
|
123
|
-
}
|
|
124
|
-
if (!body.name?.trim()) {
|
|
125
|
-
E.toast('Name is required.', { type: 'error' });
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
try {
|
|
129
|
-
const res = isEdit
|
|
130
|
-
? await H.put(`${config.endpoint}/${existing.id}`, body)
|
|
131
|
-
: await H.post(config.endpoint, body);
|
|
132
|
-
if (res.error) throw new Error(res.error);
|
|
133
|
-
slideover.close();
|
|
134
|
-
E.toast(isEdit ? 'Saved.' : 'Created.', { type: 'success' });
|
|
135
|
-
await reload();
|
|
136
|
-
} catch (err) {
|
|
137
|
-
E.toast(err?.message ?? 'Save failed.', { type: 'error' });
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
slideover.open();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
$container.find('#btn-new').on('click', () => openEditor(null));
|
|
145
|
-
|
|
146
|
-
await reload();
|
|
147
|
-
Domma.icons.scan();
|
|
148
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Invoice plugin - receivers CRUD view.
|
|
3
|
-
*/
|
|
4
|
-
import {mountPartyView} from './party-view.js?v=1';
|
|
5
|
-
|
|
6
|
-
export const receiversView = {
|
|
7
|
-
templateUrl: '/plugins/invoice/admin/templates/receivers.html',
|
|
8
|
-
onMount: ($container) => mountPartyView($container, {
|
|
9
|
-
kind: 'receiver',
|
|
10
|
-
endpoint: '/api/plugins/invoice/receivers',
|
|
11
|
-
label: 'Receiver',
|
|
12
|
-
fields: [
|
|
13
|
-
{ key: 'name', label: 'Contact Name', required: true, type: 'text' },
|
|
14
|
-
{ key: 'company', label: 'Company', type: 'text' },
|
|
15
|
-
{ key: 'email', label: 'Email', type: 'text' },
|
|
16
|
-
{ key: 'phone', label: 'Phone', type: 'text' },
|
|
17
|
-
{ key: 'vatNumber', label: 'VAT Number', type: 'text' },
|
|
18
|
-
{ key: 'reference', label: 'Reference', type: 'text' },
|
|
19
|
-
{ key: 'address', label: 'Address', type: 'textarea' }
|
|
20
|
-
]
|
|
21
|
-
})
|
|
22
|
-
};
|