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() {
|
|
|
|
Hooks.on('renderCompendium', async (pack, html, data) => RddCompendiumOrganiser.onRenderCompendium(pack, html, data))
|
|
|
|
}
|
|
|
|
|
2021-03-25 03:18:27 +01:00
|
|
|
static async onRenderCompendium(compendium, html, data) {
|
|
|
|
console.log('onRenderCompendium', compendium, html, data);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|