refactor widget constructor

This commit is contained in:
zadam 2019-08-17 10:45:20 +02:00
parent 723fc42d88
commit 53c4bb8a94
6 changed files with 15 additions and 32 deletions

View File

@ -5,17 +5,15 @@ import messagingService from "../services/messaging.js";
import StandardWidget from "./standard_widget.js"; import StandardWidget from "./standard_widget.js";
class AttributesWidget extends StandardWidget { class AttributesWidget extends StandardWidget {
constructor(ctx, state) { getWidgetTitle() { return "Attributes"; }
super(ctx, state);
this.$title.text("Attributes");
getHeaderActions() {
const $showFullButton = $("<a>").append("show dialog").addClass('widget-header-action'); const $showFullButton = $("<a>").append("show dialog").addClass('widget-header-action');
$showFullButton.click(() => { $showFullButton.click(() => {
attributesDialog.showDialog(); attributesDialog.showDialog();
}); });
this.$headerActions.append($showFullButton); return [$showFullButton];
} }
async doRenderBody() { async doRenderBody() {

View File

@ -24,21 +24,15 @@ const linkOverlays = [
]; ];
class LinkMapWidget extends StandardWidget { class LinkMapWidget extends StandardWidget {
/** getWidgetTitle() { return "Link map"; }
* @param {TabContext} ctx
* @param {object} state
*/
constructor(ctx, state) {
super(ctx, state);
this.$title.text("Link map");
getHeaderActions() {
const $showFullButton = $("<a>").append("show full").addClass('widget-header-action'); const $showFullButton = $("<a>").append("show full").addClass('widget-header-action');
$showFullButton.click(() => { $showFullButton.click(() => {
linkMapDialog.showDialog(); linkMapDialog.showDialog();
}); });
this.$headerActions.append($showFullButton); return [$showFullButton];
} }
async doRenderBody() { async doRenderBody() {

View File

@ -26,15 +26,7 @@ const TPL = `
`; `;
class NoteInfoWidget extends StandardWidget { class NoteInfoWidget extends StandardWidget {
/** getWidgetTitle() { return "Note info"; }
* @param {TabContext} ctx
* @param {object} state
*/
constructor(ctx, state) {
super(ctx, state);
this.$title.text("Note info");
}
async doRenderBody() { async doRenderBody() {
this.$body.html(TPL); this.$body.html(TPL);

View File

@ -7,15 +7,7 @@ const TPL = `
`; `;
class NoteRevisionsWidget extends StandardWidget { class NoteRevisionsWidget extends StandardWidget {
/** getWidgetTitle() { return "Note revisions"; }
* @param {TabContext} ctx
* @param {object} state
*/
constructor(ctx, state) {
super(ctx, state);
this.$title.text("Note revisions");
}
async doRenderBody() { async doRenderBody() {
const revisionItems = await server.get(`notes/${this.ctx.note.noteId}/revisions`); const revisionItems = await server.get(`notes/${this.ctx.note.noteId}/revisions`);

View File

@ -41,9 +41,15 @@ class StandardWidget {
this.$widget.on('shown.bs.collapse', () => this.ctx.stateChanged()); this.$widget.on('shown.bs.collapse', () => this.ctx.stateChanged());
this.$widget.on('hidden.bs.collapse', () => this.ctx.stateChanged()); this.$widget.on('hidden.bs.collapse', () => this.ctx.stateChanged());
this.$title = this.$widget.find('.widget-title'); this.$title = this.$widget.find('.widget-title');
this.$title.text(this.getWidgetTitle());
this.$headerActions = this.$widget.find('.widget-header-actions'); this.$headerActions = this.$widget.find('.widget-header-actions');
this.$headerActions.append(...this.getHeaderActions());
} }
getWidgetTitle() { return "Untitled widget"; }
getHeaderActions() { return []; }
async renderBody() { async renderBody() {
if (!this.isVisible() || this.rendered) { if (!this.isVisible() || this.rendered) {
return; return;

View File

@ -134,6 +134,7 @@ ul.fancytree-container {
} }
.note-detail-sidebar .widget-header-actions { .note-detail-sidebar .widget-header-actions {
padding-right: 10px;
} }
.note-detail-sidebar .widget-header-action { .note-detail-sidebar .widget-header-action {