2022-01-29 22:49:34 +01:00
|
|
|
import { SYSTEM_RDD } from "./constants.js";
|
2021-01-26 00:25:41 +01:00
|
|
|
import { Misc } from "./misc.js";
|
|
|
|
|
|
|
|
export class RddCompendiumOrganiser {
|
|
|
|
static init() {
|
2022-09-07 18:47:56 +02:00
|
|
|
Hooks.on('renderCompendium', async (pack, html, compendiumData) => RddCompendiumOrganiser.onRenderCompendium(pack, html, compendiumData))
|
2021-01-26 00:25:41 +01:00
|
|
|
}
|
|
|
|
|
2022-09-07 18:47:56 +02:00
|
|
|
static async onRenderCompendium(compendium, html, compendiumData) {
|
|
|
|
console.log('onRenderCompendium', compendium, html, compendiumData);
|
2021-05-24 00:43:46 +02:00
|
|
|
const pack = compendium.collection
|
2022-01-29 22:49:34 +01:00
|
|
|
if (pack.metadata.system === SYSTEM_RDD) {
|
2021-01-26 00:25:41 +01:00
|
|
|
html.find('.directory-item').each((i, element) => {
|
2021-05-24 00:43:46 +02:00
|
|
|
RddCompendiumOrganiser.setEntityTypeName(pack, element);
|
2021-01-26 00:25:41 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-24 00:43:46 +02:00
|
|
|
static async setEntityTypeName(pack, element) {
|
|
|
|
const label = Misc.getEntityTypeLabel(await pack.getDocument(element.dataset.documentId));
|
|
|
|
RddCompendiumOrganiser.insertEntityType(element, label);
|
|
|
|
}
|
|
|
|
|
|
|
|
static insertEntityType(element, label) {
|
|
|
|
if (label) {
|
|
|
|
element.children[1].insertAdjacentHTML('afterbegin', `<label class="type-compendium">${label}: </label>`);
|
|
|
|
}
|
2021-01-26 00:25:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|