From 53aebf1448696acf01ddd0684407738860e2a96e Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 1 Apr 2023 13:58:53 +0200 Subject: [PATCH] wip attachment widget --- src/public/app/widgets/attachment_detail.js | 66 +++++++------------ .../widgets/buttons/attachments_actions.js | 6 +- .../app/widgets/dialogs/note_revisions.js | 2 - .../app/widgets/type_widgets/attachments.js | 61 ++--------------- 4 files changed, 31 insertions(+), 104 deletions(-) diff --git a/src/public/app/widgets/attachment_detail.js b/src/public/app/widgets/attachment_detail.js index bf8a1fb5d..7a100a2c6 100644 --- a/src/public/app/widgets/attachment_detail.js +++ b/src/public/app/widgets/attachment_detail.js @@ -1,5 +1,3 @@ -import TypeWidget from "./type_widget.js"; -import server from "../../services/server.js"; import utils from "../../services/utils.js"; import AttachmentActionsWidget from "../buttons/attachments_actions.js"; import BasicWidget from "./basic_widget.js"; @@ -36,7 +34,16 @@ const TPL = ` } -
+
+
+

+
+
+
+
+ +
+
`; export default class AttachmentDetailWidget extends BasicWidget { @@ -44,56 +51,27 @@ export default class AttachmentDetailWidget extends BasicWidget { super(); this.attachment = attachment; + this.attachmentActionsWidget = new AttachmentActionsWidget(attachment); + this.child(this.attachmentActionsWidget); } doRender() { this.$widget = $(TPL); this.$wrapper = this.$widget.find('.attachment-detail-wrapper'); + this.$wrapper.find('.attachment-title').text(this.attachment.title); + this.$wrapper.find('.attachment-details') + .text(`Role: ${this.attachment.role}, Size: ${utils.formatSize(this.attachment.contentLength)}`); + this.$wrapper.find('.attachment-actions-container').append(this.attachmentActionsWidget.render()); + this.$wrapper.find('.attachment-content').append(this.renderContent()); super.doRender(); } - async doRefresh(note) { - this.$list.empty(); - this.children = []; - - const attachments = await server.get(`notes/${this.noteId}/attachments?includeContent=true`); - - if (attachments.length === 0) { - this.$list.html("This note has no attachments."); - - return; - } - - for (const attachment of attachments) { - const attachmentActionsWidget = new AttachmentActionsWidget(attachment); - this.child(attachmentActionsWidget); - - this.$list.append( - $('
') - .append( - $('
') - .append($('

').append($('').text(attachment.title))) - .append( - $('
') - .text(`Role: ${attachment.role}, Size: ${utils.formatSize(attachment.contentLength)}`) - ) - .append($('
')) // spacer - .append(attachmentActionsWidget.render()) - ) - .append( - $('
') - .append(this.renderContent(attachment)) - ) - ); - } - } - - renderContent(attachment) { - if (attachment.content) { - return $("
").text(attachment.content);
-        } else if (attachment.role === 'image') {
-            return ``;
+    renderContent() {
+        if (this.attachment.content) {
+            return $("
").text(this.attachment.content);
+        } else if (this.attachment.role === 'image') {
+            return ``;
         } else {
             return '';
         }
diff --git a/src/public/app/widgets/buttons/attachments_actions.js b/src/public/app/widgets/buttons/attachments_actions.js
index 6d6121862..bfae9cec3 100644
--- a/src/public/app/widgets/buttons/attachments_actions.js
+++ b/src/public/app/widgets/buttons/attachments_actions.js
@@ -1,5 +1,6 @@
 import BasicWidget from "../basic_widget.js";
 import server from "../../services/server.js";
+import dialogService from "../../services/dialog.js";
 
 const TPL = `