@fiduswriter/frontend 0.1.9
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/LICENSE +661 -0
- package/README.md +66 -0
- package/dist/admin_console/index.d.ts +8 -0
- package/dist/admin_console/index.d.ts.map +1 -0
- package/dist/admin_console/index.js +54 -0
- package/dist/admin_console/index.js.map +1 -0
- package/dist/api/index.d.ts +193 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +6 -0
- package/dist/api/index.js.map +1 -0
- package/dist/app/index.d.ts +74 -0
- package/dist/app/index.d.ts.map +1 -0
- package/dist/app/index.js +471 -0
- package/dist/app/index.js.map +1 -0
- package/dist/common/index.d.ts +3 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +3 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/templates.d.ts +3 -0
- package/dist/common/templates.d.ts.map +1 -0
- package/dist/common/templates.js +42 -0
- package/dist/common/templates.js.map +1 -0
- package/dist/common/user_util.d.ts +6 -0
- package/dist/common/user_util.d.ts.map +1 -0
- package/dist/common/user_util.js +16 -0
- package/dist/common/user_util.js.map +1 -0
- package/dist/document_templates/actions.d.ts +11 -0
- package/dist/document_templates/actions.d.ts.map +1 -0
- package/dist/document_templates/actions.js +141 -0
- package/dist/document_templates/actions.js.map +1 -0
- package/dist/document_templates/editor.d.ts +28 -0
- package/dist/document_templates/editor.d.ts.map +1 -0
- package/dist/document_templates/editor.js +139 -0
- package/dist/document_templates/editor.js.map +1 -0
- package/dist/document_templates/index.d.ts +3 -0
- package/dist/document_templates/index.d.ts.map +1 -0
- package/dist/document_templates/index.js +3 -0
- package/dist/document_templates/index.js.map +1 -0
- package/dist/document_templates/menu.d.ts +7 -0
- package/dist/document_templates/menu.d.ts.map +1 -0
- package/dist/document_templates/menu.js +62 -0
- package/dist/document_templates/menu.js.map +1 -0
- package/dist/document_templates/overview.d.ts +52 -0
- package/dist/document_templates/overview.d.ts.map +1 -0
- package/dist/document_templates/overview.js +274 -0
- package/dist/document_templates/overview.js.map +1 -0
- package/dist/document_templates/templates.d.ts +3 -0
- package/dist/document_templates/templates.d.ts.map +1 -0
- package/dist/document_templates/templates.js +9 -0
- package/dist/document_templates/templates.js.map +1 -0
- package/dist/documents/importer/docx/import.d.ts +5 -0
- package/dist/documents/importer/docx/import.d.ts.map +1 -0
- package/dist/documents/importer/docx/import.js +15 -0
- package/dist/documents/importer/docx/import.js.map +1 -0
- package/dist/documents/importer/docx/index.d.ts +2 -0
- package/dist/documents/importer/docx/index.d.ts.map +1 -0
- package/dist/documents/importer/docx/index.js +2 -0
- package/dist/documents/importer/docx/index.js.map +1 -0
- package/dist/documents/importer/native/file.d.ts +7 -0
- package/dist/documents/importer/native/file.d.ts.map +1 -0
- package/dist/documents/importer/native/file.js +60 -0
- package/dist/documents/importer/native/file.js.map +1 -0
- package/dist/documents/importer/native/import.d.ts +41 -0
- package/dist/documents/importer/native/import.d.ts.map +1 -0
- package/dist/documents/importer/native/import.js +126 -0
- package/dist/documents/importer/native/import.js.map +1 -0
- package/dist/documents/importer/native/index.d.ts +3 -0
- package/dist/documents/importer/native/index.d.ts.map +1 -0
- package/dist/documents/importer/native/index.js +3 -0
- package/dist/documents/importer/native/index.js.map +1 -0
- package/dist/documents/importer/odt/import.d.ts +5 -0
- package/dist/documents/importer/odt/import.d.ts.map +1 -0
- package/dist/documents/importer/odt/import.js +16 -0
- package/dist/documents/importer/odt/import.js.map +1 -0
- package/dist/documents/importer/odt/index.d.ts +2 -0
- package/dist/documents/importer/odt/index.d.ts.map +1 -0
- package/dist/documents/importer/odt/index.js +2 -0
- package/dist/documents/importer/odt/index.js.map +1 -0
- package/dist/documents/importer/pandoc/import.d.ts +5 -0
- package/dist/documents/importer/pandoc/import.d.ts.map +1 -0
- package/dist/documents/importer/pandoc/import.js +37 -0
- package/dist/documents/importer/pandoc/import.js.map +1 -0
- package/dist/documents/importer/pandoc/index.d.ts +2 -0
- package/dist/documents/importer/pandoc/index.d.ts.map +1 -0
- package/dist/documents/importer/pandoc/index.js +2 -0
- package/dist/documents/importer/pandoc/index.js.map +1 -0
- package/dist/documents/importer/register.d.ts +4 -0
- package/dist/documents/importer/register.d.ts.map +1 -0
- package/dist/documents/importer/register.js +4 -0
- package/dist/documents/importer/register.js.map +1 -0
- package/dist/documents/overview/actions.d.ts +32 -0
- package/dist/documents/overview/actions.d.ts.map +1 -0
- package/dist/documents/overview/actions.js +725 -0
- package/dist/documents/overview/actions.js.map +1 -0
- package/dist/documents/overview/index.d.ts +98 -0
- package/dist/documents/overview/index.d.ts.map +1 -0
- package/dist/documents/overview/index.js +814 -0
- package/dist/documents/overview/index.js.map +1 -0
- package/dist/documents/overview/menu.d.ts +28 -0
- package/dist/documents/overview/menu.d.ts.map +1 -0
- package/dist/documents/overview/menu.js +222 -0
- package/dist/documents/overview/menu.js.map +1 -0
- package/dist/documents/overview/templates.d.ts +31 -0
- package/dist/documents/overview/templates.d.ts.map +1 -0
- package/dist/documents/overview/templates.js +39 -0
- package/dist/documents/overview/templates.js.map +1 -0
- package/dist/documents/revisions/index.d.ts +14 -0
- package/dist/documents/revisions/index.d.ts.map +1 -0
- package/dist/documents/revisions/index.js +143 -0
- package/dist/documents/revisions/index.js.map +1 -0
- package/dist/documents/revisions/templates.d.ts +4 -0
- package/dist/documents/revisions/templates.d.ts.map +1 -0
- package/dist/documents/revisions/templates.js +36 -0
- package/dist/documents/revisions/templates.js.map +1 -0
- package/dist/documents/tools.d.ts +16 -0
- package/dist/documents/tools.d.ts.map +1 -0
- package/dist/documents/tools.js +69 -0
- package/dist/documents/tools.js.map +1 -0
- package/dist/error_hook/index.d.ts +19 -0
- package/dist/error_hook/index.d.ts.map +1 -0
- package/dist/error_hook/index.js +75 -0
- package/dist/error_hook/index.js.map +1 -0
- package/dist/feedback/index.d.ts +12 -0
- package/dist/feedback/index.d.ts.map +1 -0
- package/dist/feedback/index.js +125 -0
- package/dist/feedback/index.js.map +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/indexed_db/index.d.ts +24 -0
- package/dist/indexed_db/index.d.ts.map +1 -0
- package/dist/indexed_db/index.js +175 -0
- package/dist/indexed_db/index.js.map +1 -0
- package/dist/maintenance/index.d.ts +19 -0
- package/dist/maintenance/index.d.ts.map +1 -0
- package/dist/maintenance/index.js +223 -0
- package/dist/maintenance/index.js.map +1 -0
- package/dist/menu/index.d.ts +25 -0
- package/dist/menu/index.d.ts.map +1 -0
- package/dist/menu/index.js +229 -0
- package/dist/menu/index.js.map +1 -0
- package/dist/menu/templates.d.ts +6 -0
- package/dist/menu/templates.d.ts.map +1 -0
- package/dist/menu/templates.js +10 -0
- package/dist/menu/templates.js.map +1 -0
- package/dist/pages/404.d.ts +9 -0
- package/dist/pages/404.d.ts.map +1 -0
- package/dist/pages/404.js +12 -0
- package/dist/pages/404.js.map +1 -0
- package/dist/pages/flatpage.d.ts +12 -0
- package/dist/pages/flatpage.d.ts.map +1 -0
- package/dist/pages/flatpage.js +39 -0
- package/dist/pages/flatpage.js.map +1 -0
- package/dist/pages/offline.d.ts +10 -0
- package/dist/pages/offline.d.ts.map +1 -0
- package/dist/pages/offline.js +27 -0
- package/dist/pages/offline.js.map +1 -0
- package/dist/pages/setup.d.ts +10 -0
- package/dist/pages/setup.d.ts.map +1 -0
- package/dist/pages/setup.js +22 -0
- package/dist/pages/setup.js.map +1 -0
- package/dist/plugins/menu/index.d.ts +3 -0
- package/dist/plugins/menu/index.d.ts.map +1 -0
- package/dist/plugins/menu/index.js +2 -0
- package/dist/plugins/menu/index.js.map +1 -0
- package/dist/prelogin/index.d.ts +51 -0
- package/dist/prelogin/index.d.ts.map +1 -0
- package/dist/prelogin/index.js +131 -0
- package/dist/prelogin/index.js.map +1 -0
- package/dist/prelogin/templates.d.ts +20 -0
- package/dist/prelogin/templates.d.ts.map +1 -0
- package/dist/prelogin/templates.js +50 -0
- package/dist/prelogin/templates.js.map +1 -0
- package/dist/state_plugins/contributor_input/add_button.d.ts +22 -0
- package/dist/state_plugins/contributor_input/add_button.d.ts.map +1 -0
- package/dist/state_plugins/contributor_input/add_button.js +106 -0
- package/dist/state_plugins/contributor_input/add_button.js.map +1 -0
- package/dist/state_plugins/contributor_input/helpers.d.ts +3 -0
- package/dist/state_plugins/contributor_input/helpers.d.ts.map +1 -0
- package/dist/state_plugins/contributor_input/helpers.js +23 -0
- package/dist/state_plugins/contributor_input/helpers.js.map +1 -0
- package/dist/state_plugins/contributor_input/index.d.ts +4 -0
- package/dist/state_plugins/contributor_input/index.d.ts.map +1 -0
- package/dist/state_plugins/contributor_input/index.js +4 -0
- package/dist/state_plugins/contributor_input/index.js.map +1 -0
- package/dist/state_plugins/contributor_input/node_view.d.ts +20 -0
- package/dist/state_plugins/contributor_input/node_view.d.ts.map +1 -0
- package/dist/state_plugins/contributor_input/node_view.js +85 -0
- package/dist/state_plugins/contributor_input/node_view.js.map +1 -0
- package/dist/state_plugins/index.d.ts +3 -0
- package/dist/state_plugins/index.d.ts.map +1 -0
- package/dist/state_plugins/index.js +3 -0
- package/dist/state_plugins/index.js.map +1 -0
- package/dist/state_plugins/tag_input/helpers.d.ts +5 -0
- package/dist/state_plugins/tag_input/helpers.d.ts.map +1 -0
- package/dist/state_plugins/tag_input/helpers.js +55 -0
- package/dist/state_plugins/tag_input/helpers.js.map +1 -0
- package/dist/state_plugins/tag_input/index.d.ts +5 -0
- package/dist/state_plugins/tag_input/index.d.ts.map +1 -0
- package/dist/state_plugins/tag_input/index.js +5 -0
- package/dist/state_plugins/tag_input/index.js.map +1 -0
- package/dist/state_plugins/tag_input/node_view.d.ts +19 -0
- package/dist/state_plugins/tag_input/node_view.d.ts.map +1 -0
- package/dist/state_plugins/tag_input/node_view.js +85 -0
- package/dist/state_plugins/tag_input/node_view.js.map +1 -0
- package/dist/state_plugins/tag_input/tag_editor.d.ts +4 -0
- package/dist/state_plugins/tag_input/tag_editor.d.ts.map +1 -0
- package/dist/state_plugins/tag_input/tag_editor.js +160 -0
- package/dist/state_plugins/tag_input/tag_editor.js.map +1 -0
- package/dist/state_plugins/tag_input/tag_editor_plugins.d.ts +5 -0
- package/dist/state_plugins/tag_input/tag_editor_plugins.d.ts.map +1 -0
- package/dist/state_plugins/tag_input/tag_editor_plugins.js +64 -0
- package/dist/state_plugins/tag_input/tag_editor_plugins.js.map +1 -0
- package/dist/types.d.ts +53 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/user/auth/email_confirm.d.ts +23 -0
- package/dist/user/auth/email_confirm.d.ts.map +1 -0
- package/dist/user/auth/email_confirm.js +123 -0
- package/dist/user/auth/email_confirm.js.map +1 -0
- package/dist/user/auth/email_confirm_templates.d.ts +12 -0
- package/dist/user/auth/email_confirm_templates.d.ts.map +1 -0
- package/dist/user/auth/email_confirm_templates.js +30 -0
- package/dist/user/auth/email_confirm_templates.js.map +1 -0
- package/dist/user/auth/login.d.ts +13 -0
- package/dist/user/auth/login.d.ts.map +1 -0
- package/dist/user/auth/login.js +186 -0
- package/dist/user/auth/login.js.map +1 -0
- package/dist/user/auth/password_reset_change.d.ts +11 -0
- package/dist/user/auth/password_reset_change.d.ts.map +1 -0
- package/dist/user/auth/password_reset_change.js +101 -0
- package/dist/user/auth/password_reset_change.js.map +1 -0
- package/dist/user/auth/password_reset_request.d.ts +10 -0
- package/dist/user/auth/password_reset_request.d.ts.map +1 -0
- package/dist/user/auth/password_reset_request.js +82 -0
- package/dist/user/auth/password_reset_request.js.map +1 -0
- package/dist/user/auth/signup.d.ts +9 -0
- package/dist/user/auth/signup.d.ts.map +1 -0
- package/dist/user/auth/signup.js +148 -0
- package/dist/user/auth/signup.js.map +1 -0
- package/dist/user/auth/two_factor.d.ts +10 -0
- package/dist/user/auth/two_factor.d.ts.map +1 -0
- package/dist/user/auth/two_factor.js +201 -0
- package/dist/user/auth/two_factor.js.map +1 -0
- package/dist/user/contacts/add_dialog.d.ts +7 -0
- package/dist/user/contacts/add_dialog.d.ts.map +1 -0
- package/dist/user/contacts/add_dialog.js +84 -0
- package/dist/user/contacts/add_dialog.js.map +1 -0
- package/dist/user/contacts/delete_dialog.d.ts +6 -0
- package/dist/user/contacts/delete_dialog.d.ts.map +1 -0
- package/dist/user/contacts/delete_dialog.js +38 -0
- package/dist/user/contacts/delete_dialog.js.map +1 -0
- package/dist/user/contacts/index.d.ts +35 -0
- package/dist/user/contacts/index.d.ts.map +1 -0
- package/dist/user/contacts/index.js +234 -0
- package/dist/user/contacts/index.js.map +1 -0
- package/dist/user/contacts/invite.d.ts +9 -0
- package/dist/user/contacts/invite.d.ts.map +1 -0
- package/dist/user/contacts/invite.js +21 -0
- package/dist/user/contacts/invite.js.map +1 -0
- package/dist/user/contacts/menu.d.ts +7 -0
- package/dist/user/contacts/menu.d.ts.map +1 -0
- package/dist/user/contacts/menu.js +62 -0
- package/dist/user/contacts/menu.js.map +1 -0
- package/dist/user/contacts/respond_invite.d.ts +9 -0
- package/dist/user/contacts/respond_invite.d.ts.map +1 -0
- package/dist/user/contacts/respond_invite.js +65 -0
- package/dist/user/contacts/respond_invite.js.map +1 -0
- package/dist/user/contacts/templates.d.ts +7 -0
- package/dist/user/contacts/templates.d.ts.map +1 -0
- package/dist/user/contacts/templates.js +24 -0
- package/dist/user/contacts/templates.js.map +1 -0
- package/dist/user/profile/delete_user.d.ts +8 -0
- package/dist/user/profile/delete_user.d.ts.map +1 -0
- package/dist/user/profile/delete_user.js +56 -0
- package/dist/user/profile/delete_user.js.map +1 -0
- package/dist/user/profile/dialogs.d.ts +10 -0
- package/dist/user/profile/dialogs.d.ts.map +1 -0
- package/dist/user/profile/dialogs.js +311 -0
- package/dist/user/profile/dialogs.js.map +1 -0
- package/dist/user/profile/index.d.ts +27 -0
- package/dist/user/profile/index.d.ts.map +1 -0
- package/dist/user/profile/index.js +254 -0
- package/dist/user/profile/index.js.map +1 -0
- package/dist/user/profile/templates.d.ts +22 -0
- package/dist/user/profile/templates.d.ts.map +1 -0
- package/dist/user/profile/templates.js +261 -0
- package/dist/user/profile/templates.js.map +1 -0
- package/dist/workers/adjust_doc_to_template.d.ts +11 -0
- package/dist/workers/adjust_doc_to_template.d.ts.map +1 -0
- package/dist/workers/adjust_doc_to_template.js +26 -0
- package/dist/workers/adjust_doc_to_template.js.map +1 -0
- package/package.json +225 -0
- package/src/admin_console/index.ts +84 -0
- package/src/api/index.ts +149 -0
- package/src/app/index.ts +605 -0
- package/src/common/index.ts +2 -0
- package/src/common/templates.ts +49 -0
- package/src/common/user_util.ts +16 -0
- package/src/document_templates/actions.ts +179 -0
- package/src/document_templates/editor.ts +177 -0
- package/src/document_templates/index.ts +2 -0
- package/src/document_templates/menu.ts +74 -0
- package/src/document_templates/overview.ts +335 -0
- package/src/document_templates/templates.ts +9 -0
- package/src/documents/importer/docx/import.ts +25 -0
- package/src/documents/importer/docx/index.ts +1 -0
- package/src/documents/importer/native/file.ts +112 -0
- package/src/documents/importer/native/import.ts +219 -0
- package/src/documents/importer/native/index.ts +2 -0
- package/src/documents/importer/odt/import.ts +26 -0
- package/src/documents/importer/odt/index.ts +1 -0
- package/src/documents/importer/pandoc/import.ts +57 -0
- package/src/documents/importer/pandoc/index.ts +1 -0
- package/src/documents/importer/register.ts +8 -0
- package/src/documents/overview/actions.ts +1031 -0
- package/src/documents/overview/index.ts +1006 -0
- package/src/documents/overview/menu.ts +311 -0
- package/src/documents/overview/templates.ts +64 -0
- package/src/documents/revisions/index.ts +183 -0
- package/src/documents/revisions/templates.ts +42 -0
- package/src/documents/tools.ts +107 -0
- package/src/error_hook/index.ts +129 -0
- package/src/feedback/index.ts +185 -0
- package/src/global.d.ts +22 -0
- package/src/index.ts +95 -0
- package/src/indexed_db/index.ts +217 -0
- package/src/maintenance/index.ts +258 -0
- package/src/menu/index.ts +267 -0
- package/src/menu/templates.ts +21 -0
- package/src/pages/404.ts +13 -0
- package/src/pages/flatpage.ts +43 -0
- package/src/pages/offline.ts +39 -0
- package/src/pages/setup.ts +34 -0
- package/src/plugins/menu/index.ts +3 -0
- package/src/prelogin/index.ts +175 -0
- package/src/prelogin/templates.ts +86 -0
- package/src/types.ts +63 -0
- package/src/user/auth/email_confirm.ts +153 -0
- package/src/user/auth/email_confirm_templates.ts +76 -0
- package/src/user/auth/login.ts +221 -0
- package/src/user/auth/password_reset_change.ts +120 -0
- package/src/user/auth/password_reset_request.ts +107 -0
- package/src/user/auth/signup.ts +182 -0
- package/src/user/auth/two_factor.ts +244 -0
- package/src/user/contacts/add_dialog.ts +104 -0
- package/src/user/contacts/delete_dialog.ts +40 -0
- package/src/user/contacts/index.ts +289 -0
- package/src/user/contacts/invite.ts +24 -0
- package/src/user/contacts/menu.ts +70 -0
- package/src/user/contacts/respond_invite.ts +76 -0
- package/src/user/contacts/templates.ts +29 -0
- package/src/user/profile/delete_user.ts +71 -0
- package/src/user/profile/dialogs.ts +363 -0
- package/src/user/profile/index.ts +359 -0
- package/src/user/profile/templates.ts +299 -0
- package/src/workers/adjust_doc_to_template.ts +41 -0
|
@@ -0,0 +1,1006 @@
|
|
|
1
|
+
import {docSchema} from "@fiduswriter/document/schema/document/index"
|
|
2
|
+
import deepEqual from "fast-deep-equal"
|
|
3
|
+
import {
|
|
4
|
+
Dialog,
|
|
5
|
+
OverviewDataTable,
|
|
6
|
+
OverviewMenuView,
|
|
7
|
+
activateWait,
|
|
8
|
+
addAlert,
|
|
9
|
+
avatarTemplate,
|
|
10
|
+
deactivateWait,
|
|
11
|
+
ensureCSS,
|
|
12
|
+
escapeText,
|
|
13
|
+
findTarget,
|
|
14
|
+
postJson,
|
|
15
|
+
setDocTitle,
|
|
16
|
+
shortFileTitle,
|
|
17
|
+
whenReady
|
|
18
|
+
} from "fwtoolkit"
|
|
19
|
+
|
|
20
|
+
import {baseBodyTemplate} from "../../common/index.js"
|
|
21
|
+
import {FeedbackTab} from "../../feedback/index.js"
|
|
22
|
+
import {SiteMenu} from "../../menu/index.js"
|
|
23
|
+
import type {App} from "../../types.js"
|
|
24
|
+
|
|
25
|
+
import {DocumentOverviewActions} from "./actions.js"
|
|
26
|
+
import {bulkMenuModel, menuModel} from "./menu.js"
|
|
27
|
+
import type {MenuModel} from "./menu.js"
|
|
28
|
+
import {dateCell, deleteFolderCell} from "./templates.js"
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
* Helper functions for the document overview page.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
interface DocumentListEntry {
|
|
35
|
+
id: number
|
|
36
|
+
title: string
|
|
37
|
+
path: string
|
|
38
|
+
e2ee?: boolean
|
|
39
|
+
is_owner?: boolean
|
|
40
|
+
owner: {id: number; name: string; avatar?: string}
|
|
41
|
+
added: number
|
|
42
|
+
updated: number
|
|
43
|
+
revisions: Array<Record<string, unknown>>
|
|
44
|
+
rights?: string
|
|
45
|
+
template?: string
|
|
46
|
+
content?: unknown
|
|
47
|
+
[key: string]: unknown
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface Contact {
|
|
51
|
+
id: number
|
|
52
|
+
[key: string]: unknown
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface DocumentOverviewConstructorOptions {
|
|
56
|
+
app: App & {
|
|
57
|
+
isOffline: () => boolean
|
|
58
|
+
indexedDB: {
|
|
59
|
+
readAllData: (store: string) => Promise<Array<Record<string, unknown>>>
|
|
60
|
+
clearData: (store: string) => Promise<void>
|
|
61
|
+
insertData: (store: string, data: Array<Record<string, unknown>>) => Promise<void>
|
|
62
|
+
}
|
|
63
|
+
settings: Record<string, unknown>
|
|
64
|
+
bibDB?: unknown
|
|
65
|
+
csl?: {getStyles: () => Promise<unknown>}
|
|
66
|
+
page: unknown
|
|
67
|
+
}
|
|
68
|
+
user: Record<string, unknown>
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export class DocumentOverview {
|
|
72
|
+
app: DocumentOverviewConstructorOptions["app"]
|
|
73
|
+
user: Record<string, unknown>
|
|
74
|
+
path: string
|
|
75
|
+
schema: any
|
|
76
|
+
documentList: DocumentListEntry[]
|
|
77
|
+
contacts: Contact[]
|
|
78
|
+
mod: {actions?: DocumentOverviewActions}
|
|
79
|
+
lastSort: {column: number; dir: string}
|
|
80
|
+
active: boolean
|
|
81
|
+
hasPassphraseSetUp: boolean
|
|
82
|
+
dom!: HTMLElement
|
|
83
|
+
table: any
|
|
84
|
+
overviewTable: any
|
|
85
|
+
dtBulk: any
|
|
86
|
+
dtBulkModel: MenuModel
|
|
87
|
+
menu: any
|
|
88
|
+
plugins: Record<string, {init(): void}> | null
|
|
89
|
+
documentStyles: any
|
|
90
|
+
documentTemplates: Record<string, {id: number | string; title: string; [key: string]: unknown}>
|
|
91
|
+
|
|
92
|
+
constructor({app, user}: DocumentOverviewConstructorOptions, path = "/") {
|
|
93
|
+
this.app = app
|
|
94
|
+
this.user = user
|
|
95
|
+
this.path = path
|
|
96
|
+
this.schema = docSchema
|
|
97
|
+
this.documentList = []
|
|
98
|
+
this.contacts = []
|
|
99
|
+
this.mod = {}
|
|
100
|
+
this.lastSort = {column: 0, dir: "asc"}
|
|
101
|
+
this.active = false
|
|
102
|
+
this.hasPassphraseSetUp = false
|
|
103
|
+
this.plugins = null
|
|
104
|
+
this.documentStyles = null
|
|
105
|
+
this.documentTemplates = {}
|
|
106
|
+
this.dtBulkModel = bulkMenuModel()
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
init(): Promise<void> {
|
|
110
|
+
if (this.active) {
|
|
111
|
+
return Promise.resolve()
|
|
112
|
+
}
|
|
113
|
+
this.active = true
|
|
114
|
+
return whenReady().then(() => {
|
|
115
|
+
this.render()
|
|
116
|
+
const smenu = new SiteMenu(this.app as any, "documents")
|
|
117
|
+
smenu.init()
|
|
118
|
+
new DocumentOverviewActions(this)
|
|
119
|
+
this.menu = new OverviewMenuView(this, menuModel as any)
|
|
120
|
+
this.menu.init()
|
|
121
|
+
this.dtBulkModel = bulkMenuModel()
|
|
122
|
+
this.activateFidusPlugins()
|
|
123
|
+
this.bind()
|
|
124
|
+
return this.getDocumentListData()
|
|
125
|
+
.then(() => this.bulkDecryptDocumentEncryptionKeys())
|
|
126
|
+
.then(() => this._checkPassphraseAndUpdateMenu())
|
|
127
|
+
.then(() => deactivateWait() as any)
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
render(): void {
|
|
132
|
+
this.dom = document.createElement("body")
|
|
133
|
+
this.dom.innerHTML = baseBodyTemplate({
|
|
134
|
+
contents: "",
|
|
135
|
+
user: this.user as any,
|
|
136
|
+
hasOverview: true,
|
|
137
|
+
app: this.app as any
|
|
138
|
+
})
|
|
139
|
+
ensureCSS([
|
|
140
|
+
staticUrl("css/document_overview.css"),
|
|
141
|
+
staticUrl("css/add_remove_dialog.css"),
|
|
142
|
+
staticUrl("css/access_rights_dialog.css"),
|
|
143
|
+
staticUrl("css/e2ee.css")
|
|
144
|
+
])
|
|
145
|
+
document.body = this.dom
|
|
146
|
+
setDocTitle(gettext("Document Overview"), this.app as any)
|
|
147
|
+
const feedbackTab = new FeedbackTab()
|
|
148
|
+
feedbackTab.init()
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
bind(): void {
|
|
152
|
+
this.dom.addEventListener("click", event => {
|
|
153
|
+
const el: Record<string, any> = {}
|
|
154
|
+
let docId: number
|
|
155
|
+
switch (true) {
|
|
156
|
+
case findTarget(event, ".revisions", el): {
|
|
157
|
+
docId = Number.parseInt(el.target.dataset.id)
|
|
158
|
+
this.mod.actions!.revisionsDialog(docId, this.app)
|
|
159
|
+
break
|
|
160
|
+
}
|
|
161
|
+
case findTarget(event, ".document-settings", el):
|
|
162
|
+
docId = Number.parseInt(el.target.dataset.id)
|
|
163
|
+
this.mod.actions!.settingsDocumentDialog(docId)
|
|
164
|
+
break
|
|
165
|
+
case findTarget(event, ".delete-document", el):
|
|
166
|
+
docId = Number.parseInt(el.target.dataset.id)
|
|
167
|
+
this.mod.actions!.deleteDocumentDialog([docId], this.app)
|
|
168
|
+
break
|
|
169
|
+
case findTarget(event, ".delete-folder", el): {
|
|
170
|
+
const ids = el.target.dataset.ids
|
|
171
|
+
.split(",")
|
|
172
|
+
.map((id: string) => Number.parseInt(id))
|
|
173
|
+
this.mod.actions!.deleteDocumentDialog(ids, this.app)
|
|
174
|
+
break
|
|
175
|
+
}
|
|
176
|
+
case findTarget(event, ".fw-owned-by-user.rights", el): {
|
|
177
|
+
break
|
|
178
|
+
}
|
|
179
|
+
case findTarget(event, "a.fw-data-table-title.parentdir", el):
|
|
180
|
+
event.preventDefault()
|
|
181
|
+
if (this.table.data.data.length > 0) {
|
|
182
|
+
this.path = el.target.dataset.path
|
|
183
|
+
window.history.pushState(
|
|
184
|
+
{},
|
|
185
|
+
"",
|
|
186
|
+
el.target.getAttribute("href")
|
|
187
|
+
)
|
|
188
|
+
this.initTable()
|
|
189
|
+
} else {
|
|
190
|
+
const confirmFolderDeletionDialog = new Dialog({
|
|
191
|
+
title: gettext("Confirm deletion"),
|
|
192
|
+
body: `<p>
|
|
193
|
+
${gettext("Leaving an empty folder will delete it. Do you really want to delete this folder?")}
|
|
194
|
+
</p>`,
|
|
195
|
+
id: "confirmfolderdeletion",
|
|
196
|
+
icon: "exclamation-triangle",
|
|
197
|
+
buttons: [
|
|
198
|
+
{
|
|
199
|
+
text: gettext("Delete"),
|
|
200
|
+
classes: "fw-dark delete-folder",
|
|
201
|
+
click: () => {
|
|
202
|
+
confirmFolderDeletionDialog.close()
|
|
203
|
+
this.path = el.target.dataset.path
|
|
204
|
+
window.history.pushState(
|
|
205
|
+
{},
|
|
206
|
+
"",
|
|
207
|
+
el.target.getAttribute("href")
|
|
208
|
+
)
|
|
209
|
+
this.initTable()
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
type: "cancel"
|
|
214
|
+
}
|
|
215
|
+
]
|
|
216
|
+
} as any)
|
|
217
|
+
|
|
218
|
+
confirmFolderDeletionDialog.open()
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
break
|
|
222
|
+
case findTarget(event, "a.fw-data-table-title.subdir", el):
|
|
223
|
+
event.preventDefault()
|
|
224
|
+
this.path = el.target.dataset.path
|
|
225
|
+
window.history.pushState(
|
|
226
|
+
{},
|
|
227
|
+
"",
|
|
228
|
+
el.target.getAttribute("href")
|
|
229
|
+
)
|
|
230
|
+
this.initTable()
|
|
231
|
+
break
|
|
232
|
+
case findTarget(event, "a.fw-data-table-title", el):
|
|
233
|
+
event.preventDefault()
|
|
234
|
+
if (this.app.isOffline()) {
|
|
235
|
+
addAlert(
|
|
236
|
+
"info",
|
|
237
|
+
gettext(
|
|
238
|
+
"You cannot open a document while you are offline."
|
|
239
|
+
)
|
|
240
|
+
)
|
|
241
|
+
} else {
|
|
242
|
+
this.app.goTo(el.target.getAttribute("href"))
|
|
243
|
+
}
|
|
244
|
+
break
|
|
245
|
+
default:
|
|
246
|
+
break
|
|
247
|
+
}
|
|
248
|
+
})
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
activateFidusPlugins(): void {
|
|
252
|
+
if (this.plugins) {
|
|
253
|
+
return
|
|
254
|
+
}
|
|
255
|
+
this.plugins = {}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
getDocumentListData(): Promise<void> {
|
|
259
|
+
const cachedPromise = this.showCached()
|
|
260
|
+
if (this.app.isOffline()) {
|
|
261
|
+
return cachedPromise.then(() => {})
|
|
262
|
+
}
|
|
263
|
+
return whenReady()
|
|
264
|
+
.then(() => postJson("/api/document/documentlist/"))
|
|
265
|
+
.then(({json}) => {
|
|
266
|
+
const typedJson = json as Record<string, unknown>
|
|
267
|
+
return cachedPromise.then(oldJson => {
|
|
268
|
+
if (!deepEqual(typedJson, oldJson)) {
|
|
269
|
+
this.updateIndexedDB(typedJson)
|
|
270
|
+
this.initializeView(typedJson)
|
|
271
|
+
}
|
|
272
|
+
})
|
|
273
|
+
})
|
|
274
|
+
.catch(error => {
|
|
275
|
+
if (this.app.isOffline()) {
|
|
276
|
+
return cachedPromise.then(() => {})
|
|
277
|
+
} else {
|
|
278
|
+
addAlert("error", gettext("Document data loading failed."))
|
|
279
|
+
throw error
|
|
280
|
+
}
|
|
281
|
+
})
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
async bulkDecryptDocumentEncryptionKeys(): Promise<void> {
|
|
285
|
+
try {
|
|
286
|
+
const response = await postJson(
|
|
287
|
+
"/api/document/encryption_key/get_all/",
|
|
288
|
+
{}
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
if (!(response.json as any)?.keys?.length) {
|
|
292
|
+
return
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const {PassphraseCrypto} = await import(
|
|
296
|
+
"fwtoolkit/e2ee/passphrase-crypto"
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
for (const keyData of (response.json as any).keys) {
|
|
300
|
+
const {document_id, encrypted_key, encrypted_with_master_key} =
|
|
301
|
+
keyData
|
|
302
|
+
|
|
303
|
+
const sessionKey = sessionStorage.getItem(
|
|
304
|
+
`e2ee_key_${document_id}`
|
|
305
|
+
)
|
|
306
|
+
if (sessionKey) {
|
|
307
|
+
continue
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (!encrypted_with_master_key) {
|
|
311
|
+
continue
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
try {
|
|
315
|
+
const masterKeyBase64 =
|
|
316
|
+
sessionStorage.getItem("e2ee_master_key")
|
|
317
|
+
if (!masterKeyBase64) {
|
|
318
|
+
continue
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const masterKeyBytes = Uint8Array.from(
|
|
322
|
+
atob(masterKeyBase64),
|
|
323
|
+
c => c.charCodeAt(0)
|
|
324
|
+
)
|
|
325
|
+
const masterKey = await (PassphraseCrypto as any).importKey(
|
|
326
|
+
masterKeyBytes,
|
|
327
|
+
"AES-GCM"
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
const dek = await PassphraseCrypto.decryptString(
|
|
331
|
+
encrypted_key,
|
|
332
|
+
masterKey
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
sessionStorage.setItem(`e2ee_key_${document_id}`, dek)
|
|
336
|
+
} catch (_error) {
|
|
337
|
+
continue
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
} catch (_error) {
|
|
341
|
+
// Silently fail - this is a best-effort operation
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
async _checkPassphraseAndUpdateMenu(): Promise<void> {
|
|
346
|
+
const e2eeMode = this.app.settings.E2EE_MODE as string
|
|
347
|
+
if (e2eeMode === "disabled") {
|
|
348
|
+
return
|
|
349
|
+
}
|
|
350
|
+
const {PassphraseManager} = await import(
|
|
351
|
+
"fwtoolkit/e2ee/passphrase-manager"
|
|
352
|
+
)
|
|
353
|
+
this.hasPassphraseSetUp = await PassphraseManager.hasEncryptionKeys()
|
|
354
|
+
if (e2eeMode === "required" && !this.hasPassphraseSetUp) {
|
|
355
|
+
const importItemIdx = this.menu.model.content.findIndex(
|
|
356
|
+
(item: any) => item.id === "import_document"
|
|
357
|
+
)
|
|
358
|
+
if (importItemIdx !== -1) {
|
|
359
|
+
this.menu.model.content.splice(importItemIdx, 1)
|
|
360
|
+
this.menu.update()
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
showCached(): Promise<any> {
|
|
366
|
+
return this.loaddatafromIndexedDB().then(json => {
|
|
367
|
+
if (!json) {
|
|
368
|
+
activateWait(true)
|
|
369
|
+
return
|
|
370
|
+
}
|
|
371
|
+
return this.initializeView(json)
|
|
372
|
+
})
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
loaddatafromIndexedDB(): Promise<any> {
|
|
376
|
+
return this.app.indexedDB
|
|
377
|
+
.readAllData("document_data")
|
|
378
|
+
.then(response => {
|
|
379
|
+
if (!response.length) {
|
|
380
|
+
return false
|
|
381
|
+
}
|
|
382
|
+
const data = response[0]
|
|
383
|
+
delete data.id
|
|
384
|
+
return data
|
|
385
|
+
})
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
updateIndexedDB(json: Record<string, unknown>): Promise<void> {
|
|
389
|
+
;(json as any).id = 1
|
|
390
|
+
return this.app.indexedDB
|
|
391
|
+
.clearData("document_data")
|
|
392
|
+
.then(() => this.app.indexedDB.insertData("document_data", [json]))
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
initializeView(json: any): any {
|
|
396
|
+
if (!this.active) {
|
|
397
|
+
return json
|
|
398
|
+
}
|
|
399
|
+
const ids = new Set<number>()
|
|
400
|
+
this.documentList = (json.documents as DocumentListEntry[]).filter(doc => {
|
|
401
|
+
if (ids.has(doc.id)) {
|
|
402
|
+
return false
|
|
403
|
+
}
|
|
404
|
+
ids.add(doc.id)
|
|
405
|
+
return true
|
|
406
|
+
})
|
|
407
|
+
|
|
408
|
+
this.contacts = json.contacts
|
|
409
|
+
this.documentStyles = json.document_styles
|
|
410
|
+
this.documentTemplates = json.document_templates
|
|
411
|
+
this.initTable()
|
|
412
|
+
this.decryptE2EETitles()
|
|
413
|
+
window.scrollTo(0, 0)
|
|
414
|
+
if (Object.keys(this.documentTemplates).length > 1) {
|
|
415
|
+
this.multipleNewDocumentMenuItem()
|
|
416
|
+
} else {
|
|
417
|
+
this.singleNewDocumentMenuItem()
|
|
418
|
+
}
|
|
419
|
+
return json
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
async decryptE2EETitles(): Promise<void> {
|
|
423
|
+
const e2eeDocs = this.documentList.filter(
|
|
424
|
+
doc =>
|
|
425
|
+
doc.e2ee &&
|
|
426
|
+
doc.title &&
|
|
427
|
+
sessionStorage.getItem(`e2ee_title_${doc.id}`) === null
|
|
428
|
+
)
|
|
429
|
+
if (!e2eeDocs.length) {
|
|
430
|
+
return
|
|
431
|
+
}
|
|
432
|
+
const {E2EEKeyManager} = await import("fwtoolkit/e2ee/key-manager")
|
|
433
|
+
const {E2EEEncryptor} = await import("fwtoolkit/e2ee/encryptor")
|
|
434
|
+
for (const doc of e2eeDocs) {
|
|
435
|
+
const key = await E2EEKeyManager.getKeyFromSession(doc.id)
|
|
436
|
+
if (!key) {
|
|
437
|
+
continue
|
|
438
|
+
}
|
|
439
|
+
try {
|
|
440
|
+
const title = await E2EEEncryptor.decrypt(doc.title, key)
|
|
441
|
+
sessionStorage.setItem(`e2ee_title_${doc.id}`, title)
|
|
442
|
+
const linkEl = document.querySelector(
|
|
443
|
+
`a.fw-data-table-title[href="/document/${doc.id}"]`
|
|
444
|
+
)
|
|
445
|
+
if (linkEl) {
|
|
446
|
+
const span = linkEl.querySelector("span.fw-searchable")
|
|
447
|
+
if (span) {
|
|
448
|
+
span.textContent = shortFileTitle(title, doc.path)
|
|
449
|
+
span.classList.remove("e2ee-encrypted-title")
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
} catch (_e) {
|
|
453
|
+
// Decryption failed — key may be stale. Ignore.
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
onResize(): void {
|
|
459
|
+
if (!this.table) {
|
|
460
|
+
return
|
|
461
|
+
}
|
|
462
|
+
this.initTable()
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
initTable(searching = false): void {
|
|
466
|
+
if (this.overviewTable) {
|
|
467
|
+
this.overviewTable.destroy()
|
|
468
|
+
this.overviewTable = null
|
|
469
|
+
}
|
|
470
|
+
this.table = null
|
|
471
|
+
this.dtBulk = null
|
|
472
|
+
|
|
473
|
+
const subdirs: Record<string, any> = {}
|
|
474
|
+
const contentsEl = document.querySelector(".fw-contents") as HTMLElement
|
|
475
|
+
contentsEl.innerHTML = ""
|
|
476
|
+
|
|
477
|
+
if (this.path !== "/") {
|
|
478
|
+
const headerEl = document.createElement("h1")
|
|
479
|
+
headerEl.innerHTML = escapeText(this.path)
|
|
480
|
+
contentsEl.appendChild(headerEl)
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
const hiddenCols = [0, 1]
|
|
484
|
+
|
|
485
|
+
if (window.innerWidth < 500) {
|
|
486
|
+
hiddenCols.push(2, 5)
|
|
487
|
+
if (window.innerWidth < 400) {
|
|
488
|
+
hiddenCols.push(6)
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
const fileList = this.documentList
|
|
492
|
+
.map(doc => this.createTableRow(doc, subdirs, searching))
|
|
493
|
+
.filter(row => !!row)
|
|
494
|
+
|
|
495
|
+
let tableRender: any = false
|
|
496
|
+
if (!searching && this.path !== "/") {
|
|
497
|
+
const pathParts = this.path.split("/")
|
|
498
|
+
pathParts.pop()
|
|
499
|
+
pathParts.pop()
|
|
500
|
+
const parentPath = pathParts.join("/") + "/"
|
|
501
|
+
const href =
|
|
502
|
+
parentPath === "/" && (this.app as any).routes[""].app === "document"
|
|
503
|
+
? parentPath
|
|
504
|
+
: `/documents${encodeURI(parentPath)}`
|
|
505
|
+
tableRender = (_data: any, table: any, type: string) => {
|
|
506
|
+
if (!["main", "message"].includes(type)) {
|
|
507
|
+
return
|
|
508
|
+
}
|
|
509
|
+
table.childNodes[1].childNodes.unshift({
|
|
510
|
+
nodeName: "TR",
|
|
511
|
+
attributes: {
|
|
512
|
+
"data-index": "0"
|
|
513
|
+
},
|
|
514
|
+
childNodes: [
|
|
515
|
+
{nodeName: "TD"},
|
|
516
|
+
{
|
|
517
|
+
nodeName: "TD",
|
|
518
|
+
childNodes: [
|
|
519
|
+
{
|
|
520
|
+
nodeName: "a",
|
|
521
|
+
attributes: {
|
|
522
|
+
class: "fw-data-table-title fw-link-text parentdir",
|
|
523
|
+
href,
|
|
524
|
+
"data-path": parentPath
|
|
525
|
+
},
|
|
526
|
+
childNodes: [
|
|
527
|
+
{
|
|
528
|
+
nodeName: "i",
|
|
529
|
+
attributes: {
|
|
530
|
+
class: "fa-solid fa-folder"
|
|
531
|
+
}
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
nodeName: "span",
|
|
535
|
+
attributes: {},
|
|
536
|
+
childNodes: [
|
|
537
|
+
{
|
|
538
|
+
nodeName: "#text",
|
|
539
|
+
data: ".."
|
|
540
|
+
}
|
|
541
|
+
]
|
|
542
|
+
}
|
|
543
|
+
]
|
|
544
|
+
}
|
|
545
|
+
]
|
|
546
|
+
},
|
|
547
|
+
{nodeName: "TD"},
|
|
548
|
+
{nodeName: "TD"},
|
|
549
|
+
{nodeName: "TD"},
|
|
550
|
+
{nodeName: "TD"},
|
|
551
|
+
{nodeName: "TD"},
|
|
552
|
+
{nodeName: "TD"}
|
|
553
|
+
]
|
|
554
|
+
})
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
this.overviewTable = new OverviewDataTable({
|
|
559
|
+
dom: contentsEl,
|
|
560
|
+
classes: ["fw-data-table", "fw-document-table", "fw-large"],
|
|
561
|
+
columns: [
|
|
562
|
+
{select: 0, type: "number"},
|
|
563
|
+
{select: 1, type: "string"},
|
|
564
|
+
{select: 2, type: "boolean"},
|
|
565
|
+
{select: [5, 6], type: "date"},
|
|
566
|
+
{select: hiddenCols, hidden: true},
|
|
567
|
+
{select: [2, 4, 8, 9], sortable: false},
|
|
568
|
+
{select: [this.lastSort.column], sort: this.lastSort.dir}
|
|
569
|
+
],
|
|
570
|
+
data: fileList,
|
|
571
|
+
idColumn: 0,
|
|
572
|
+
checkboxColumn: 2,
|
|
573
|
+
bulkMenu: this.dtBulkModel,
|
|
574
|
+
bulkMenuPage: this,
|
|
575
|
+
searchable: searching,
|
|
576
|
+
scrollY: `${Math.max(window.innerHeight - 360, 200)}px`,
|
|
577
|
+
tabIndex: 1,
|
|
578
|
+
labels: {
|
|
579
|
+
noRows: gettext("No documents available"),
|
|
580
|
+
noResults: gettext("No documents found")
|
|
581
|
+
},
|
|
582
|
+
headings: [
|
|
583
|
+
"", "", "",
|
|
584
|
+
gettext("Title"),
|
|
585
|
+
gettext("Revisions"),
|
|
586
|
+
gettext("Created"),
|
|
587
|
+
gettext("Last changed"),
|
|
588
|
+
gettext("Owner"),
|
|
589
|
+
gettext("Settings"),
|
|
590
|
+
""
|
|
591
|
+
],
|
|
592
|
+
template: (options: any, _dom: any) =>
|
|
593
|
+
`<div class='${options.classes.container}'style='height: ${options.scrollY}; overflow-Y: auto;'></div>`,
|
|
594
|
+
tableRender,
|
|
595
|
+
rowRender: (row: any, tr: any, _index: number) => {
|
|
596
|
+
if (row.cells[1].data === "folder") {
|
|
597
|
+
tr.childNodes[0].childNodes = []
|
|
598
|
+
return
|
|
599
|
+
}
|
|
600
|
+
const id = row.cells[0].data
|
|
601
|
+
const inputNode: any = {
|
|
602
|
+
nodeName: "input",
|
|
603
|
+
attributes: {
|
|
604
|
+
type: "checkbox",
|
|
605
|
+
class: "entry-select fw-check",
|
|
606
|
+
"data-id": id,
|
|
607
|
+
id: `doc-${id}`
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
if (row.cells[2].data) {
|
|
611
|
+
inputNode.attributes.checked = true
|
|
612
|
+
}
|
|
613
|
+
tr.childNodes[0].childNodes = [
|
|
614
|
+
inputNode,
|
|
615
|
+
{
|
|
616
|
+
nodeName: "label",
|
|
617
|
+
attributes: {for: `doc-${id}`}
|
|
618
|
+
}
|
|
619
|
+
]
|
|
620
|
+
},
|
|
621
|
+
onEnter: (row: any, _event: any) => {
|
|
622
|
+
if (this.getSelected().length > 0) {
|
|
623
|
+
return
|
|
624
|
+
}
|
|
625
|
+
const rowIndex = this.table.data.data.indexOf(row)
|
|
626
|
+
const link = this.table.dom.querySelector(
|
|
627
|
+
`tr[data-index="${rowIndex}"] a.fw-data-table-title`
|
|
628
|
+
)
|
|
629
|
+
if (link) {
|
|
630
|
+
link.click()
|
|
631
|
+
}
|
|
632
|
+
},
|
|
633
|
+
onDelete: (row: any) => {
|
|
634
|
+
const docId = row.cells[0].data
|
|
635
|
+
this.mod.actions!.deleteDocumentDialog([docId], this.app)
|
|
636
|
+
}
|
|
637
|
+
} as any)
|
|
638
|
+
this.overviewTable.init()
|
|
639
|
+
this.table = this.overviewTable.table
|
|
640
|
+
this.dtBulk = this.overviewTable.dtBulk
|
|
641
|
+
|
|
642
|
+
this.table.on("datatable.sort", (column: number, dir: string) => {
|
|
643
|
+
this.lastSort = {column, dir}
|
|
644
|
+
})
|
|
645
|
+
|
|
646
|
+
this.table.dom.focus()
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
createTableRow(
|
|
650
|
+
doc: DocumentListEntry,
|
|
651
|
+
subdirs: Record<string, any>,
|
|
652
|
+
searching: boolean
|
|
653
|
+
): any {
|
|
654
|
+
let path = doc.path
|
|
655
|
+
if (!path.startsWith("/")) {
|
|
656
|
+
path = "/" + path
|
|
657
|
+
}
|
|
658
|
+
if (!path.startsWith(this.path)) {
|
|
659
|
+
return false
|
|
660
|
+
}
|
|
661
|
+
if (path.endsWith("/")) {
|
|
662
|
+
path += doc.title.replace(/\//g, "")
|
|
663
|
+
}
|
|
664
|
+
const currentPath = path.slice(this.path.length)
|
|
665
|
+
if (!searching && currentPath.includes("/")) {
|
|
666
|
+
const subdir = currentPath.split("/").shift()!
|
|
667
|
+
if (subdirs[subdir]) {
|
|
668
|
+
if (doc.added < subdirs[subdir].added) {
|
|
669
|
+
subdirs[subdir].added = doc.added
|
|
670
|
+
subdirs[subdir].row[5] = dateCell({date: doc.added})
|
|
671
|
+
}
|
|
672
|
+
if (doc.updated > subdirs[subdir].updated) {
|
|
673
|
+
subdirs[subdir].updated = doc.updated
|
|
674
|
+
subdirs[subdir].row[6] = dateCell({date: doc.updated})
|
|
675
|
+
}
|
|
676
|
+
if ((this.user as any).id === doc.owner.id) {
|
|
677
|
+
subdirs[subdir].ownedIds.push(doc.id)
|
|
678
|
+
subdirs[subdir].row[9] = deleteFolderCell({
|
|
679
|
+
subdir,
|
|
680
|
+
ids: subdirs[subdir].ownedIds
|
|
681
|
+
})
|
|
682
|
+
}
|
|
683
|
+
return false
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
const ownedIds = (this.user as any).id === doc.owner.id ? [doc.id] : []
|
|
687
|
+
const row = [
|
|
688
|
+
"0",
|
|
689
|
+
"folder",
|
|
690
|
+
null,
|
|
691
|
+
`<a class="fw-data-table-title fw-link-text subdir" href="/documents${encodeURI(this.path + subdir)}/" data-path="${this.path}${subdir}/">
|
|
692
|
+
<i class="fa-solid fa-folder"></i>
|
|
693
|
+
<span>${escapeText(subdir)}</span>
|
|
694
|
+
</a>`,
|
|
695
|
+
"",
|
|
696
|
+
dateCell({date: doc.added}),
|
|
697
|
+
dateCell({date: doc.updated}),
|
|
698
|
+
"",
|
|
699
|
+
"",
|
|
700
|
+
ownedIds.length ? deleteFolderCell({subdir, ids: ownedIds}) : ""
|
|
701
|
+
]
|
|
702
|
+
subdirs[subdir] = {
|
|
703
|
+
row,
|
|
704
|
+
added: doc.added,
|
|
705
|
+
updated: doc.updated,
|
|
706
|
+
ownedIds
|
|
707
|
+
}
|
|
708
|
+
return row
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
let displayTitle = doc.title
|
|
712
|
+
let hasDecryptedTitle = false
|
|
713
|
+
if (doc.e2ee) {
|
|
714
|
+
const cachedTitle = sessionStorage.getItem(`e2ee_title_${doc.id}`)
|
|
715
|
+
if (cachedTitle !== null) {
|
|
716
|
+
displayTitle = cachedTitle
|
|
717
|
+
hasDecryptedTitle = true
|
|
718
|
+
} else if (doc.title) {
|
|
719
|
+
displayTitle = gettext("Encrypted Document")
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
return [
|
|
724
|
+
String(doc.id),
|
|
725
|
+
"file",
|
|
726
|
+
false,
|
|
727
|
+
`<a class="fw-data-table-title fw-link-text" href="/document/${doc.id}" data-id="${doc.id}">
|
|
728
|
+
${doc.e2ee ? '<i class="fa-solid fa-lock e2ee-doc-indicator" title="' + gettext("End-to-end encrypted document") + '"></i>' : '<i class="fa-regular fa-file-alt"></i>'}
|
|
729
|
+
<span class="fw-searchable${doc.e2ee && !hasDecryptedTitle ? " e2ee-encrypted-title" : ""}">
|
|
730
|
+
${shortFileTitle(displayTitle, doc.path)}
|
|
731
|
+
</span>
|
|
732
|
+
${doc.template ? `<small class="doc-template-name">${escapeText(doc.template)}</small>` : ""}
|
|
733
|
+
</a>`,
|
|
734
|
+
doc.revisions.length
|
|
735
|
+
? `<span class="revisions" data-id="${doc.id}">
|
|
736
|
+
<i class="fa-solid fa-history"></i>
|
|
737
|
+
</span>`
|
|
738
|
+
: "",
|
|
739
|
+
dateCell({date: doc.added}),
|
|
740
|
+
dateCell({date: doc.updated}),
|
|
741
|
+
`<span>
|
|
742
|
+
${avatarTemplate({user: doc.owner})}
|
|
743
|
+
</span>
|
|
744
|
+
<span class="fw-searchable">${escapeText(doc.owner.name)}</span>`,
|
|
745
|
+
`<span class="${doc.is_owner ? "document-settings fw-link-text" : "rights"}" data-id="${doc.id}" title="${doc.rights}">
|
|
746
|
+
${doc.is_owner ? '<i class="fa-solid fa-cog"></i>' : `<i data-id="${doc.id}" class="fw-icon-access-right icon-access-${doc.rights}"></i>`}
|
|
747
|
+
</span>`,
|
|
748
|
+
`<span class="delete-document fw-link-text" data-id="${doc.id}"
|
|
749
|
+
data-title="${escapeText(currentPath)}">
|
|
750
|
+
${
|
|
751
|
+
(this.user as any).id === doc.owner.id
|
|
752
|
+
? '<i class="fa-solid fa-trash-alt"></i>'
|
|
753
|
+
: ""
|
|
754
|
+
}
|
|
755
|
+
</span>`
|
|
756
|
+
]
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
multipleNewDocumentMenuItem(): void {
|
|
760
|
+
const menuItem = this.menu.model.content.find(
|
|
761
|
+
(menuItem: any) => menuItem.id === "new_document"
|
|
762
|
+
)
|
|
763
|
+
menuItem.type = "dropdown"
|
|
764
|
+
menuItem.content = Object.values(this.documentTemplates).map(
|
|
765
|
+
docTemplate => ({
|
|
766
|
+
title: docTemplate.title || gettext("Undefined"),
|
|
767
|
+
action: () => this.goToNewDocument(`n${docTemplate.id}`)
|
|
768
|
+
})
|
|
769
|
+
)
|
|
770
|
+
this.menu.update()
|
|
771
|
+
|
|
772
|
+
if (this.dtBulkModel.content.find((item: any) => item.id === "copy_as")) {
|
|
773
|
+
return
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
this.dtBulkModel.content.push({
|
|
777
|
+
id: "copy_as",
|
|
778
|
+
title: gettext("Copy selected as..."),
|
|
779
|
+
tooltip: gettext(
|
|
780
|
+
"Copy the documents and assign them to a specific template."
|
|
781
|
+
),
|
|
782
|
+
action: (overview: DocumentOverview) => {
|
|
783
|
+
const ids = overview.getSelected()
|
|
784
|
+
if (ids.length) {
|
|
785
|
+
overview.mod.actions!.copyFilesAs(ids)
|
|
786
|
+
}
|
|
787
|
+
},
|
|
788
|
+
disabled: (overview: DocumentOverview) =>
|
|
789
|
+
!overview.getSelected().length || overview.app.isOffline(),
|
|
790
|
+
order: 2.5
|
|
791
|
+
})
|
|
792
|
+
|
|
793
|
+
this.dtBulk!.update()
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
singleNewDocumentMenuItem(): void {
|
|
797
|
+
const menuItem = this.menu.model.content.find(
|
|
798
|
+
(menuItem: any) => menuItem.id === "new_document"
|
|
799
|
+
)
|
|
800
|
+
if (menuItem.type === "text") {
|
|
801
|
+
return
|
|
802
|
+
}
|
|
803
|
+
menuItem.type = "text"
|
|
804
|
+
delete menuItem.content
|
|
805
|
+
this.menu.update()
|
|
806
|
+
|
|
807
|
+
this.dtBulkModel.content = this.dtBulkModel.content.filter(
|
|
808
|
+
(item: any) => item.id !== "copy_as"
|
|
809
|
+
)
|
|
810
|
+
this.dtBulk!.update()
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
getSelected(): number[] {
|
|
814
|
+
return Array.from(
|
|
815
|
+
document.querySelectorAll(".entry-select:checked:not(:disabled)")
|
|
816
|
+
).map(el => Number.parseInt((el as HTMLElement).getAttribute("data-id")!))
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
goToNewDocument(id: string): void {
|
|
820
|
+
let url = `/document${this.path}${id}`
|
|
821
|
+
if (this.app.settings.E2EE_MODE === "required") {
|
|
822
|
+
url += "?e2ee=true"
|
|
823
|
+
this.app.goTo(url)
|
|
824
|
+
} else if (this.app.settings.E2EE_MODE === "disabled") {
|
|
825
|
+
this.app.goTo(url)
|
|
826
|
+
} else {
|
|
827
|
+
const encryptedInfoBody = `
|
|
828
|
+
<p class="e2ee-choice-intro">${gettext("Encrypted documents protect your content so that only people with the password can read it.")}</p>
|
|
829
|
+
<strong>${gettext("Advantages")}</strong>
|
|
830
|
+
<ul>
|
|
831
|
+
<li>${gettext("Only people with the password can read the document.")}</li>
|
|
832
|
+
<li>${gettext("The server cannot access the document contents.")}</li>
|
|
833
|
+
</ul>
|
|
834
|
+
<strong>${gettext("Disadvantages")}</strong>
|
|
835
|
+
<ul>
|
|
836
|
+
<li>${gettext("Limited access rights options (no tracked changes or review modes).")}</li>
|
|
837
|
+
<li>${gettext("If you lose the password or passphrase, there is no way to recover the document.")}</li>
|
|
838
|
+
<li>${gettext("You must share the password with collaborators manually (unless they use a personal passphrase).")}</li>
|
|
839
|
+
</ul>
|
|
840
|
+
`
|
|
841
|
+
const regularInfoBody = `
|
|
842
|
+
<p class="e2ee-choice-intro">${gettext("Regular documents are the default and work well for most users.")}</p>
|
|
843
|
+
<strong>${gettext("Advantages")}</strong>
|
|
844
|
+
<ul>
|
|
845
|
+
<li>${gettext("Full access rights options including tracked changes and review modes.")}</li>
|
|
846
|
+
<li>${gettext("No risk of losing access if you forget a password.")}</li>
|
|
847
|
+
<li>${gettext("Easier collaboration — no need to share passwords with collaborators.")}</li>
|
|
848
|
+
</ul>
|
|
849
|
+
<strong>${gettext("Disadvantages")}</strong>
|
|
850
|
+
<ul>
|
|
851
|
+
<li>${gettext("The server can technically access the document contents.")}</li>
|
|
852
|
+
<li>${gettext("No additional protection beyond your account password.")}</li>
|
|
853
|
+
</ul>
|
|
854
|
+
`
|
|
855
|
+
const dialog = new Dialog({
|
|
856
|
+
title: gettext("Choose encryption type of new document."),
|
|
857
|
+
width: 460,
|
|
858
|
+
body: `<div>
|
|
859
|
+
<div>
|
|
860
|
+
<input type="radio" id="nonencrypted" name="encryption" value="nonencrypted" checked>
|
|
861
|
+
<label for="nonencrypted">${gettext("Non-encrypted")}</label>
|
|
862
|
+
</div>
|
|
863
|
+
<div> </div>
|
|
864
|
+
<div>
|
|
865
|
+
<input type="radio" id="e2ee" name="encryption" value="e2ee">
|
|
866
|
+
<label for="e2ee">${gettext("Encrypted")}</label>
|
|
867
|
+
</div>
|
|
868
|
+
<div id="e2ee-info-regular" class="e2ee-choice-info">
|
|
869
|
+
${regularInfoBody}
|
|
870
|
+
</div>
|
|
871
|
+
<div id="e2ee-info-encrypted" class="e2ee-choice-info" style="display: none;">
|
|
872
|
+
${encryptedInfoBody}
|
|
873
|
+
</div>
|
|
874
|
+
</div>`,
|
|
875
|
+
buttons: [
|
|
876
|
+
{text: gettext("Cancel"), type: "cancel"},
|
|
877
|
+
{
|
|
878
|
+
text: gettext("Create"),
|
|
879
|
+
type: "ok",
|
|
880
|
+
click: async (_event: Event) => {
|
|
881
|
+
const e2ee =
|
|
882
|
+
(document.querySelector(
|
|
883
|
+
'input[name="encryption"]:checked'
|
|
884
|
+
) as HTMLInputElement)?.value === "e2ee"
|
|
885
|
+
dialog.close()
|
|
886
|
+
|
|
887
|
+
if (e2ee) {
|
|
888
|
+
const {PassphraseManager} = await import(
|
|
889
|
+
"fwtoolkit/e2ee/passphrase-manager"
|
|
890
|
+
)
|
|
891
|
+
const hasPassphraseKeys =
|
|
892
|
+
await PassphraseManager.hasEncryptionKeys()
|
|
893
|
+
const hasDismissed =
|
|
894
|
+
await PassphraseManager.hasUserDismissedPassphraseOffer()
|
|
895
|
+
|
|
896
|
+
if (!hasPassphraseKeys && !hasDismissed) {
|
|
897
|
+
const {setupPassphraseDialog} = await import(
|
|
898
|
+
"fwtoolkit/e2ee/passphrase-dialog"
|
|
899
|
+
)
|
|
900
|
+
const setupConfirmed = await new Promise<boolean>(
|
|
901
|
+
resolve => {
|
|
902
|
+
const setupDialog = new Dialog({
|
|
903
|
+
title: gettext("Set Up Personal Encryption (Optional)"),
|
|
904
|
+
body: `<p>${gettext("Would you like to set up a personal passphrase now? This will allow you to unlock all your encrypted documents with a single passphrase.")}</p>
|
|
905
|
+
<p><strong>${gettext("Note:")}</strong> ${gettext("This is optional. You can also use a per-document password instead.")}</p>`,
|
|
906
|
+
buttons: [
|
|
907
|
+
{
|
|
908
|
+
text: gettext("Skip for Now"),
|
|
909
|
+
type: "cancel",
|
|
910
|
+
click: async () => {
|
|
911
|
+
setupDialog.close()
|
|
912
|
+
await PassphraseManager.markPassphraseDismissed()
|
|
913
|
+
resolve(false)
|
|
914
|
+
}
|
|
915
|
+
},
|
|
916
|
+
{
|
|
917
|
+
text: gettext("Set Up Passphrase"),
|
|
918
|
+
type: "ok",
|
|
919
|
+
click: () => {
|
|
920
|
+
setupDialog.close()
|
|
921
|
+
resolve(true)
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
]
|
|
925
|
+
} as any)
|
|
926
|
+
setupDialog.open()
|
|
927
|
+
}
|
|
928
|
+
)
|
|
929
|
+
|
|
930
|
+
if (setupConfirmed) {
|
|
931
|
+
await setupPassphraseDialog(
|
|
932
|
+
async (passphrase: string) => {
|
|
933
|
+
try {
|
|
934
|
+
const {recoveryKey} =
|
|
935
|
+
await PassphraseManager.setupEncryption(
|
|
936
|
+
passphrase
|
|
937
|
+
)
|
|
938
|
+
const {showRecoveryKeyDialog} =
|
|
939
|
+
await import(
|
|
940
|
+
"fwtoolkit/e2ee/passphrase-dialog"
|
|
941
|
+
)
|
|
942
|
+
// @ts-ignore
|
|
943
|
+
await showRecoveryKeyDialog(
|
|
944
|
+
recoveryKey
|
|
945
|
+
)
|
|
946
|
+
} catch (e: any) {
|
|
947
|
+
addAlert(
|
|
948
|
+
"error",
|
|
949
|
+
gettext(
|
|
950
|
+
"Failed to set up passphrase: " +
|
|
951
|
+
e.message
|
|
952
|
+
)
|
|
953
|
+
)
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
)
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
url += "?e2ee=true"
|
|
961
|
+
}
|
|
962
|
+
this.app.goTo(url)
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
]
|
|
966
|
+
} as any)
|
|
967
|
+
dialog.open()
|
|
968
|
+
setTimeout(() => {
|
|
969
|
+
const nonencryptedRadio = document.getElementById("nonencrypted")
|
|
970
|
+
const e2eeRadio = document.getElementById("e2ee")
|
|
971
|
+
const regularInfo = document.getElementById("e2ee-info-regular")
|
|
972
|
+
const encryptedInfo = document.getElementById("e2ee-info-encrypted")
|
|
973
|
+
if (nonencryptedRadio && e2eeRadio && regularInfo && encryptedInfo) {
|
|
974
|
+
const toggleInfo = () => {
|
|
975
|
+
if ((e2eeRadio as HTMLInputElement).checked) {
|
|
976
|
+
regularInfo.style.display = "none"
|
|
977
|
+
encryptedInfo.style.display = "block"
|
|
978
|
+
} else {
|
|
979
|
+
regularInfo.style.display = "block"
|
|
980
|
+
encryptedInfo.style.display = "none"
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
nonencryptedRadio.addEventListener("change", toggleInfo)
|
|
984
|
+
e2eeRadio.addEventListener("change", toggleInfo)
|
|
985
|
+
}
|
|
986
|
+
}, 100)
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
close(): void {
|
|
991
|
+
if (!this.active) {
|
|
992
|
+
return
|
|
993
|
+
}
|
|
994
|
+
if (this.overviewTable) {
|
|
995
|
+
this.overviewTable.destroy()
|
|
996
|
+
this.overviewTable = null
|
|
997
|
+
}
|
|
998
|
+
this.table = null
|
|
999
|
+
this.dtBulk = null
|
|
1000
|
+
if (this.menu) {
|
|
1001
|
+
this.menu.destroy()
|
|
1002
|
+
this.menu = null
|
|
1003
|
+
}
|
|
1004
|
+
this.active = false
|
|
1005
|
+
}
|
|
1006
|
+
}
|