Notes/src/public/app/widgets/right_panel_widget.ts

84 lines
2.4 KiB
TypeScript
Raw Normal View History

import BasicWidget from "./basic_widget.js";
import AbstractButtonWidget from "./buttons/abstract_button.js";
2021-05-22 12:35:41 +02:00
import NoteContextAwareWidget from "./note_context_aware_widget.js";
2019-08-15 21:08:41 +02:00
const WIDGET_TPL = `
<div class="card widget">
<div class="card-header">
<div class="card-header-title"></div>
<div class="card-header-buttons"></div>
</div>
2019-08-15 21:08:41 +02:00
<div id="[to be set]" class="body-wrapper">
2019-08-15 21:08:41 +02:00
<div class="card-body"></div>
</div>
</div>`;
2019-08-15 21:08:41 +02:00
2023-08-21 04:15:53 -04:00
/**
* This widget manages rendering panels in the right-hand pane.
*/
class RightPanelWidget extends NoteContextAwareWidget {
private $bodyWrapper!: JQuery<HTMLElement>;
$body!: JQuery<HTMLElement>;
private $title!: JQuery<HTMLElement>;
private $buttons!: JQuery<HTMLElement>;
2023-08-21 04:15:53 -04:00
/** Title to show in the panel. */
2025-01-09 18:07:02 +02:00
get widgetTitle() {
return "Untitled widget";
}
2025-01-09 18:07:02 +02:00
get widgetButtons(): AbstractButtonWidget<any>[] {
return [];
}
2025-01-09 18:07:02 +02:00
get help() {
return {};
}
constructor() {
super();
this.child(...this.widgetButtons);
}
2023-08-21 04:15:53 -04:00
/**
* Do not override this method unless you know what you're doing.
2023-08-21 04:15:53 -04:00
* Do not override this method unless you know what you're doing.
*/
2020-02-02 20:02:08 +01:00
doRender() {
2019-08-15 21:08:41 +02:00
this.$widget = $(WIDGET_TPL);
2021-06-13 22:55:31 +02:00
this.contentSized();
2025-01-09 18:07:02 +02:00
this.$widget.find("[data-target]").attr("data-target", `#${this.componentId}`);
2019-08-15 21:08:41 +02:00
2025-01-09 18:07:02 +02:00
this.$bodyWrapper = this.$widget.find(".body-wrapper");
this.$bodyWrapper.attr("id", this.componentId); // for toggle to work we need id
2025-01-09 18:07:02 +02:00
this.$body = this.$bodyWrapper.find(".card-body");
2019-08-15 21:08:41 +02:00
2025-01-09 18:07:02 +02:00
this.$title = this.$widget.find(".card-header .card-header-title");
2020-03-16 22:14:18 +01:00
this.$title.text(this.widgetTitle);
2025-01-09 18:07:02 +02:00
this.$buttons = this.$widget.find(".card-header .card-header-buttons");
this.$buttons.empty();
for (const buttonWidget of this.children) {
this.$buttons.append((buttonWidget as BasicWidget).render());
}
2025-01-09 18:07:02 +02:00
this.initialized = this.doRenderBody().catch((e) => {
2024-10-25 20:50:13 +03:00
this.logRenderingError(e);
});
}
2023-08-21 04:15:53 -04:00
/**
* Method used for rendering the body of the widget (via existing this.$body)
*
2023-08-21 04:15:53 -04:00
* Your class should override this method.
* @returns {Promise|undefined} if widget needs async operation to initialize, it can return a Promise
2023-08-21 04:15:53 -04:00
*/
2019-08-15 21:08:41 +02:00
async doRenderBody() {}
2020-07-03 22:27:45 +02:00
}
2023-08-21 04:15:53 -04:00
export default RightPanelWidget;