import server from "../../services/server.js"; import NoteContextAwareWidget from "../note_context_aware_widget.js"; import toastService from "../../services/toast.js"; import openService from "../../services/open.js"; import utils from "../../services/utils.js"; import { t } from "../../services/i18n.js"; const TPL = `
${t("image_properties.original_file_name")}: ${t("image_properties.file_type")}: ${t("image_properties.file_size")}:
`; export default class ImagePropertiesWidget extends NoteContextAwareWidget { get name() { return "imageProperties"; } get toggleCommand() { return "toggleRibbonTabImageProperties"; } isEnabled() { return this.note && this.note.type === 'image'; } getTitle() { return { show: this.isEnabled(), activate: true, title: t("image_properties.title"), icon: 'bx bx-image' }; } doRender() { this.$widget = $(TPL); this.contentSized(); this.$copyReferenceToClipboardButton = this.$widget.find(".image-copy-reference-to-clipboard"); this.$copyReferenceToClipboardButton.on('click', () => this.triggerEvent(`copyImageReferenceToClipboard`, {ntxId: this.noteContext.ntxId})); this.$uploadNewRevisionButton = this.$widget.find(".image-upload-new-revision"); this.$uploadNewRevisionInput = this.$widget.find(".image-upload-new-revision-input"); this.$fileName = this.$widget.find(".image-filename"); this.$fileType = this.$widget.find(".image-filetype"); this.$fileSize = this.$widget.find(".image-filesize"); this.$openButton = this.$widget.find(".image-open"); this.$openButton.on('click', () => openService.openNoteExternally(this.noteId, this.note.mime)); this.$imageDownloadButton = this.$widget.find(".image-download"); this.$imageDownloadButton.on('click', () => openService.downloadFileNote(this.noteId)); this.$uploadNewRevisionButton.on("click", () => { this.$uploadNewRevisionInput.trigger("click"); }); this.$uploadNewRevisionInput.on('change', async () => { const fileToUpload = this.$uploadNewRevisionInput[0].files[0]; // copy to allow reset below this.$uploadNewRevisionInput.val(''); const result = await server.upload(`images/${this.noteId}`, fileToUpload); if (result.uploaded) { toastService.showMessage(t("image_properties.upload_success")); await utils.clearBrowserCache(); this.refresh(); } else { toastService.showError(t("image_properties.upload_failed", { message: result.message })); } }); } async refreshWithNote(note) { this.$widget.show(); const blob = await this.note.getBlob(); this.$fileName.text(note.getLabelValue('originalFileName') || "?"); this.$fileSize.text(utils.formatSize(blob.contentLength)); this.$fileType.text(note.mime); } }