const TPL = `
Note ID |
|
Created |
|
Modified |
|
Type |
|
MIME |
|
`;
class NoteInfoWidget {
/**
* @param {TabContext} ctx
* @param {jQuery} $widget
*/
constructor(ctx, $widget) {
this.ctx = ctx;
this.$widget = $widget;
this.$widget.on('show.bs.collapse', () => this.renderBody());
this.$widget.on('show.bs.collapse', () => this.ctx.stateChanged());
this.$widget.on('hide.bs.collapse', () => this.ctx.stateChanged());
this.$title = this.$widget.find('.widget-title');
this.$title.text("Note info");
this.$bodyWrapper = this.$widget.find('.body-wrapper');
}
async renderBody() {
if (!this.isVisible()) {
return;
}
const $body = this.$widget.find('.card-body');
$body.html(TPL);
const $noteId = $body.find(".note-info-note-id");
const $dateCreated = $body.find(".note-info-date-created");
const $dateModified = $body.find(".note-info-date-modified");
const $type = $body.find(".note-info-type");
const $mime = $body.find(".note-info-mime");
const note = this.ctx.note;
$noteId.text(note.noteId);
$dateCreated.text(note.dateCreated);
$dateModified.text(note.dateModified);
$type.text(note.type);
$mime.text(note.mime);
}
syncDataReceived(syncData) {
if (syncData.find(sd => sd.entityName === 'notes' && sd.entityId === this.ctx.note.noteId)) {
this.renderBody();
}
}
getWidgetState() {
return {
id: 'attributes',
visible: this.isVisible()
};
}
isVisible() {
return this.$bodyWrapper.is(":visible");
}
}
export default NoteInfoWidget;