[TASK] refactor steering checkbox

This commit is contained in:
Marie Birner
2023-09-28 16:07:52 +02:00
committed by philipp
parent 2ae01c0c65
commit 8cec4e4c11
3 changed files with 53 additions and 37 deletions

View File

@ -49,10 +49,10 @@ function selectBoatChange() {
)[0];
const rowers = Number(originalOption.dataset.amount_seats) - 1;
setMaxAmountRowers(rowers);
const isShipmasterSteering = originalOption.dataset.default_shipmaster_only_steering;
setMaxAmountRowers(rowers,isShipmasterSteering);
return opt;
}
}
@ -91,7 +91,7 @@ function reloadPage() {
});
}
function setMaxAmountRowers(rowers: number){
function setMaxAmountRowers(rowers: number, isShipmasterSteering='false') {
let curSelection = choiceObjects['newrower'].getValue(true);
let amount_to_delete = (<any>curSelection).length - rowers;
if (amount_to_delete > 0){
@ -102,14 +102,24 @@ function setMaxAmountRowers(rowers: number){
}
choiceObjects['newrower'].config.maxItemCount = rowers;
const only_steering = <HTMLSelectElement>document.querySelector('#shipmaster_only_steering');
if (rowers === 0) {
choiceObjects['newrower'].disable()
only_steering.disabled = true;
choiceObjects['newrower'].disable()
}else{
choiceObjects['newrower'].enable()
only_steering.disabled = false;
choiceObjects['newrower'].enable()
}
let only_steering = <HTMLSelectElement>document.querySelector('#shipmaster_only_steering');
if(only_steering) {
if(isShipmasterSteering == 'true') {
only_steering.removeAttribute('disabled');
only_steering.setAttribute('checked', 'true');
only_steering.parentElement?.parentElement?.parentElement?.classList.remove('opacity-50');
} else {
only_steering.setAttribute('disabled', 'disabled');
only_steering.removeAttribute('checked');
only_steering.parentElement?.parentElement?.parentElement?.classList.add('opacity-50');
}
}
}
function initBoatActions() {
@ -119,20 +129,21 @@ function initBoatActions() {
select.addEventListener('click', function() {
if(select.dataset.seats) {
const rowers = Number(select.dataset.seats) - 1;
const isShipmasterSteering = select.dataset.default_shipmaster_only_steering;
setMaxAmountRowers(rowers);
if (select.dataset.id) {
choiceObjects['boat_id'].setChoiceByValue(select.dataset.id);
}
setMaxAmountRowers(rowers, isShipmasterSteering);
if (select.dataset.id) {
choiceObjects['boat_id'].setChoiceByValue(select.dataset.id);
}
window.scrollTo(0, 0);
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;
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;
}
});
});