fix multi-select; only show private boats owner + kiosk

This commit is contained in:
2023-09-24 22:17:28 +02:00
parent ce73fd8902
commit 09af9981df
4 changed files with 60 additions and 10 deletions

View File

@ -39,9 +39,9 @@ function selectBoatChange() {
)[0];
const rowers = Number(originalOption.dataset.amount_seats) - 1;
choiceObjects['newrower'].config.maxItemCount = rowers;
choiceObjects['newrower'].removeActiveItems(rowers);
(rowers === 0 ? choiceObjects['newrower'].disable() : choiceObjects['newrower'].enable());
setMaxAmountRowers(rowers);
return opt;
}
@ -62,6 +62,27 @@ function selectBoatChange() {
choiceObjects[shipmasterSelect.id] = shipmasterChoice;
}
function setMaxAmountRowers(rowers){
let curSelection = choiceObjects['newrower'].getValue(true);
let amount_to_delete = curSelection.length - rowers;
if (amount_to_delete > 0){
let to_delete = curSelection.slice(-amount_to_delete);
for (let del of to_delete) {
choiceObjects['newrower'].removeActiveItemsByValue(del);
}
}
choiceObjects['newrower'].config.maxItemCount = rowers;
const only_steering = <HTMLSelectElement>document.querySelector('#shipmaster_only_steering');
if (rowers === 0) {
choiceObjects['newrower'].disable()
only_steering.disabled = true;
}else{
choiceObjects['newrower'].enable()
only_steering.disabled = false;
}
}
function initBoatActions() {
const boatSelects = document.querySelectorAll('.boats-js[data-onclick="true"]');
if(boatSelects) {
@ -69,14 +90,20 @@ function initBoatActions() {
select.addEventListener('click', function() {
if(select.dataset.seats) {
const rowers = Number(select.dataset.seats) - 1;
choiceObjects['newrower'].config.maxItemCount = rowers;
choiceObjects['newrower'].removeActiveItems(rowers);
setMaxAmountRowers(rowers);
if (select.dataset.id) {
choiceObjects['boat_id'].setChoiceByValue(select.dataset.id);
}
(rowers === 0 ? choiceObjects['newrower'].disable() : choiceObjects['newrower'].enable());
window.scrollTo(0, 0);
const inputElement = document.getElementById("departure") as HTMLInputElement;
const now = new Date();
const formattedDateTime = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}T${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`;
inputElement.value = formattedDateTime;
}
});
});
@ -100,7 +127,7 @@ function initNewChoice(select: HTMLInputElement) {
noChoicesText: 'Keine Ergebnisse gefunden',
itemSelectText: 'Zum Auswählen klicken',
placeholderValue: 'Ruderer auswählen',
maxItemCount: Number(select.dataset.seats) - 1,
maxItemCount: -1, //TODO
maxItemText: (maxItemCount) => {
return `Nur ${maxItemCount} Ruderer können hinzugefügt werden`;
},