Entrée ajoute le milieu aux fréquences

This commit is contained in:
Vincent Vandemeulebrouck 2022-12-02 21:21:21 +01:00
parent 86f9c37b30
commit 4b4d778d9c
2 changed files with 22 additions and 13 deletions

View File

@ -150,21 +150,31 @@ export class EnvironmentSheetHelper {
static activateListeners(sheet, html) { static activateListeners(sheet, html) {
if (!sheet.options.editable) return; if (!sheet.options.editable) return;
html.find("input.input-selection-milieu").keypress(event => {
if (event.keyCode == '13') {
EnvironmentSheetHelper.onAddMilieu(html, sheet, event);
}
event.stopPropagation();
})
html.find("a.milieu-add").click(event => EnvironmentSheetHelper.onAddMilieu(html, sheet, event)); html.find("a.milieu-add").click(event => EnvironmentSheetHelper.onAddMilieu(html, sheet, event));
html.find("div.environnement-milieu a.milieu-delete").click(event => EnvironmentSheetHelper.onDeleteMilieu(sheet, event)); html.find("div.environnement-milieu a.milieu-delete").click(event => EnvironmentSheetHelper.onDeleteMilieu(sheet, event));
html.find("div.environnement-milieu select.environnement-rarete").change(event => EnvironmentSheetHelper.onChange(sheet, event, html.find("div.environnement-milieu select.environnement-rarete").change(event => EnvironmentSheetHelper.onChange(sheet, event,
(updated) => { updated => EnvironmentSheetHelper.$changeRarete(event, updated)));
const name = $(event.currentTarget).val();
const rarete = Environnement.getRarete(name);
updated.rarete = rarete.name;
updated.frequence = Math.min(
Math.max(rarete.min, updated.frequence ?? rarete.frequence),
rarete.max);
}));
html.find("div.environnement-milieu input[name='environnement-frequence']").change(event => EnvironmentSheetHelper.onChange(sheet, event, html.find("div.environnement-milieu input[name='environnement-frequence']").change(event => EnvironmentSheetHelper.onChange(sheet, event,
(updated) => { updated => EnvironmentSheetHelper.$changeFrequence(updated, event)));
updated.frequence = Number($(event.currentTarget).val()) }
}));
static $changeFrequence(updated, event) {
updated.frequence = Number($(event.currentTarget).val());
}
static $changeRarete(event, updated) {
const name = $(event.currentTarget).val();
const rarete = Environnement.getRarete(name);
updated.rarete = rarete.name;
updated.frequence = Math.min(
Math.max(rarete.min, updated.frequence ?? rarete.frequence),
rarete.max);
} }
static async onAddMilieu(html, sheet, event) { static async onAddMilieu(html, sheet, event) {
@ -186,7 +196,7 @@ export class EnvironmentSheetHelper {
static async onDeleteMilieu(sheet, event) { static async onDeleteMilieu(sheet, event) {
const milieu = EnvironmentSheetHelper.$getEventMilieu(event); const milieu = EnvironmentSheetHelper.$getEventMilieu(event);
if (milieu) { if (milieu != undefined) {
const newList = sheet.item.system.environnement.filter(it => it.milieu != milieu) const newList = sheet.item.system.environnement.filter(it => it.milieu != milieu)
.sort(Misc.ascending(it => it.milieu)); .sort(Misc.ascending(it => it.milieu));
await sheet.item.update({ 'system.environnement': newList }); await sheet.item.update({ 'system.environnement': newList });

View File

@ -81,7 +81,6 @@ function autocomplete(input, proposals) {
currentFocus--; currentFocus--;
addActive(container); addActive(container);
} else if (e.keyCode == 13) { } else if (e.keyCode == 13) {
e.preventDefault();
if (currentFocus > -1 && container) { if (currentFocus > -1 && container) {
container[currentFocus].click(); container[currentFocus].click();
} }