wip attachment widget

This commit is contained in:
zadam
2023-04-01 23:55:04 +02:00
parent 53aebf1448
commit 2bc78ccafb
12 changed files with 268 additions and 92 deletions

View File

@@ -1,6 +1,7 @@
import utils from "../../services/utils.js";
import AttachmentActionsWidget from "../buttons/attachments_actions.js";
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 = `
<div class="attachment-detail">
@@ -38,7 +39,7 @@ const TPL = `
<div class="attachment-title-line">
<h4 class="attachment-title"></h4>
<div class="attachment-details"></div>
<div style="flex: 1 1;">
<div style="flex: 1 1;"></div>
<div class="attachment-actions-container"></div>
</div>
@@ -50,6 +51,7 @@ export default class AttachmentDetailWidget extends BasicWidget {
constructor(attachment) {
super();
this.contentSized();
this.attachment = attachment;
this.attachmentActionsWidget = new AttachmentActionsWidget(attachment);
this.child(this.attachmentActionsWidget);
@@ -57,14 +59,25 @@ export default class AttachmentDetailWidget extends BasicWidget {
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());
super.doRender();
}
renderContent() {
@@ -76,4 +89,20 @@ export default class AttachmentDetailWidget extends BasicWidget {
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();
}
}
}
}