import utils from "../services/utils.js"; import AttachmentActionsWidget from "./buttons/attachments_actions.js"; import BasicWidget from "./basic_widget.js"; import server from "../services/server.js"; const TPL = `
`; export default class AttachmentDetailWidget extends BasicWidget { constructor(attachment) { super(); this.contentSized(); this.attachment = attachment; this.attachmentActionsWidget = new AttachmentActionsWidget(attachment); this.child(this.attachmentActionsWidget); } doRender() { this.$widget = $(TPL); this.refresh(); super.doRender(); } refresh() { this.$widget.find('.attachment-detail-wrapper') .empty() .append( $(TPL) .find('.attachment-detail-wrapper') .html() ); 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()); } renderContent() { if (this.attachment.content) { return $("").text(this.attachment.content); } else if (this.attachment.role === 'image') { return ``; } else { return ''; } } async entitiesReloadedEvent({loadResults}) { console.log("AttachmentDetailWidget: entitiesReloadedEvent"); const attachmentChange = loadResults.getAttachments().find(att => att.attachmentId === this.attachment.attachmentId); if (attachmentChange) { if (attachmentChange.isDeleted) { this.toggleInt(false); } else { this.attachment = await server.get(`notes/${this.attachment.parentId}/attachments/${this.attachment.attachmentId}?includeContent=true`); this.refresh(); } } } }