diff --git a/src/public/app/widgets/buttons/attachments_actions.js b/src/public/app/widgets/buttons/attachments_actions.ts
similarity index 86%
rename from src/public/app/widgets/buttons/attachments_actions.js
rename to src/public/app/widgets/buttons/attachments_actions.ts
index 5ee51b9d9..f25e9c376 100644
--- a/src/public/app/widgets/buttons/attachments_actions.js
+++ b/src/public/app/widgets/buttons/attachments_actions.ts
@@ -8,6 +8,8 @@ import appContext from "../../components/app_context.js";
import openService from "../../services/open.js";
import utils from "../../services/utils.js";
import { Dropdown } from "bootstrap";
+import type attachmentsApiRoute from "../../../../routes/api/attachments.js"
+import type FAttachment from "../../entities/fattachment.js";
const TPL = `
@@ -79,7 +81,12 @@ const TPL = `
`;
export default class AttachmentActionsWidget extends BasicWidget {
- constructor(attachment, isFullDetail) {
+ $uploadNewRevisionInput!: JQuery;
+ attachment: FAttachment;
+ isFullDetail: boolean;
+ dropdown!: Dropdown;
+
+ constructor(attachment: FAttachment, isFullDetail: boolean) {
super();
this.attachment = attachment;
@@ -92,20 +99,21 @@ export default class AttachmentActionsWidget extends BasicWidget {
doRender() {
this.$widget = $(TPL);
- this.dropdown = Dropdown.getOrCreateInstance(this.$widget.find("[data-bs-toggle='dropdown']"));
+ this.dropdown = Dropdown.getOrCreateInstance(this.$widget.find("[data-bs-toggle='dropdown']")[0]);
this.$widget.on("click", ".dropdown-item", () => this.dropdown.toggle());
this.$uploadNewRevisionInput = this.$widget.find(".attachment-upload-new-revision-input");
this.$uploadNewRevisionInput.on("change", async () => {
- const fileToUpload = this.$uploadNewRevisionInput[0].files[0]; // copy to allow reset below
+
+ const fileToUpload = this.$uploadNewRevisionInput[0].files?.item(0); // copy to allow reset below
this.$uploadNewRevisionInput.val("");
-
- const result = await server.upload(`attachments/${this.attachmentId}/file`, fileToUpload);
-
- if (result.uploaded) {
- toastService.showMessage(t("attachments_actions.upload_success"));
- } else {
- toastService.showError(t("attachments_actions.upload_failed"));
+ if (fileToUpload) {
+ const result = await server.upload(`attachments/${this.attachmentId}/file`, fileToUpload);
+ if (result.uploaded) {
+ toastService.showMessage(t("attachments_actions.upload_success"));
+ } else {
+ toastService.showError(t("attachments_actions.upload_failed"));
+ }
}
});
@@ -122,6 +130,7 @@ export default class AttachmentActionsWidget extends BasicWidget {
const $openAttachmentCustomButton = this.$widget.find("[data-trigger-command='openAttachmentCustom']");
$openAttachmentCustomButton.addClass("disabled").append($('').attr("title", t("attachments_actions.open_custom_client_only")));
}
+
}
async openAttachmentCommand() {
@@ -141,7 +150,8 @@ export default class AttachmentActionsWidget extends BasicWidget {
}
async copyAttachmentLinkToClipboardCommand() {
- this.parent.copyAttachmentLinkToClipboard();
+ //TriliumNextTODO: the parent here is AttachmentDetailWidget
+ this.parent?.copyAttachmentLinkToClipboard();
}
async deleteAttachmentCommand() {
@@ -158,7 +168,8 @@ export default class AttachmentActionsWidget extends BasicWidget {
return;
}
- const { note: newNote } = await server.post(`attachments/${this.attachmentId}/convert-to-note`);
+
+ const { note: newNote } = await server.post>(`attachments/${this.attachmentId}/convert-to-note`);
toastService.showMessage(t("attachments_actions.convert_success", { title: this.attachment.title }));
await ws.waitForMaxKnownEntityChangeId();
await appContext.tabManager.getActiveContext().setNote(newNote.noteId);