Cleanup - preparation Coeur
Simplification de code: - des Méthodes simples sur une ligne - utilisation de item.update au lieu de updateEmbeddedDocuments quand possibe - renommage des templates SubActeur - déplacement de logs quand compétence non trouvée
This commit is contained in:
45
module/dialog-select.js
Normal file
45
module/dialog-select.js
Normal file
@ -0,0 +1,45 @@
|
||||
|
||||
export class DialogSelect extends Dialog {
|
||||
static extractIdNameImg(it) { return { id: it.id, name: it.name, img: it.img } }
|
||||
|
||||
static async select(selectData, onSelectChoice) {
|
||||
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/dialog-select.html", selectData)
|
||||
|
||||
const dialogData = {
|
||||
title: selectData.title ?? selectData.label,
|
||||
content: html,
|
||||
buttons: {}
|
||||
}
|
||||
|
||||
const dialogOptions = {
|
||||
classes: ["rdd-dialog-select"],
|
||||
width: 'fit-content',
|
||||
height: 'fit-content',
|
||||
'max-height': 600,
|
||||
'z-index': 99999
|
||||
}
|
||||
new DialogSelect(dialogData, dialogOptions, selectData, onSelectChoice).render(true)
|
||||
}
|
||||
|
||||
constructor(dialogData, dialogOptions, selectionData, onSelectChoice) {
|
||||
super(dialogData, dialogOptions)
|
||||
this.selectionData = selectionData
|
||||
this.onSelectChoice = onSelectChoice
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html)
|
||||
this.html = html
|
||||
this.html.find("li.select-choice").click(event =>
|
||||
this.choiceSelected(this.html.find(event.currentTarget)?.data("id"))
|
||||
)
|
||||
}
|
||||
|
||||
choiceSelected(selectedId) {
|
||||
const selected = this.selectionData.find(it => it.id == selectedId)
|
||||
this.close()
|
||||
if (selected) {
|
||||
this.onSelectChoice(selected)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user