@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,1031 @@
|
|
|
1
|
+
import {AccessRightsTab} from "@fiduswriter/editor/documents/access_rights/index"
|
|
2
|
+
import {ExportFidusFile, SaveCopy} from "@fiduswriter/editor/exporter/native/index"
|
|
3
|
+
import {
|
|
4
|
+
Dialog,
|
|
5
|
+
DialogTabs,
|
|
6
|
+
activateWait,
|
|
7
|
+
addAlert,
|
|
8
|
+
addProgress,
|
|
9
|
+
deactivateWait,
|
|
10
|
+
escapeText,
|
|
11
|
+
longFilePath,
|
|
12
|
+
postJson,
|
|
13
|
+
shortFileTitle
|
|
14
|
+
} from "fwtoolkit"
|
|
15
|
+
import {E2EEKeyManager} from "fwtoolkit/e2ee/key-manager"
|
|
16
|
+
import {enterPassphraseDialog} from "fwtoolkit/e2ee/passphrase-dialog"
|
|
17
|
+
import {PassphraseManager} from "fwtoolkit/e2ee/passphrase-manager"
|
|
18
|
+
import {createPasswordDialog, enterPasswordDialog} from "fwtoolkit/e2ee/password-dialog"
|
|
19
|
+
|
|
20
|
+
import type {DocumentOverview} from "./index.js"
|
|
21
|
+
import {documentDialogTemplate, importDocumentTemplate} from "./templates.js"
|
|
22
|
+
|
|
23
|
+
const exportProgressCallback = (doc: Record<string, unknown>) => {
|
|
24
|
+
const title = shortFileTitle(doc.title as string, (doc.path as string) || "")
|
|
25
|
+
const task = addProgress("info", `${title}: ${gettext("Exporting...")}`, {
|
|
26
|
+
autoClose: 6000
|
|
27
|
+
})
|
|
28
|
+
return (message: string, percentage: number) => task.update(percentage, message)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const getDisplayTitle = (doc: Record<string, unknown>): string => {
|
|
32
|
+
if (doc.e2ee) {
|
|
33
|
+
const cached = sessionStorage.getItem(`e2ee_title_${doc.id}`)
|
|
34
|
+
if (cached !== null) {
|
|
35
|
+
return cached
|
|
36
|
+
}
|
|
37
|
+
if (doc.title) {
|
|
38
|
+
return gettext("Encrypted Document")
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return (doc.title as string) || ""
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class DocumentOverviewActions {
|
|
45
|
+
documentOverview: DocumentOverview
|
|
46
|
+
dialogParts: Array<{
|
|
47
|
+
title: string
|
|
48
|
+
description: string
|
|
49
|
+
template: (params: {doc: Record<string, unknown>}) => string
|
|
50
|
+
}>
|
|
51
|
+
onSave: Array<(doc: Record<string, unknown>) => Promise<void>>
|
|
52
|
+
accessRightsTab: any
|
|
53
|
+
accessRightsLoading: boolean
|
|
54
|
+
|
|
55
|
+
constructor(documentOverview: DocumentOverview) {
|
|
56
|
+
documentOverview.mod.actions = this
|
|
57
|
+
this.documentOverview = documentOverview
|
|
58
|
+
this.dialogParts = []
|
|
59
|
+
this.onSave = []
|
|
60
|
+
this.accessRightsTab = null
|
|
61
|
+
this.accessRightsLoading = false
|
|
62
|
+
|
|
63
|
+
this.dialogParts.push({
|
|
64
|
+
title: gettext("Access Rights"),
|
|
65
|
+
description: gettext("Share your document with others"),
|
|
66
|
+
template: ({doc}) => {
|
|
67
|
+
if (
|
|
68
|
+
!this.accessRightsLoading &&
|
|
69
|
+
(!this.accessRightsTab ||
|
|
70
|
+
this.accessRightsTab.documentIds[0] !== doc.id)
|
|
71
|
+
) {
|
|
72
|
+
this.loadAccessRightsTab(doc)
|
|
73
|
+
}
|
|
74
|
+
if (this.accessRightsLoading) {
|
|
75
|
+
return `<div id="access-rights-settings-tab"><table class="fw-dialog-table"><tr><th></th><td><i class="fa fa-spinner fa-pulse"></i> ${gettext("Loading access rights…")}</td></tr></table></div>`
|
|
76
|
+
}
|
|
77
|
+
return `<div id="access-rights-settings-tab">${this.accessRightsTab.render()}</div>`
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
this.onSave.push(doc => {
|
|
82
|
+
if (
|
|
83
|
+
this.accessRightsTab &&
|
|
84
|
+
this.accessRightsTab.documentIds[0] === doc.id
|
|
85
|
+
) {
|
|
86
|
+
return this.accessRightsTab.submit()
|
|
87
|
+
}
|
|
88
|
+
return Promise.resolve()
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
loadAccessRightsTab(doc: Record<string, unknown>): void {
|
|
93
|
+
this.accessRightsLoading = true
|
|
94
|
+
this.accessRightsTab = new AccessRightsTab({
|
|
95
|
+
documentIds: [doc.id as number],
|
|
96
|
+
contacts: this.documentOverview.contacts as any,
|
|
97
|
+
newContactCall: ((memberDetails: Record<string, unknown>) =>
|
|
98
|
+
this.documentOverview.contacts.push(memberDetails as any)) as any,
|
|
99
|
+
e2ee: doc.e2ee as boolean,
|
|
100
|
+
settings: this.documentOverview.app.settings
|
|
101
|
+
})
|
|
102
|
+
this.accessRightsTab
|
|
103
|
+
.load()
|
|
104
|
+
.then(() => {
|
|
105
|
+
this.accessRightsLoading = false
|
|
106
|
+
const container = document.querySelector("#access-rights-settings-tab")
|
|
107
|
+
if (container) {
|
|
108
|
+
this.accessRightsTab.container = container
|
|
109
|
+
this.accessRightsTab.render()
|
|
110
|
+
this.accessRightsTab.bindEvents()
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
.catch(() => {
|
|
114
|
+
this.accessRightsLoading = false
|
|
115
|
+
const container = document.querySelector("#access-rights-settings-tab")
|
|
116
|
+
if (container) {
|
|
117
|
+
container.innerHTML = `<p class="fw-ar-error">${gettext("Could not load access rights.")}</p>`
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
deleteDocument(id: number): Promise<void> {
|
|
123
|
+
const doc = this.documentOverview.documentList.find(d => d.id === id)
|
|
124
|
+
if (!doc) {
|
|
125
|
+
return Promise.resolve()
|
|
126
|
+
}
|
|
127
|
+
const displayTitle = getDisplayTitle(doc)
|
|
128
|
+
return postJson("/api/document/delete/", {id}).then(({json}) => {
|
|
129
|
+
if ((json as any).done) {
|
|
130
|
+
addAlert(
|
|
131
|
+
"success",
|
|
132
|
+
`${gettext("Document has been deleted")}: '${escapeText(longFilePath(displayTitle, doc.path))}'`
|
|
133
|
+
)
|
|
134
|
+
this.documentOverview.documentList =
|
|
135
|
+
this.documentOverview.documentList.filter(d => d.id !== id)
|
|
136
|
+
this.documentOverview.initTable()
|
|
137
|
+
} else {
|
|
138
|
+
addAlert(
|
|
139
|
+
"error",
|
|
140
|
+
`${gettext("Could not delete document")}: '${escapeText(longFilePath(displayTitle, doc.path))}'`
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
deleteDocumentDialog(ids: number[], app: any): void {
|
|
147
|
+
if (app.isOffline()) {
|
|
148
|
+
addAlert(
|
|
149
|
+
"info",
|
|
150
|
+
gettext("You cannot delete a document while you are offline.")
|
|
151
|
+
)
|
|
152
|
+
return
|
|
153
|
+
}
|
|
154
|
+
const docPaths = ids.map(id => {
|
|
155
|
+
const doc = this.documentOverview.documentList.find(d => d.id === id)!
|
|
156
|
+
return escapeText(longFilePath(getDisplayTitle(doc), doc.path))
|
|
157
|
+
})
|
|
158
|
+
const confirmDeletionDialog = new Dialog({
|
|
159
|
+
title: gettext("Confirm deletion"),
|
|
160
|
+
body: `<p>
|
|
161
|
+
${
|
|
162
|
+
ids.length > 1
|
|
163
|
+
? gettext("Do you really want to delete the following documents?")
|
|
164
|
+
: gettext("Do you really want to delete the following document?")
|
|
165
|
+
}
|
|
166
|
+
</p>
|
|
167
|
+
<p>
|
|
168
|
+
${docPaths.join("<br>")}
|
|
169
|
+
</p>`,
|
|
170
|
+
id: "confirmdeletion",
|
|
171
|
+
icon: "exclamation-triangle",
|
|
172
|
+
buttons: [
|
|
173
|
+
{
|
|
174
|
+
text: gettext("Delete"),
|
|
175
|
+
classes: "fw-dark",
|
|
176
|
+
click: () => {
|
|
177
|
+
Promise.all(
|
|
178
|
+
ids.map(id => this.deleteDocument(id))
|
|
179
|
+
).then(() => {
|
|
180
|
+
confirmDeletionDialog.close()
|
|
181
|
+
this.documentOverview.initTable()
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
type: "cancel"
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
} as any)
|
|
190
|
+
|
|
191
|
+
confirmDeletionDialog.open()
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async importDocument(): Promise<void> {
|
|
195
|
+
const documentTemplates = this.documentOverview.documentTemplates || {}
|
|
196
|
+
const importIds = Object.keys(documentTemplates)
|
|
197
|
+
let importId = importIds[0]
|
|
198
|
+
|
|
199
|
+
const templateSelector =
|
|
200
|
+
importIds.length > 1
|
|
201
|
+
? `<label for="import-template-selector">${gettext("Import as:")}</label>
|
|
202
|
+
<div class="fw-select-container">
|
|
203
|
+
<select class="fw-button fw-light fw-large" id="import-template-selector">
|
|
204
|
+
${Object.entries(documentTemplates)
|
|
205
|
+
.map(
|
|
206
|
+
([key, template]) =>
|
|
207
|
+
`<option value="${escapeText(key)}">${escapeText(template.title as string)}</option>`
|
|
208
|
+
)
|
|
209
|
+
.join("")}
|
|
210
|
+
</select>
|
|
211
|
+
<div class="fw-select-arrow fa-solid fa-caret-down"></div>
|
|
212
|
+
</div>`
|
|
213
|
+
: ""
|
|
214
|
+
|
|
215
|
+
const e2eeMode = this.documentOverview.app.settings.E2EE_MODE as string
|
|
216
|
+
const hasPassphrase = this.documentOverview.hasPassphraseSetUp ?? false
|
|
217
|
+
|
|
218
|
+
if (e2eeMode === "required" && !hasPassphrase) {
|
|
219
|
+
addAlert(
|
|
220
|
+
"warning",
|
|
221
|
+
gettext(
|
|
222
|
+
"You need to set up a personal passphrase before you can import documents."
|
|
223
|
+
)
|
|
224
|
+
)
|
|
225
|
+
return
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
let e2eeHtml = ""
|
|
229
|
+
let forceE2EE = false
|
|
230
|
+
if (e2eeMode === "required") {
|
|
231
|
+
forceE2EE = true
|
|
232
|
+
e2eeHtml = `<div class="e2ee-import-note" style="margin-top: 10px;">
|
|
233
|
+
<em>${gettext("This document will be saved as encrypted.")}</em>
|
|
234
|
+
</div>`
|
|
235
|
+
} else if (e2eeMode === "enabled" && hasPassphrase) {
|
|
236
|
+
e2eeHtml = `<div class="e2ee-import-choice" style="margin-top: 10px;">
|
|
237
|
+
<div>
|
|
238
|
+
<input type="radio" id="import-nonencrypted" name="import-encryption" value="nonencrypted" checked>
|
|
239
|
+
<label for="import-nonencrypted">${gettext("Non-encrypted")}</label>
|
|
240
|
+
</div>
|
|
241
|
+
<div>
|
|
242
|
+
<input type="radio" id="import-e2ee" name="import-encryption" value="e2ee">
|
|
243
|
+
<label for="import-e2ee">${gettext("Encrypted")}</label>
|
|
244
|
+
</div>
|
|
245
|
+
</div>`
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const {importerRegistry} = await import("../importer/register.js")
|
|
249
|
+
const supportedDescriptions = Object.entries(
|
|
250
|
+
importerRegistry.getAllDescriptions() as Record<string, string[]>
|
|
251
|
+
)
|
|
252
|
+
.map(
|
|
253
|
+
([description, extensions]) =>
|
|
254
|
+
`${description} (${(extensions as string[]).join(", ")})`
|
|
255
|
+
)
|
|
256
|
+
.join("<br>")
|
|
257
|
+
const supportedFormatsText = `${gettext("Supported formats")}:<p>FIDUS<br>${supportedDescriptions}</p><p>${gettext("You can also upload a ZIP file that contains one file in any of these formats as well as images and/or bibtex file.")}</p>`
|
|
258
|
+
|
|
259
|
+
const {FidusFileImporter} = await import("../importer/native/file.js")
|
|
260
|
+
|
|
261
|
+
const importDialog = new Dialog({
|
|
262
|
+
id: "import_document",
|
|
263
|
+
title: gettext("Import a document"),
|
|
264
|
+
body: importDocumentTemplate({
|
|
265
|
+
templateSelector,
|
|
266
|
+
e2eeHtml,
|
|
267
|
+
supportedFormatsText
|
|
268
|
+
}),
|
|
269
|
+
height: (importIds.length > 1 ? 260 : 210) + (e2eeHtml ? 60 : 0),
|
|
270
|
+
buttons: [
|
|
271
|
+
{
|
|
272
|
+
text: gettext("Import"),
|
|
273
|
+
classes: "fw-dark",
|
|
274
|
+
click: async () => {
|
|
275
|
+
const file: File | null = (document.getElementById("doc-uploader") as HTMLInputElement)?.files?.[0] || null
|
|
276
|
+
if (!file) {
|
|
277
|
+
return false
|
|
278
|
+
}
|
|
279
|
+
if (104857600 < file.size) {
|
|
280
|
+
addAlert("error", gettext("File too large"))
|
|
281
|
+
return false
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
let targetE2EE = forceE2EE
|
|
285
|
+
if (e2eeMode === "enabled" && hasPassphrase) {
|
|
286
|
+
targetE2EE =
|
|
287
|
+
(document.querySelector(
|
|
288
|
+
'input[name="import-encryption"]:checked'
|
|
289
|
+
) as HTMLInputElement)?.value === "e2ee"
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const doImport = async (e2eeOptions: any): Promise<any> => {
|
|
293
|
+
const isFidus =
|
|
294
|
+
file!.name.split(".").pop()!.toLowerCase() === "fidus"
|
|
295
|
+
|
|
296
|
+
if (isFidus) {
|
|
297
|
+
const importer = new FidusFileImporter(
|
|
298
|
+
file!,
|
|
299
|
+
this.documentOverview.user,
|
|
300
|
+
this.documentOverview.path,
|
|
301
|
+
true,
|
|
302
|
+
this.documentOverview.contacts,
|
|
303
|
+
e2eeOptions
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
try {
|
|
307
|
+
const {ok, statusText, doc} = await (importer as any).init()
|
|
308
|
+
deactivateWait()
|
|
309
|
+
if (ok) {
|
|
310
|
+
addAlert("info", statusText)
|
|
311
|
+
} else {
|
|
312
|
+
addAlert("error", statusText)
|
|
313
|
+
return null
|
|
314
|
+
}
|
|
315
|
+
this.documentOverview.documentList.push(doc)
|
|
316
|
+
this.documentOverview.initTable()
|
|
317
|
+
importDialog.close()
|
|
318
|
+
return doc
|
|
319
|
+
} catch (_error) {
|
|
320
|
+
deactivateWait()
|
|
321
|
+
return null
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (importIds.length > 1) {
|
|
326
|
+
importId = (document.getElementById(
|
|
327
|
+
"import-template-selector"
|
|
328
|
+
) as HTMLSelectElement).value
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (file!.type === "application/zip") {
|
|
332
|
+
const {default: JSZip} = await import("jszip")
|
|
333
|
+
const zip = await JSZip.loadAsync(file!)
|
|
334
|
+
const importerInfo = importerRegistry.getZipImporter(zip)
|
|
335
|
+
|
|
336
|
+
if (!importerInfo) {
|
|
337
|
+
addAlert("error", gettext("No importable files found in ZIP"))
|
|
338
|
+
deactivateWait()
|
|
339
|
+
return
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const files = await importerInfo.getContents()
|
|
343
|
+
const importer = new importerInfo.importer(
|
|
344
|
+
files.mainContent,
|
|
345
|
+
this.documentOverview.user,
|
|
346
|
+
this.documentOverview.path,
|
|
347
|
+
importId,
|
|
348
|
+
{files, e2eeOptions}
|
|
349
|
+
)
|
|
350
|
+
|
|
351
|
+
const {ok, statusText, doc} = await (importer as any).init()
|
|
352
|
+
deactivateWait()
|
|
353
|
+
if (ok) {
|
|
354
|
+
addAlert("info", statusText)
|
|
355
|
+
} else {
|
|
356
|
+
addAlert("error", statusText)
|
|
357
|
+
return null
|
|
358
|
+
}
|
|
359
|
+
this.documentOverview.documentList.push(doc)
|
|
360
|
+
this.documentOverview.initTable()
|
|
361
|
+
importDialog.close()
|
|
362
|
+
return doc
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const fileExtension = file!.name.split(".").pop()!.toLowerCase()
|
|
366
|
+
const importerInfo = importerRegistry.getImporter(fileExtension)
|
|
367
|
+
|
|
368
|
+
if (!importerInfo) {
|
|
369
|
+
addAlert("error", gettext("Unsupported file format"))
|
|
370
|
+
deactivateWait()
|
|
371
|
+
return
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const options: any = {
|
|
375
|
+
bibDB: this.documentOverview.app.bibDB,
|
|
376
|
+
files: {},
|
|
377
|
+
e2eeOptions
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const importer = new importerInfo.importer(
|
|
381
|
+
file!,
|
|
382
|
+
this.documentOverview.user,
|
|
383
|
+
this.documentOverview.path,
|
|
384
|
+
importId,
|
|
385
|
+
options
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
const {ok, statusText, doc} = await (importer as any).init()
|
|
389
|
+
deactivateWait()
|
|
390
|
+
if (ok) {
|
|
391
|
+
addAlert("info", statusText)
|
|
392
|
+
} else {
|
|
393
|
+
addAlert("error", statusText)
|
|
394
|
+
return null
|
|
395
|
+
}
|
|
396
|
+
this.documentOverview.documentList.push(doc)
|
|
397
|
+
this.documentOverview.initTable()
|
|
398
|
+
importDialog.close()
|
|
399
|
+
return doc
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if (targetE2EE) {
|
|
403
|
+
activateWait()
|
|
404
|
+
|
|
405
|
+
const importWithAutoPassword = async () => {
|
|
406
|
+
const password =
|
|
407
|
+
await PassphraseManager.generateDocumentPassword()
|
|
408
|
+
const salt = window.crypto.getRandomValues(new Uint8Array(16))
|
|
409
|
+
const iterations = 600000
|
|
410
|
+
const key = await PassphraseManager.resolvePasswordToKey(
|
|
411
|
+
password,
|
|
412
|
+
salt,
|
|
413
|
+
iterations
|
|
414
|
+
)
|
|
415
|
+
const e2eeOptions = {
|
|
416
|
+
enabled: true,
|
|
417
|
+
key,
|
|
418
|
+
salt: btoa(String.fromCharCode(...salt)),
|
|
419
|
+
iterations
|
|
420
|
+
}
|
|
421
|
+
const doc = await doImport(e2eeOptions)
|
|
422
|
+
if (doc?.id) {
|
|
423
|
+
try {
|
|
424
|
+
await PassphraseManager.saveDocumentPassword(doc.id, password)
|
|
425
|
+
} catch (err) {
|
|
426
|
+
console.error(
|
|
427
|
+
"Failed to save document password for imported document:",
|
|
428
|
+
err
|
|
429
|
+
)
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if (PassphraseManager.hasKeysInSession()) {
|
|
435
|
+
try {
|
|
436
|
+
await importWithAutoPassword()
|
|
437
|
+
} catch (error) {
|
|
438
|
+
deactivateWait()
|
|
439
|
+
addAlert("error", gettext("Could not create encrypted document."))
|
|
440
|
+
console.error(error)
|
|
441
|
+
}
|
|
442
|
+
} else {
|
|
443
|
+
deactivateWait()
|
|
444
|
+
let errorMessage = ""
|
|
445
|
+
let done = false
|
|
446
|
+
while (!done) {
|
|
447
|
+
const result: any = await new Promise(resolve => {
|
|
448
|
+
enterPassphraseDialog(
|
|
449
|
+
(pwd: string) => resolve({action: "unlock", passphrase: pwd}),
|
|
450
|
+
() => resolve({action: "recover"}),
|
|
451
|
+
{errorMessage}
|
|
452
|
+
)
|
|
453
|
+
})
|
|
454
|
+
if (result?.action === "unlock" && result.passphrase) {
|
|
455
|
+
activateWait()
|
|
456
|
+
try {
|
|
457
|
+
await PassphraseManager.unlockWithPassphrase(result.passphrase)
|
|
458
|
+
await importWithAutoPassword()
|
|
459
|
+
done = true
|
|
460
|
+
} catch (err: any) {
|
|
461
|
+
deactivateWait()
|
|
462
|
+
if (err instanceof DOMException || err.name === "OperationError") {
|
|
463
|
+
errorMessage = gettext("Incorrect passphrase. Please try again.")
|
|
464
|
+
} else {
|
|
465
|
+
addAlert("error", gettext("Could not create encrypted document."))
|
|
466
|
+
console.error(err)
|
|
467
|
+
done = true
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
} else if (result?.action === "recover") {
|
|
471
|
+
const {recoverWithKeyDialog, showRecoveryKeyDialog} =
|
|
472
|
+
await import("fwtoolkit/e2ee/passphrase-dialog")
|
|
473
|
+
const recoverResult: any = await new Promise(resolve => {
|
|
474
|
+
recoverWithKeyDialog(resolve)
|
|
475
|
+
})
|
|
476
|
+
if (recoverResult) {
|
|
477
|
+
activateWait()
|
|
478
|
+
try {
|
|
479
|
+
const {newRecoveryKey} =
|
|
480
|
+
await PassphraseManager.recoverWithRecoveryKey(
|
|
481
|
+
recoverResult.recoveryKey,
|
|
482
|
+
recoverResult.newPassphrase
|
|
483
|
+
)
|
|
484
|
+
await new Promise(resolve =>
|
|
485
|
+
showRecoveryKeyDialog(newRecoveryKey, resolve as any)
|
|
486
|
+
)
|
|
487
|
+
await importWithAutoPassword()
|
|
488
|
+
done = true
|
|
489
|
+
} catch (_err) {
|
|
490
|
+
deactivateWait()
|
|
491
|
+
errorMessage = gettext(
|
|
492
|
+
"Recovery failed. Please check your recovery key and try again."
|
|
493
|
+
)
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
} else {
|
|
497
|
+
done = true
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
} else {
|
|
502
|
+
activateWait()
|
|
503
|
+
doImport(null)
|
|
504
|
+
}
|
|
505
|
+
return undefined
|
|
506
|
+
}
|
|
507
|
+
},
|
|
508
|
+
{type: "cancel"}
|
|
509
|
+
]
|
|
510
|
+
} as any)
|
|
511
|
+
importDialog.open()
|
|
512
|
+
|
|
513
|
+
const uploader = document.getElementById("doc-uploader")
|
|
514
|
+
if (uploader) {
|
|
515
|
+
uploader.addEventListener("change", () => {
|
|
516
|
+
const nameEl = document.getElementById("import-doc-name")
|
|
517
|
+
if (nameEl) {
|
|
518
|
+
nameEl.innerHTML = (uploader as HTMLInputElement).value.replace(
|
|
519
|
+
/C:\\fakepath\\/i,
|
|
520
|
+
""
|
|
521
|
+
)
|
|
522
|
+
}
|
|
523
|
+
})
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
const docBtn = document.getElementById("import-doc-btn")
|
|
527
|
+
if (docBtn) {
|
|
528
|
+
docBtn.addEventListener("click", event => {
|
|
529
|
+
;(document.getElementById("doc-uploader") as HTMLElement).click()
|
|
530
|
+
event.preventDefault()
|
|
531
|
+
})
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
copyFiles(ids: number[]): void {
|
|
536
|
+
// Use dynamic import for tools
|
|
537
|
+
import("../tools.js").then(({getMissingDocumentListData}) => {
|
|
538
|
+
getMissingDocumentListData(
|
|
539
|
+
ids,
|
|
540
|
+
this.documentOverview.documentList as any,
|
|
541
|
+
this.documentOverview.schema,
|
|
542
|
+
null as any // using original postJson-based version for now
|
|
543
|
+
).then(() => {
|
|
544
|
+
ids.forEach(id => {
|
|
545
|
+
const doc = this.documentOverview.documentList.find(
|
|
546
|
+
entry => entry.id === id
|
|
547
|
+
)
|
|
548
|
+
if (!doc) return
|
|
549
|
+
const copier = new SaveCopy(
|
|
550
|
+
doc,
|
|
551
|
+
{db: doc.bibliography as any},
|
|
552
|
+
{db: doc.images as any},
|
|
553
|
+
this.documentOverview.user as any
|
|
554
|
+
)
|
|
555
|
+
|
|
556
|
+
copier
|
|
557
|
+
.init()
|
|
558
|
+
.then(({doc: newDoc}: any) => {
|
|
559
|
+
this.documentOverview.documentList.push(newDoc)
|
|
560
|
+
this.documentOverview.initTable()
|
|
561
|
+
})
|
|
562
|
+
.catch(() => false)
|
|
563
|
+
})
|
|
564
|
+
})
|
|
565
|
+
})
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
copyFilesAs(ids: number[]): void {
|
|
569
|
+
import("../tools.js").then(({getMissingDocumentListData}) => {
|
|
570
|
+
getMissingDocumentListData(
|
|
571
|
+
ids,
|
|
572
|
+
this.documentOverview.documentList as any,
|
|
573
|
+
this.documentOverview.schema,
|
|
574
|
+
null as any
|
|
575
|
+
).then(() => {
|
|
576
|
+
const docs = ids.map(id =>
|
|
577
|
+
this.documentOverview.documentList.find(entry => entry.id === id)
|
|
578
|
+
)
|
|
579
|
+
const allE2EE = docs.every(doc => doc?.e2ee)
|
|
580
|
+
const anyE2EE = docs.some(doc => doc?.e2ee)
|
|
581
|
+
const e2eeMode = this.documentOverview.app.settings.E2EE_MODE as string
|
|
582
|
+
|
|
583
|
+
const canToggleE2EE =
|
|
584
|
+
e2eeMode === "enabled" ||
|
|
585
|
+
(e2eeMode === "required" && !allE2EE) ||
|
|
586
|
+
(e2eeMode === "disabled" && anyE2EE)
|
|
587
|
+
|
|
588
|
+
let e2eeHtml = ""
|
|
589
|
+
if (canToggleE2EE) {
|
|
590
|
+
const checked = e2eeMode === "required" || allE2EE ? "checked" : ""
|
|
591
|
+
e2eeHtml = `
|
|
592
|
+
<div class="e2ee-copy-toggle" style="margin-top: 15px;">
|
|
593
|
+
<label>
|
|
594
|
+
<input type="checkbox" id="e2ee-copy-toggle" ${checked}>
|
|
595
|
+
${gettext("Encrypt the copy")}
|
|
596
|
+
</label>
|
|
597
|
+
</div>
|
|
598
|
+
`
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
const selectTemplateDialog = new Dialog({
|
|
602
|
+
title: gettext("Choose document template"),
|
|
603
|
+
body: `<p>
|
|
604
|
+
${ids.length > 1 ? gettext("Select document template for copies") : gettext("Select document template for copy.")}
|
|
605
|
+
</p>
|
|
606
|
+
<select class="fw-button fw-large fw-light">${Object.entries(
|
|
607
|
+
this.documentOverview.documentTemplates
|
|
608
|
+
)
|
|
609
|
+
.map(
|
|
610
|
+
([importId, dt]) =>
|
|
611
|
+
`<option value="${escapeText(importId)}">${escapeText(dt.title as string)}</option>`
|
|
612
|
+
)
|
|
613
|
+
.join("")}</select>
|
|
614
|
+
${e2eeHtml}`,
|
|
615
|
+
buttons: [
|
|
616
|
+
{
|
|
617
|
+
text: gettext("Copy"),
|
|
618
|
+
classes: "fw-dark",
|
|
619
|
+
click: () => {
|
|
620
|
+
const targetE2EE =
|
|
621
|
+
canToggleE2EE &&
|
|
622
|
+
(selectTemplateDialog.dialogEl.querySelector(
|
|
623
|
+
"#e2ee-copy-toggle"
|
|
624
|
+
) as HTMLInputElement)?.checked
|
|
625
|
+
|
|
626
|
+
const doCopy = (sourceKey: any, targetPassword: string | null) => {
|
|
627
|
+
ids.forEach(id => {
|
|
628
|
+
const doc = this.documentOverview.documentList.find(
|
|
629
|
+
entry => entry.id === id
|
|
630
|
+
)
|
|
631
|
+
if (!doc) return
|
|
632
|
+
const e2eeOptions: any = {}
|
|
633
|
+
if (doc.e2ee && sourceKey) {
|
|
634
|
+
e2eeOptions.sourceKey = sourceKey
|
|
635
|
+
}
|
|
636
|
+
if (targetE2EE && targetPassword) {
|
|
637
|
+
e2eeOptions.targetE2EE = true
|
|
638
|
+
e2eeOptions.targetPassword = targetPassword
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
const copier = new SaveCopy(
|
|
642
|
+
doc,
|
|
643
|
+
{db: doc.bibliography as any},
|
|
644
|
+
{db: doc.images as any},
|
|
645
|
+
this.documentOverview.user as any,
|
|
646
|
+
(selectTemplateDialog.dialogEl.querySelector(
|
|
647
|
+
"select"
|
|
648
|
+
) as HTMLSelectElement).value,
|
|
649
|
+
e2eeOptions
|
|
650
|
+
)
|
|
651
|
+
|
|
652
|
+
copier
|
|
653
|
+
.init()
|
|
654
|
+
.then(({doc: newDoc}: any) => {
|
|
655
|
+
this.documentOverview.documentList.push(newDoc)
|
|
656
|
+
this.documentOverview.initTable()
|
|
657
|
+
})
|
|
658
|
+
.catch((error: Error) => {
|
|
659
|
+
console.error(error)
|
|
660
|
+
addAlert("error", gettext("Could not copy document."))
|
|
661
|
+
})
|
|
662
|
+
})
|
|
663
|
+
selectTemplateDialog.close()
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
if (anyE2EE && !targetE2EE) {
|
|
667
|
+
enterPasswordDialog(async (password: string) => {
|
|
668
|
+
try {
|
|
669
|
+
const sampleDoc = docs.find(doc => doc?.e2ee)!
|
|
670
|
+
const salt = new Uint8Array(
|
|
671
|
+
atob(sampleDoc.e2ee_salt as string)
|
|
672
|
+
.split("")
|
|
673
|
+
.map(c => c.charCodeAt(0))
|
|
674
|
+
)
|
|
675
|
+
const key = await E2EEKeyManager.deriveKey(
|
|
676
|
+
password,
|
|
677
|
+
salt,
|
|
678
|
+
(sampleDoc.e2ee_iterations as number) || 600000
|
|
679
|
+
)
|
|
680
|
+
doCopy(key, null)
|
|
681
|
+
} catch (_err) {
|
|
682
|
+
addAlert("error", gettext("Incorrect password."))
|
|
683
|
+
}
|
|
684
|
+
})
|
|
685
|
+
} else if (!anyE2EE && targetE2EE) {
|
|
686
|
+
createPasswordDialog((password: string) => {
|
|
687
|
+
doCopy(null, password)
|
|
688
|
+
})
|
|
689
|
+
} else if (anyE2EE && targetE2EE) {
|
|
690
|
+
enterPasswordDialog(async (password: string) => {
|
|
691
|
+
try {
|
|
692
|
+
const sampleDoc = docs.find(doc => doc?.e2ee)!
|
|
693
|
+
const salt = new Uint8Array(
|
|
694
|
+
atob(sampleDoc.e2ee_salt as string)
|
|
695
|
+
.split("")
|
|
696
|
+
.map(c => c.charCodeAt(0))
|
|
697
|
+
)
|
|
698
|
+
const key = await E2EEKeyManager.deriveKey(
|
|
699
|
+
password,
|
|
700
|
+
salt,
|
|
701
|
+
(sampleDoc.e2ee_iterations as number) || 600000
|
|
702
|
+
)
|
|
703
|
+
createPasswordDialog((targetPassword: string) => {
|
|
704
|
+
doCopy(key, targetPassword)
|
|
705
|
+
})
|
|
706
|
+
} catch (_err) {
|
|
707
|
+
addAlert("error", gettext("Incorrect password."))
|
|
708
|
+
}
|
|
709
|
+
})
|
|
710
|
+
} else {
|
|
711
|
+
doCopy(null, null)
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
},
|
|
715
|
+
{type: "cancel"}
|
|
716
|
+
]
|
|
717
|
+
} as any)
|
|
718
|
+
selectTemplateDialog.open()
|
|
719
|
+
})
|
|
720
|
+
})
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
downloadNativeFiles(ids: number[]): void {
|
|
724
|
+
import("../tools.js").then(({getMissingDocumentListData}) => {
|
|
725
|
+
getMissingDocumentListData(
|
|
726
|
+
ids,
|
|
727
|
+
this.documentOverview.documentList as any,
|
|
728
|
+
this.documentOverview.schema,
|
|
729
|
+
null as any
|
|
730
|
+
).then(() =>
|
|
731
|
+
ids.forEach(id => {
|
|
732
|
+
const doc = this.documentOverview.documentList.find(entry => entry.id === id)
|
|
733
|
+
if (!doc) return
|
|
734
|
+
new ExportFidusFile(doc as any, {db: doc.bibliography as any}, {db: doc.images as any})
|
|
735
|
+
})
|
|
736
|
+
)
|
|
737
|
+
})
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
downloadSlimNativeFiles(ids: number[]): void {
|
|
741
|
+
import("../tools.js").then(({getMissingDocumentListData}) => {
|
|
742
|
+
getMissingDocumentListData(
|
|
743
|
+
ids,
|
|
744
|
+
this.documentOverview.documentList as any,
|
|
745
|
+
this.documentOverview.schema,
|
|
746
|
+
null as any
|
|
747
|
+
).then(() =>
|
|
748
|
+
ids.forEach(id => {
|
|
749
|
+
const doc = this.documentOverview.documentList.find(entry => entry.id === id)
|
|
750
|
+
if (!doc) return
|
|
751
|
+
new ExportFidusFile(doc as any, {db: doc.bibliography as any}, {db: doc.images as any}, false)
|
|
752
|
+
})
|
|
753
|
+
)
|
|
754
|
+
})
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
downloadHTMLFiles(ids: number[]): void {
|
|
758
|
+
import("../tools.js").then(({getMissingDocumentListData}) => {
|
|
759
|
+
getMissingDocumentListData(
|
|
760
|
+
ids,
|
|
761
|
+
this.documentOverview.documentList as any,
|
|
762
|
+
this.documentOverview.schema,
|
|
763
|
+
null as any
|
|
764
|
+
).then(() =>
|
|
765
|
+
ids.forEach(id => {
|
|
766
|
+
const doc = this.documentOverview.documentList.find(entry => entry.id === id)
|
|
767
|
+
if (!doc) return
|
|
768
|
+
const progressCallback = exportProgressCallback(doc!)
|
|
769
|
+
import("@fiduswriter/document/exporter/html/index").then(
|
|
770
|
+
({HTMLExporter}) => {
|
|
771
|
+
const exporter = new HTMLExporter(
|
|
772
|
+
doc as any,
|
|
773
|
+
{db: doc!.bibliography as any},
|
|
774
|
+
{db: doc!.images as any},
|
|
775
|
+
this.documentOverview.app.csl as any,
|
|
776
|
+
new Date((doc!.updated as number) * 1000),
|
|
777
|
+
this.documentOverview.documentStyles
|
|
778
|
+
)
|
|
779
|
+
exporter.progressCallback = progressCallback as any
|
|
780
|
+
exporter.init()
|
|
781
|
+
}
|
|
782
|
+
)
|
|
783
|
+
})
|
|
784
|
+
)
|
|
785
|
+
})
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
downloadTemplateExportFiles(
|
|
789
|
+
ids: number[],
|
|
790
|
+
templateUrl: string,
|
|
791
|
+
templateType: string
|
|
792
|
+
): void {
|
|
793
|
+
import("../tools.js").then(({getMissingDocumentListData}) => {
|
|
794
|
+
getMissingDocumentListData(
|
|
795
|
+
ids,
|
|
796
|
+
this.documentOverview.documentList as any,
|
|
797
|
+
this.documentOverview.schema,
|
|
798
|
+
null as any
|
|
799
|
+
).then(() => {
|
|
800
|
+
ids.forEach(id => {
|
|
801
|
+
const doc = this.documentOverview.documentList.find(entry => entry.id === id)
|
|
802
|
+
if (!doc) return
|
|
803
|
+
const progressCallback = exportProgressCallback(doc!)
|
|
804
|
+
if (templateType === "docx") {
|
|
805
|
+
import("@fiduswriter/document/exporter/docx/index").then(
|
|
806
|
+
({DOCXExporter}) => {
|
|
807
|
+
const exporter = new DOCXExporter(
|
|
808
|
+
doc as any,
|
|
809
|
+
templateUrl,
|
|
810
|
+
{db: doc!.bibliography as any},
|
|
811
|
+
{db: doc!.images as any},
|
|
812
|
+
this.documentOverview.app.csl as any
|
|
813
|
+
)
|
|
814
|
+
exporter.progressCallback = progressCallback as any
|
|
815
|
+
exporter.init()
|
|
816
|
+
}
|
|
817
|
+
)
|
|
818
|
+
} else {
|
|
819
|
+
import("@fiduswriter/document/exporter/odt/index").then(
|
|
820
|
+
({ODTExporter}) => {
|
|
821
|
+
const exporter = new ODTExporter(
|
|
822
|
+
doc as any,
|
|
823
|
+
templateUrl,
|
|
824
|
+
{db: doc!.bibliography as any},
|
|
825
|
+
{db: doc!.images as any},
|
|
826
|
+
this.documentOverview.app.csl as any
|
|
827
|
+
)
|
|
828
|
+
exporter.progressCallback = progressCallback as any
|
|
829
|
+
exporter.init()
|
|
830
|
+
}
|
|
831
|
+
)
|
|
832
|
+
}
|
|
833
|
+
})
|
|
834
|
+
})
|
|
835
|
+
})
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
downloadLatexFiles(ids: number[]): void {
|
|
839
|
+
import("../tools.js").then(({getMissingDocumentListData}) => {
|
|
840
|
+
getMissingDocumentListData(
|
|
841
|
+
ids,
|
|
842
|
+
this.documentOverview.documentList as any,
|
|
843
|
+
this.documentOverview.schema,
|
|
844
|
+
null as any
|
|
845
|
+
).then(() =>
|
|
846
|
+
ids.forEach(id => {
|
|
847
|
+
const doc = this.documentOverview.documentList.find(entry => entry.id === id)
|
|
848
|
+
if (!doc) return
|
|
849
|
+
const progressCallback = exportProgressCallback(doc!)
|
|
850
|
+
import("@fiduswriter/document/exporter/latex/index").then(
|
|
851
|
+
({LatexExporter}) => {
|
|
852
|
+
const exporter = new LatexExporter(
|
|
853
|
+
doc as any,
|
|
854
|
+
{db: doc!.bibliography as any},
|
|
855
|
+
{db: doc!.images as any},
|
|
856
|
+
new Date((doc!.updated as number) * 1000)
|
|
857
|
+
)
|
|
858
|
+
exporter.progressCallback = progressCallback as any
|
|
859
|
+
exporter.init()
|
|
860
|
+
}
|
|
861
|
+
)
|
|
862
|
+
})
|
|
863
|
+
)
|
|
864
|
+
})
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
downloadJATSFiles(ids: number[]): void {
|
|
868
|
+
import("../tools.js").then(({getMissingDocumentListData}) => {
|
|
869
|
+
getMissingDocumentListData(
|
|
870
|
+
ids,
|
|
871
|
+
this.documentOverview.documentList as any,
|
|
872
|
+
this.documentOverview.schema,
|
|
873
|
+
null as any
|
|
874
|
+
).then(() =>
|
|
875
|
+
ids.forEach(id => {
|
|
876
|
+
const doc = this.documentOverview.documentList.find(entry => entry.id === id)
|
|
877
|
+
if (!doc) return
|
|
878
|
+
const progressCallback = exportProgressCallback(doc!)
|
|
879
|
+
import("@fiduswriter/document/exporter/jats/index").then(
|
|
880
|
+
({JATSExporter}) => {
|
|
881
|
+
const exporter = new JATSExporter(
|
|
882
|
+
doc as any,
|
|
883
|
+
{db: doc!.bibliography as any},
|
|
884
|
+
{db: doc!.images as any},
|
|
885
|
+
this.documentOverview.app.csl as any,
|
|
886
|
+
new Date((doc!.updated as number) * 1000),
|
|
887
|
+
"article"
|
|
888
|
+
)
|
|
889
|
+
exporter.progressCallback = progressCallback as any
|
|
890
|
+
exporter.init()
|
|
891
|
+
}
|
|
892
|
+
)
|
|
893
|
+
})
|
|
894
|
+
)
|
|
895
|
+
})
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
downloadBITSFiles(ids: number[]): void {
|
|
899
|
+
import("../tools.js").then(({getMissingDocumentListData}) => {
|
|
900
|
+
getMissingDocumentListData(
|
|
901
|
+
ids,
|
|
902
|
+
this.documentOverview.documentList as any,
|
|
903
|
+
this.documentOverview.schema,
|
|
904
|
+
null as any
|
|
905
|
+
).then(() =>
|
|
906
|
+
ids.forEach(id => {
|
|
907
|
+
const doc = this.documentOverview.documentList.find(entry => entry.id === id)
|
|
908
|
+
if (!doc) return
|
|
909
|
+
const progressCallback = exportProgressCallback(doc!)
|
|
910
|
+
import("@fiduswriter/document/exporter/jats/index").then(
|
|
911
|
+
({JATSExporter}) => {
|
|
912
|
+
const exporter = new JATSExporter(
|
|
913
|
+
doc as any,
|
|
914
|
+
{db: doc!.bibliography as any},
|
|
915
|
+
{db: doc!.images as any},
|
|
916
|
+
this.documentOverview.app.csl as any,
|
|
917
|
+
new Date((doc!.updated as number) * 1000),
|
|
918
|
+
"book-part-wrapper"
|
|
919
|
+
)
|
|
920
|
+
exporter.progressCallback = progressCallback as any
|
|
921
|
+
exporter.init()
|
|
922
|
+
}
|
|
923
|
+
)
|
|
924
|
+
})
|
|
925
|
+
)
|
|
926
|
+
})
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
downloadEpubFiles(ids: number[]): void {
|
|
930
|
+
import("../tools.js").then(({getMissingDocumentListData}) => {
|
|
931
|
+
getMissingDocumentListData(
|
|
932
|
+
ids,
|
|
933
|
+
this.documentOverview.documentList as any,
|
|
934
|
+
this.documentOverview.schema,
|
|
935
|
+
null as any
|
|
936
|
+
).then(() =>
|
|
937
|
+
ids.forEach(id => {
|
|
938
|
+
const doc = this.documentOverview.documentList.find(entry => entry.id === id)
|
|
939
|
+
if (!doc) return
|
|
940
|
+
const progressCallback = exportProgressCallback(doc!)
|
|
941
|
+
import("@fiduswriter/document/exporter/epub/index").then(
|
|
942
|
+
({EpubExporter}) => {
|
|
943
|
+
const exporter = new EpubExporter(
|
|
944
|
+
doc as any,
|
|
945
|
+
{db: doc!.bibliography as any},
|
|
946
|
+
{db: doc!.images as any},
|
|
947
|
+
this.documentOverview.app.csl as any,
|
|
948
|
+
new Date((doc!.updated as number) * 1000),
|
|
949
|
+
this.documentOverview.documentStyles
|
|
950
|
+
)
|
|
951
|
+
exporter.progressCallback = progressCallback as any
|
|
952
|
+
exporter.init()
|
|
953
|
+
}
|
|
954
|
+
)
|
|
955
|
+
})
|
|
956
|
+
)
|
|
957
|
+
})
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
settingsDocumentDialog(docId: number): void {
|
|
961
|
+
const doc = this.documentOverview.documentList.find(entry => entry.id === docId)
|
|
962
|
+
if (!doc || !this.dialogParts.length) {
|
|
963
|
+
return
|
|
964
|
+
}
|
|
965
|
+
const body = documentDialogTemplate({doc, dialogParts: this.dialogParts})
|
|
966
|
+
const dialog = new Dialog({
|
|
967
|
+
width: 840,
|
|
968
|
+
height: 520,
|
|
969
|
+
title: `${gettext("Document Settings")}: ${escapeText(doc.title as string)}`,
|
|
970
|
+
body,
|
|
971
|
+
buttons: [
|
|
972
|
+
{
|
|
973
|
+
text: gettext("Submit"),
|
|
974
|
+
classes: "fw-dark",
|
|
975
|
+
click: () => {
|
|
976
|
+
return Promise.all(
|
|
977
|
+
this.onSave.map(method => method(doc))
|
|
978
|
+
).then(() => dialog.close())
|
|
979
|
+
}
|
|
980
|
+
},
|
|
981
|
+
{type: "cancel"}
|
|
982
|
+
]
|
|
983
|
+
} as any)
|
|
984
|
+
dialog.open()
|
|
985
|
+
const dialogTabs = new DialogTabs(
|
|
986
|
+
this.dialogParts.map((part, index) => ({
|
|
987
|
+
id: `docOptionTab${index}`,
|
|
988
|
+
title: part.title,
|
|
989
|
+
description: part.description,
|
|
990
|
+
template: () => ""
|
|
991
|
+
})),
|
|
992
|
+
{containerId: "documentoptions-tab"}
|
|
993
|
+
)
|
|
994
|
+
dialogTabs.bind(dialog.dialogEl.querySelector("#documentoptions-tab")!)
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
revisionsDialog(documentId: number, app: any): void {
|
|
998
|
+
if (app.isOffline()) {
|
|
999
|
+
addAlert(
|
|
1000
|
+
"info",
|
|
1001
|
+
gettext(
|
|
1002
|
+
"You cannot view the revision history of a document while you are offline."
|
|
1003
|
+
)
|
|
1004
|
+
)
|
|
1005
|
+
return
|
|
1006
|
+
}
|
|
1007
|
+
import("../revisions/index.js").then(({DocumentRevisionsDialog}) => {
|
|
1008
|
+
const revDialog = new DocumentRevisionsDialog(
|
|
1009
|
+
documentId,
|
|
1010
|
+
this.documentOverview.documentList,
|
|
1011
|
+
this.documentOverview.user
|
|
1012
|
+
)
|
|
1013
|
+
revDialog.init().then((actionObject: any) => {
|
|
1014
|
+
switch (actionObject.action) {
|
|
1015
|
+
case "added-document":
|
|
1016
|
+
this.documentOverview.documentList.push(actionObject.doc)
|
|
1017
|
+
this.documentOverview.initTable()
|
|
1018
|
+
break
|
|
1019
|
+
case "deleted-revision":
|
|
1020
|
+
actionObject.doc.revisions = actionObject.doc.revisions.filter(
|
|
1021
|
+
(rev: any) => rev.pk !== actionObject.id
|
|
1022
|
+
)
|
|
1023
|
+
this.documentOverview.initTable()
|
|
1024
|
+
break
|
|
1025
|
+
}
|
|
1026
|
+
})
|
|
1027
|
+
})
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
|