refactor(calendar): dedicated method for building event content

This commit is contained in:
Elian Doran 2025-04-08 22:48:57 +03:00
parent 0b0d212854
commit eea141225d
No known key found for this signature in database

View File

@ -155,28 +155,7 @@ export default class CalendarView extends ViewMode {
locale: await CalendarView.#getLocale(), locale: await CalendarView.#getLocale(),
height: "100%", height: "100%",
nowIndicator: true, nowIndicator: true,
eventContent: (e) => { eventContent: this.#buildEventContent,
let html = "";
const { iconClass, promotedAttributes } = e.event.extendedProps;
// Title and icon
if (iconClass) {
html += `<span class="${iconClass}"></span> `;
}
html += utils.escapeHtml(e.event.title);
// Promoted attributes
if (promotedAttributes) {
for (const [name, value] of promotedAttributes) {
html += `\
<div class="promoted-attribute">
<span class="promoted-attribute-name">${name}</span>: <span class="promoted-attribute-value">${value}</span>
</div>`;
}
}
return { html };
},
dateClick: async (e) => { dateClick: async (e) => {
if (!this.isCalendarRoot) { if (!this.isCalendarRoot) {
return; return;
@ -199,6 +178,29 @@ export default class CalendarView extends ViewMode {
return this.$root; return this.$root;
} }
#buildEventContent(e: EventDropArg) {
let html = "";
const { iconClass, promotedAttributes } = e.event.extendedProps;
// Title and icon
if (iconClass) {
html += `<span class="${iconClass}"></span> `;
}
html += utils.escapeHtml(e.event.title);
// Promoted attributes
if (promotedAttributes) {
for (const [name, value] of promotedAttributes) {
html += `\
<div class="promoted-attribute">
<span class="promoted-attribute-name">${name}</span>: <span class="promoted-attribute-value">${value}</span>
</div>`;
}
}
return { html };
}
static async #getLocale() { static async #getLocale() {
const locale = options.get("locale"); const locale = options.get("locale");