2023-09-23 21:05:08 +02:00
|
|
|
|
import Choices from "choices.js";
|
2023-04-06 13:15:40 +02:00
|
|
|
|
import { Sidebar } from './js/sidebar';
|
2023-04-05 19:33:31 +02:00
|
|
|
|
import './scss/app.scss'
|
2023-09-23 21:05:08 +02:00
|
|
|
|
export interface choiceMap {
|
|
|
|
|
[details: string]: Choices;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let choiceObjects: choiceMap = {};
|
2023-04-06 10:27:04 +02:00
|
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
2023-11-04 20:16:20 +01:00
|
|
|
|
changeTheme();
|
|
|
|
|
initcolorTheme();
|
2023-04-06 10:27:04 +02:00
|
|
|
|
initSearch();
|
2023-04-06 13:15:40 +02:00
|
|
|
|
initSidebar();
|
2023-04-07 12:37:33 +02:00
|
|
|
|
initToggle();
|
2023-04-10 22:56:47 +02:00
|
|
|
|
replaceStrings();
|
2023-09-23 21:05:08 +02:00
|
|
|
|
initChoices();
|
|
|
|
|
initBoatActions();
|
2023-09-23 21:51:00 +02:00
|
|
|
|
selectBoatChange();
|
2023-09-23 22:31:19 +02:00
|
|
|
|
addRelationMagic(<HTMLElement>document.querySelector('body'));
|
2023-09-27 13:58:22 +02:00
|
|
|
|
reloadPage();
|
2023-09-27 14:46:34 +02:00
|
|
|
|
setCurrentdate(<HTMLInputElement>document.querySelector('#departure'));
|
2023-04-06 10:27:04 +02:00
|
|
|
|
});
|
|
|
|
|
|
2023-11-04 20:16:20 +01:00
|
|
|
|
function changeTheme() {
|
|
|
|
|
let toggleBtn = <HTMLElement>document.querySelector('#theme-toggle-js');
|
|
|
|
|
|
|
|
|
|
if(toggleBtn) {
|
|
|
|
|
toggleBtn.addEventListener('click', function() {
|
|
|
|
|
if(toggleBtn.dataset.theme === 'light') {
|
|
|
|
|
setTheme('dark', true);
|
|
|
|
|
} else {
|
|
|
|
|
setTheme('light', true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
* init javascript
|
|
|
|
|
* 1) detect native color scheme or use set theme in local storage
|
|
|
|
|
* 2) detect view (desktop or responsive) if on mobile device with touch screen
|
|
|
|
|
* 3) set base font size to 112.5% -> 18px
|
|
|
|
|
*/
|
|
|
|
|
function initcolorTheme() {
|
|
|
|
|
colorThemeWatcher();
|
|
|
|
|
let theme = localStorage.getItem('theme');
|
|
|
|
|
if (theme == null || theme === 'auto') {
|
|
|
|
|
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
|
|
|
|
setTheme('dark', false);
|
|
|
|
|
} else {
|
|
|
|
|
setTheme('light', false);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
setTheme(theme)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
* Listener operating system native color configuration
|
|
|
|
|
*/
|
|
|
|
|
function colorThemeWatcher() {
|
|
|
|
|
try {
|
|
|
|
|
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
|
|
|
|
|
setTheme(e.matches ? 'dark' : 'light');
|
|
|
|
|
});
|
|
|
|
|
} catch {
|
|
|
|
|
console.warn('color theme watcher not supported');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Define color scheme, colors without losing the base font size configuration
|
|
|
|
|
* and add data-theme to html tag
|
|
|
|
|
* @param theme
|
|
|
|
|
*/
|
|
|
|
|
function setTheme(theme: string, setLocalStorage = true) {
|
|
|
|
|
let toggleBtn = document.querySelector('#theme-toggle-js');
|
|
|
|
|
|
2023-11-04 20:51:03 +01:00
|
|
|
|
if (setLocalStorage) {
|
|
|
|
|
localStorage.setItem('theme', theme);
|
|
|
|
|
}
|
|
|
|
|
if (toggleBtn) toggleBtn.setAttribute('data-theme', theme);
|
2023-11-04 20:16:20 +01:00
|
|
|
|
|
2023-11-04 20:51:03 +01:00
|
|
|
|
if (document.documentElement.classList.contains('dark') && theme === 'light') {
|
|
|
|
|
document.documentElement.classList.remove('dark');
|
|
|
|
|
} else if(theme === 'dark'){
|
|
|
|
|
document.documentElement.classList.add('dark');
|
2023-11-04 20:16:20 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-27 14:46:34 +02:00
|
|
|
|
function setCurrentdate(input: HTMLInputElement) {
|
|
|
|
|
if(input) {
|
2023-10-28 10:30:16 +02:00
|
|
|
|
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')}`;
|
|
|
|
|
|
2023-10-30 13:39:58 +01:00
|
|
|
|
input.value = formattedDateTime;
|
2023-09-27 14:46:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-30 15:37:01 +01:00
|
|
|
|
interface ChoiceBoatEvent extends Event{
|
|
|
|
|
detail: {
|
|
|
|
|
value: string;
|
|
|
|
|
label: string,
|
|
|
|
|
customProperties: {
|
|
|
|
|
amount_seats: number,
|
2023-11-02 19:50:19 +01:00
|
|
|
|
owner: number,
|
2023-11-09 08:56:08 +01:00
|
|
|
|
default_destination: string,
|
2023-10-30 15:37:01 +01:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-23 21:51:00 +02:00
|
|
|
|
function selectBoatChange() {
|
2023-09-24 10:32:38 +02:00
|
|
|
|
const boatSelect = <HTMLSelectElement>document.querySelector('#boat_id');
|
|
|
|
|
|
2023-09-27 13:52:15 +02:00
|
|
|
|
if(boatSelect) {
|
|
|
|
|
const boatChoice = new Choices(boatSelect, {
|
|
|
|
|
loadingText: 'Wird geladen...',
|
|
|
|
|
noResultsText: 'Keine Ergebnisse gefunden',
|
|
|
|
|
noChoicesText: 'Keine Ergebnisse gefunden',
|
|
|
|
|
itemSelectText: 'Zum Auswählen klicken',
|
|
|
|
|
} as any);
|
2023-09-24 10:32:38 +02:00
|
|
|
|
|
2023-10-30 15:19:43 +01:00
|
|
|
|
boatSelect.addEventListener('addItem', function(e) {
|
2023-10-30 15:37:01 +01:00
|
|
|
|
const event = e as ChoiceBoatEvent;
|
|
|
|
|
const amount_seats = event.detail.customProperties.amount_seats;
|
2023-10-30 15:19:43 +01:00
|
|
|
|
setMaxAmountRowers("newrower", amount_seats);
|
2023-09-28 16:07:52 +02:00
|
|
|
|
|
2023-11-09 08:56:08 +01:00
|
|
|
|
const destination = <HTMLSelectElement>document.querySelector('#destination');
|
|
|
|
|
destination.value = event.detail.customProperties.default_destination;
|
|
|
|
|
|
2023-11-02 19:50:19 +01:00
|
|
|
|
if (event.detail.customProperties.owner){
|
|
|
|
|
choiceObjects["newrower"].setChoiceByValue(event.detail.customProperties.owner+"");
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-30 15:19:43 +01:00
|
|
|
|
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;
|
2023-11-12 13:33:39 +01:00
|
|
|
|
|
|
|
|
|
const distinput = <HTMLInputElement>document.querySelector('#distance_in_km');
|
|
|
|
|
distinput.value = "";
|
|
|
|
|
|
|
|
|
|
const destinput= <HTMLInputElement>document.querySelector('#destination');
|
|
|
|
|
destinput.dispatchEvent(new Event('input'));
|
2023-10-30 15:19:43 +01:00
|
|
|
|
},false);
|
2023-09-24 10:32:38 +02:00
|
|
|
|
|
2023-10-30 09:21:35 +01:00
|
|
|
|
choiceObjects[boatSelect.id] = boatChoice;
|
2023-10-30 15:19:43 +01:00
|
|
|
|
choiceObjects["boat_id"] = boatChoice;
|
2023-09-27 13:52:15 +02:00
|
|
|
|
}
|
2023-09-23 21:51:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-27 13:58:22 +02:00
|
|
|
|
function reloadPage() {
|
2023-11-02 13:50:34 +01:00
|
|
|
|
if (!window.location.href.includes("ergo")){
|
|
|
|
|
let pageTitle = document.title;
|
|
|
|
|
let attentionMessage = 'Riemen- und Dollenbruch';
|
2023-09-27 13:58:22 +02:00
|
|
|
|
|
2023-11-02 13:50:34 +01:00
|
|
|
|
document.addEventListener('visibilitychange', function() {
|
|
|
|
|
let isPageActive = !document.hidden;
|
2023-09-27 13:58:22 +02:00
|
|
|
|
|
2023-11-02 13:50:34 +01:00
|
|
|
|
if(!isPageActive){
|
|
|
|
|
document.title = attentionMessage;
|
|
|
|
|
} else {
|
|
|
|
|
document.title = pageTitle;
|
|
|
|
|
location.reload();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-09-27 13:58:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-30 13:39:58 +01:00
|
|
|
|
function setMaxAmountRowers(name: string, rowers: number) {
|
|
|
|
|
if(choiceObjects[name]) {
|
2023-10-30 15:37:01 +01:00
|
|
|
|
choiceObjects[name].removeActiveItems(-1);
|
2023-10-30 15:19:43 +01:00
|
|
|
|
//let curSelection = choiceObjects[name].getValue(true);
|
|
|
|
|
//let amount_to_delete = (<any>curSelection).length - rowers;
|
|
|
|
|
|
|
|
|
|
//if (amount_to_delete > 0){
|
|
|
|
|
// let to_delete = (<any>curSelection).slice(-amount_to_delete);
|
|
|
|
|
// for (let del of to_delete) {
|
|
|
|
|
// choiceObjects[name].removeActiveItemsByValue(del);
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2023-09-28 16:18:47 +02:00
|
|
|
|
|
2023-10-30 13:39:58 +01:00
|
|
|
|
let input = <HTMLElement>document.querySelector('#'+name);
|
2023-09-28 16:18:47 +02:00
|
|
|
|
if(input) {
|
2023-10-30 13:39:58 +01:00
|
|
|
|
choiceObjects[name].config.maxItemCount = rowers;
|
2023-09-28 16:18:47 +02:00
|
|
|
|
if (rowers === 0) {
|
2023-10-30 13:39:58 +01:00
|
|
|
|
choiceObjects[name].disable()
|
2023-09-28 16:18:47 +02:00
|
|
|
|
input.parentElement?.parentElement?.parentElement?.classList.add('hidden');
|
|
|
|
|
input.parentElement?.parentElement?.parentElement?.classList.add('md:block');
|
|
|
|
|
input.parentElement?.parentElement?.parentElement?.classList.add('opacity-50');
|
|
|
|
|
} else{
|
2023-10-30 13:39:58 +01:00
|
|
|
|
choiceObjects[name].enable();
|
2023-09-28 16:18:47 +02:00
|
|
|
|
input.parentElement?.parentElement?.parentElement?.classList.remove('hidden');
|
|
|
|
|
input.parentElement?.parentElement?.parentElement?.classList.remove('md:block');
|
|
|
|
|
input.parentElement?.parentElement?.parentElement?.classList.remove('opacity-50');
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-28 16:07:52 +02:00
|
|
|
|
|
2023-10-31 20:57:05 +01:00
|
|
|
|
//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('hidden');
|
|
|
|
|
// only_steering.parentElement?.parentElement?.parentElement?.classList.remove('md:block');
|
|
|
|
|
// 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('hidden');
|
|
|
|
|
// only_steering.parentElement?.parentElement?.parentElement?.classList.add('md:block');
|
|
|
|
|
// only_steering.parentElement?.parentElement?.parentElement?.classList.add('opacity-50');
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2023-10-31 22:16:14 +01:00
|
|
|
|
let shipmaster = <HTMLElement>document.querySelector('#shipmaster-'+name+'js');
|
|
|
|
|
let steering_person = <HTMLElement>document.querySelector('#steering_person-'+name+'js');
|
2023-10-31 20:57:05 +01:00
|
|
|
|
if (rowers == 1){
|
2023-10-31 21:08:57 +01:00
|
|
|
|
if (shipmaster.parentNode) {
|
|
|
|
|
(<HTMLElement>shipmaster.parentNode).classList.add('hidden');
|
|
|
|
|
}
|
2023-10-31 22:16:14 +01:00
|
|
|
|
shipmaster.removeAttribute('required');
|
|
|
|
|
|
2023-10-31 21:08:57 +01:00
|
|
|
|
if (steering_person.parentNode){
|
|
|
|
|
(<HTMLElement>steering_person.parentNode).classList.add('hidden');
|
|
|
|
|
}
|
2023-10-31 22:16:14 +01:00
|
|
|
|
steering_person.removeAttribute('required');
|
2023-10-31 20:57:05 +01:00
|
|
|
|
}else{
|
2023-10-31 21:08:57 +01:00
|
|
|
|
if (shipmaster.parentNode){
|
|
|
|
|
(<HTMLElement>shipmaster.parentNode).classList.remove('hidden');
|
|
|
|
|
}
|
2023-10-31 20:57:05 +01:00
|
|
|
|
shipmaster.setAttribute('required', 'required');
|
|
|
|
|
|
2023-10-31 21:08:57 +01:00
|
|
|
|
if (steering_person.parentNode){
|
|
|
|
|
(<HTMLElement>steering_person.parentNode).classList.remove('hidden');
|
|
|
|
|
}
|
2023-10-31 20:57:05 +01:00
|
|
|
|
steering_person.setAttribute('required', 'required');
|
2023-09-28 16:07:52 +02:00
|
|
|
|
}
|
2023-09-28 17:31:20 +02:00
|
|
|
|
}
|
2023-09-24 22:17:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-23 21:05:08 +02:00
|
|
|
|
function initBoatActions() {
|
|
|
|
|
const boatSelects = document.querySelectorAll('.boats-js[data-onclick="true"]');
|
|
|
|
|
if(boatSelects) {
|
|
|
|
|
Array.prototype.forEach.call(boatSelects, (select: HTMLInputElement) => {
|
|
|
|
|
select.addEventListener('click', function() {
|
|
|
|
|
if(select.dataset.seats) {
|
2023-09-28 16:07:52 +02:00
|
|
|
|
if (select.dataset.id) {
|
|
|
|
|
choiceObjects['boat_id'].setChoiceByValue(select.dataset.id);
|
|
|
|
|
}
|
2023-09-24 22:17:28 +02:00
|
|
|
|
|
2023-09-28 16:07:52 +02:00
|
|
|
|
window.scrollTo(0, 0);
|
2023-09-23 21:05:08 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function initChoices() {
|
|
|
|
|
const selects = document.querySelectorAll('select[data-init="true"]');
|
|
|
|
|
if(selects) {
|
|
|
|
|
Array.prototype.forEach.call(selects, (select: HTMLInputElement) => {
|
|
|
|
|
initNewChoice(select);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-30 09:21:35 +01:00
|
|
|
|
interface ChoiceEvent extends Event{
|
|
|
|
|
detail: {
|
|
|
|
|
value: string;
|
|
|
|
|
label: string,
|
|
|
|
|
customProperties: {
|
|
|
|
|
is_cox: boolean,
|
2023-10-30 13:39:58 +01:00
|
|
|
|
steers: boolean,
|
|
|
|
|
cox_on_boat: boolean,
|
2023-10-30 09:21:35 +01:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-23 21:05:08 +02:00
|
|
|
|
function initNewChoice(select: HTMLInputElement) {
|
2023-10-30 19:13:34 +01:00
|
|
|
|
let seats = 0;
|
|
|
|
|
if (select.dataset && select.dataset.seats) {
|
|
|
|
|
seats = +select.dataset.seats;
|
|
|
|
|
}
|
2023-10-31 22:16:14 +01:00
|
|
|
|
|
|
|
|
|
let shipmaster = <HTMLElement>document.querySelector('#shipmaster-'+select.id+'js');
|
|
|
|
|
let steering_person = <HTMLElement>document.querySelector('#steering_person-'+select.id+'js');
|
|
|
|
|
if (seats == 1){
|
|
|
|
|
if (shipmaster.parentNode) {
|
|
|
|
|
(<HTMLElement>shipmaster.parentNode).classList.add('hidden');
|
|
|
|
|
}
|
|
|
|
|
shipmaster.removeAttribute('required');
|
|
|
|
|
|
|
|
|
|
if (steering_person.parentNode){
|
|
|
|
|
(<HTMLElement>steering_person.parentNode).classList.add('hidden');
|
|
|
|
|
}
|
|
|
|
|
steering_person.removeAttribute('required');
|
|
|
|
|
}else{
|
|
|
|
|
if (shipmaster.parentNode){
|
|
|
|
|
(<HTMLElement>shipmaster.parentNode).classList.remove('hidden');
|
|
|
|
|
}
|
|
|
|
|
shipmaster.setAttribute('required', 'required');
|
|
|
|
|
|
|
|
|
|
if (steering_person.parentNode){
|
|
|
|
|
(<HTMLElement>steering_person.parentNode).classList.remove('hidden');
|
|
|
|
|
}
|
|
|
|
|
steering_person.setAttribute('required', 'required');
|
|
|
|
|
}
|
2023-09-23 21:05:08 +02:00
|
|
|
|
const choice = new Choices(select, {
|
|
|
|
|
removeItemButton: true,
|
|
|
|
|
loadingText: 'Wird geladen...',
|
|
|
|
|
noResultsText: 'Keine Ergebnisse gefunden',
|
|
|
|
|
noChoicesText: 'Keine Ergebnisse gefunden',
|
|
|
|
|
itemSelectText: 'Zum Auswählen klicken',
|
|
|
|
|
placeholderValue: 'Ruderer auswählen',
|
2023-10-30 19:13:34 +01:00
|
|
|
|
maxItemCount: seats,
|
2023-09-23 21:05:08 +02:00
|
|
|
|
maxItemText: (maxItemCount) => {
|
|
|
|
|
return `Nur ${maxItemCount} Ruderer können hinzugefügt werden`;
|
|
|
|
|
},
|
2023-10-30 13:39:58 +01:00
|
|
|
|
callbackOnInit: function() {
|
|
|
|
|
this._currentState.items.forEach(function(obj){
|
|
|
|
|
if (obj.customProperties && obj.customProperties.is_cox){
|
|
|
|
|
const coxSelect = <HTMLSelectElement>document.querySelector('#shipmaster-' + select.id + 'js');
|
|
|
|
|
var new_option = new Option(obj.label, obj.value);
|
|
|
|
|
if (obj.customProperties.cox_on_boat){
|
|
|
|
|
new_option.selected = true;
|
|
|
|
|
}
|
|
|
|
|
coxSelect.add(new_option);
|
|
|
|
|
}
|
|
|
|
|
const steeringSelect = <HTMLSelectElement>document.querySelector('#steering_person-' + select.id + 'js');
|
|
|
|
|
if (steeringSelect) {
|
|
|
|
|
var new_option = new Option(obj.label, obj.value);
|
|
|
|
|
if (obj.customProperties && obj.customProperties.steers){
|
|
|
|
|
new_option.selected = true;
|
|
|
|
|
}
|
|
|
|
|
steeringSelect.add(new_option);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-09-23 21:05:08 +02:00
|
|
|
|
});
|
2023-10-30 13:39:58 +01:00
|
|
|
|
choiceObjects[select.id] = choice;
|
2023-09-23 21:05:08 +02:00
|
|
|
|
|
2023-10-30 09:21:35 +01:00
|
|
|
|
select.addEventListener('addItem', function(e) {
|
|
|
|
|
const event = e as ChoiceEvent;
|
|
|
|
|
const user_id = event.detail.value;
|
|
|
|
|
const name = event.detail.label;
|
|
|
|
|
|
|
|
|
|
if (event.detail.customProperties.is_cox) {
|
2023-10-30 13:39:58 +01:00
|
|
|
|
const coxSelect = <HTMLSelectElement>document.querySelector('#shipmaster-' + select.id + 'js');
|
2023-10-30 09:21:35 +01:00
|
|
|
|
if (coxSelect){
|
|
|
|
|
coxSelect.add(new Option(name, user_id));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-30 13:39:58 +01:00
|
|
|
|
const steeringSelect = <HTMLSelectElement>document.querySelector('#steering_person-' + select.id + 'js');
|
2023-10-30 09:21:35 +01:00
|
|
|
|
if (steeringSelect) {
|
|
|
|
|
steeringSelect.add(new Option(name, user_id));
|
|
|
|
|
}
|
|
|
|
|
},false);
|
|
|
|
|
|
|
|
|
|
select.addEventListener('removeItem', function(e) {
|
|
|
|
|
const event = e as ChoiceEvent;
|
|
|
|
|
|
|
|
|
|
const user_id = event.detail.value;
|
|
|
|
|
|
2023-10-30 13:39:58 +01:00
|
|
|
|
const coxSelect = <HTMLSelectElement>document.querySelector('#shipmaster-' + select.id + 'js');
|
2023-10-30 09:21:35 +01:00
|
|
|
|
if (coxSelect) {
|
|
|
|
|
for (var i=0; i<coxSelect.length; i++) {
|
|
|
|
|
if (coxSelect.options[i].value == user_id)
|
|
|
|
|
coxSelect.remove(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-30 13:39:58 +01:00
|
|
|
|
const steeringSelect = <HTMLSelectElement>document.querySelector('#steering_person-' + select.id + 'js');
|
2023-10-30 09:21:35 +01:00
|
|
|
|
if (steeringSelect) {
|
|
|
|
|
for (var i=0; i<steeringSelect.length; i++) {
|
|
|
|
|
if (steeringSelect.options[i].value == user_id)
|
|
|
|
|
steeringSelect.remove(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},false);
|
2023-09-23 21:05:08 +02:00
|
|
|
|
|
|
|
|
|
choiceObjects[select.id] = choice;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-30 09:21:35 +01:00
|
|
|
|
|
2023-04-07 12:37:33 +02:00
|
|
|
|
function initToggle() {
|
2023-04-10 22:42:00 +02:00
|
|
|
|
// get filter btns & set object sessionStorage
|
|
|
|
|
const btns = <NodeListOf<HTMLButtonElement>>document.querySelectorAll('.filter-trips-js');
|
|
|
|
|
let filterObject = new Map();
|
2023-04-07 12:37:33 +02:00
|
|
|
|
|
2023-04-10 22:42:00 +02:00
|
|
|
|
if(btns) {
|
|
|
|
|
Array.prototype.forEach.call(btns, (btn: HTMLButtonElement) => {
|
|
|
|
|
filterObject.set(btn.dataset.action, btn.ariaPressed);
|
|
|
|
|
|
|
|
|
|
btn.addEventListener('click', () => {
|
|
|
|
|
let filter = sessionStorage.getItem('tripsFilter');
|
|
|
|
|
if(filter) {
|
|
|
|
|
let filterMap = new Map(JSON.parse(filter));
|
|
|
|
|
for (let entry of filterMap.entries()) {
|
2023-04-10 22:46:35 +02:00
|
|
|
|
if(entry[0] === btn.dataset.action && entry[1] !== 'true') {
|
2023-04-10 22:42:00 +02:00
|
|
|
|
filterMap.set(entry[0],'true');
|
|
|
|
|
} else {
|
|
|
|
|
filterMap.set(entry[0],'false');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sessionStorage.setItem('tripsFilter', JSON.stringify( Array.from(filterMap.entries())));
|
|
|
|
|
}
|
|
|
|
|
resetFilteredElements();
|
2023-04-11 08:27:58 +02:00
|
|
|
|
if(btn.getAttribute('aria-pressed') === 'false'){
|
2023-04-10 22:42:00 +02:00
|
|
|
|
Array.prototype.forEach.call(btns, (b: HTMLButtonElement) => {
|
|
|
|
|
b.setAttribute('aria-pressed', 'false');
|
|
|
|
|
});
|
|
|
|
|
triggerFilterAction(btn.dataset.action);
|
2023-04-10 22:46:35 +02:00
|
|
|
|
} else {
|
|
|
|
|
btn.setAttribute('aria-pressed', 'false');
|
2023-04-10 22:42:00 +02:00
|
|
|
|
}
|
2023-04-07 12:37:33 +02:00
|
|
|
|
});
|
2023-04-10 22:42:00 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let filter = sessionStorage.getItem('tripsFilter');
|
|
|
|
|
if(filter) {
|
|
|
|
|
let filterMap = new Map(JSON.parse(filter));
|
|
|
|
|
for (let entry of filterMap.entries()) {
|
|
|
|
|
if(entry[1] === 'true') {
|
|
|
|
|
triggerFilterAction(entry[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
sessionStorage.setItem('tripsFilter', JSON.stringify( Array.from(filterObject.entries())));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function resetFilteredElements() {
|
|
|
|
|
const hiddenElements = document.querySelectorAll('.reset-js.hidden');
|
|
|
|
|
if(hiddenElements) {
|
|
|
|
|
Array.prototype.forEach.call(hiddenElements, (hiddenElement: HTMLButtonElement) => {
|
|
|
|
|
hiddenElement.classList.remove('hidden');
|
2023-04-07 12:37:33 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
2023-04-10 22:42:00 +02:00
|
|
|
|
}
|
2023-04-07 12:37:33 +02:00
|
|
|
|
|
2023-04-10 22:42:00 +02:00
|
|
|
|
function triggerFilterAction(activeFilter: any) {
|
|
|
|
|
const activeBtn = document.querySelector('button[data-action="' + activeFilter + '"]');
|
|
|
|
|
if(activeBtn) {
|
|
|
|
|
activeBtn.setAttribute('aria-pressed', 'true');
|
2023-04-07 12:37:33 +02:00
|
|
|
|
|
2023-04-10 22:42:00 +02:00
|
|
|
|
filterAction(activeFilter);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-07 12:37:33 +02:00
|
|
|
|
|
2023-04-10 22:42:00 +02:00
|
|
|
|
function filterAction(activeFilter: string) {
|
|
|
|
|
switch(activeFilter) {
|
|
|
|
|
case 'filter-days': {
|
|
|
|
|
filterDays();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 'filter-coxs': {
|
|
|
|
|
filterCoxs();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-04-07 12:37:33 +02:00
|
|
|
|
}
|
2023-04-10 22:42:00 +02:00
|
|
|
|
}
|
2023-04-07 21:59:25 +02:00
|
|
|
|
|
2023-04-10 22:42:00 +02:00
|
|
|
|
function filterDays() {
|
|
|
|
|
const daysNoTrips = document.querySelectorAll('div[data-trips="0"]');
|
|
|
|
|
Array.prototype.forEach.call(daysNoTrips, (day: HTMLElement) => {
|
|
|
|
|
day.classList.toggle('hidden');
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-04-07 21:59:25 +02:00
|
|
|
|
|
2023-04-10 22:42:00 +02:00
|
|
|
|
function filterCoxs() {
|
|
|
|
|
const noCoxNeeded = document.querySelectorAll('div[data-coxneeded="false"]');
|
|
|
|
|
Array.prototype.forEach.call(noCoxNeeded, (notNeeded: HTMLElement) => {
|
|
|
|
|
notNeeded.classList.toggle('hidden');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-07 12:37:33 +02:00
|
|
|
|
function initSearch() {
|
2023-04-06 10:27:04 +02:00
|
|
|
|
const input = <HTMLInputElement>document.querySelector('#filter-js');
|
|
|
|
|
|
|
|
|
|
if(input) {
|
2023-04-06 10:45:33 +02:00
|
|
|
|
filterElements(input.value);
|
|
|
|
|
|
2023-04-06 10:27:04 +02:00
|
|
|
|
input.addEventListener('input', () => {
|
|
|
|
|
filterElements(input.value);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function filterElements(input: string) {
|
2023-09-27 15:36:07 +02:00
|
|
|
|
const elements = document.querySelectorAll('div[data-filterable="true"]');
|
2023-04-06 10:45:33 +02:00
|
|
|
|
let resultWrapper = <HTMLElement>document.querySelector('#filter-result-js'),
|
|
|
|
|
amountShownElements = 0;
|
2023-04-06 10:27:04 +02:00
|
|
|
|
|
|
|
|
|
Array.prototype.forEach.call(elements, (element: HTMLElement) => {
|
|
|
|
|
// set both strings (input & dataset filter) to lowercase to not be case sensitive
|
|
|
|
|
let filterString = element.dataset.filter?.toLocaleLowerCase();
|
2023-04-06 10:45:33 +02:00
|
|
|
|
|
|
|
|
|
// bulk hide all elements
|
|
|
|
|
element.style.display = 'none';
|
2023-04-06 10:27:04 +02:00
|
|
|
|
|
2023-04-06 10:45:33 +02:00
|
|
|
|
// show if input matches
|
|
|
|
|
if(filterString?.includes(input.toLocaleLowerCase())) {
|
|
|
|
|
element.style.display = 'flex';
|
|
|
|
|
amountShownElements ++;
|
2023-04-06 10:27:04 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
2023-04-06 10:45:33 +02:00
|
|
|
|
|
|
|
|
|
if(resultWrapper) {
|
|
|
|
|
resultWrapper.innerHTML = (amountShownElements === 0 ? 'Kein Ergebnis gefunden' : '<strong>' + amountShownElements + '</strong>' + (amountShownElements > 1 ? ' Ergebnisse' : ' Ergebnis') + ' gefunden');
|
|
|
|
|
}
|
2023-04-06 10:27:04 +02:00
|
|
|
|
}
|
2023-04-06 13:15:40 +02:00
|
|
|
|
|
|
|
|
|
function initSidebar() {
|
|
|
|
|
const sidebarTrigger = <NodeListOf<HTMLElement>>document.querySelectorAll('[data-trigger]');
|
|
|
|
|
|
|
|
|
|
if(sidebarTrigger) {
|
|
|
|
|
Array.prototype.forEach.call(sidebarTrigger, (triggerElement: HTMLElement) => {
|
|
|
|
|
if(triggerElement.dataset.trigger) {
|
|
|
|
|
const sidebar = new Sidebar(triggerElement.dataset.trigger);
|
|
|
|
|
|
2023-04-08 07:35:49 +02:00
|
|
|
|
triggerElement.addEventListener('click', (e) => {
|
|
|
|
|
e.preventDefault();
|
2023-04-08 09:14:48 +02:00
|
|
|
|
if(triggerElement.dataset.trigger === 'sidebar') {
|
2023-04-07 11:35:39 +02:00
|
|
|
|
initTripSidebar(triggerElement);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-06 13:15:40 +02:00
|
|
|
|
sidebar.toggle();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-07 11:35:39 +02:00
|
|
|
|
|
|
|
|
|
function initTripSidebar(triggerElement: HTMLElement) {
|
2023-04-08 09:14:48 +02:00
|
|
|
|
const sidebarElement = <HTMLElement>document.querySelector('#sidebar');
|
2023-04-08 09:17:46 +02:00
|
|
|
|
if(sidebarElement && triggerElement.dataset.body && triggerElement.dataset.header) {
|
|
|
|
|
let body = <HTMLElement>document.querySelector(triggerElement.dataset.body);
|
|
|
|
|
let bodyElement = <HTMLElement>body.cloneNode(true);
|
|
|
|
|
let bodyContainerElement = <HTMLElement>sidebarElement.querySelector('.body-js');
|
2023-09-23 21:05:08 +02:00
|
|
|
|
|
2023-06-08 15:28:08 +02:00
|
|
|
|
|
|
|
|
|
/* Quickfix duplicate ids checkboxes */
|
|
|
|
|
const checkboxes = <NodeListOf<HTMLElement>>bodyElement.querySelectorAll('input[type="checkbox"]');
|
|
|
|
|
|
|
|
|
|
Array.prototype.forEach.call(checkboxes, (checkbox: HTMLElement) => {
|
|
|
|
|
if(checkbox) {
|
|
|
|
|
checkbox.parentElement?.setAttribute('for', checkbox.id + 'js');
|
|
|
|
|
checkbox.id += 'js';
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-09-05 23:03:18 +02:00
|
|
|
|
const prefixedContent = <NodeListOf<HTMLElement>>bodyElement.querySelectorAll('.change-id-js');
|
|
|
|
|
Array.prototype.forEach.call(prefixedContent, (content: HTMLElement) => {
|
|
|
|
|
if(content) {
|
|
|
|
|
content.id += 'js';
|
|
|
|
|
|
|
|
|
|
if(content.dataset.relation){
|
|
|
|
|
content.dataset.relation += 'js';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-10-30 13:39:58 +01:00
|
|
|
|
|
2023-04-08 09:17:46 +02:00
|
|
|
|
if(bodyContainerElement) {
|
|
|
|
|
bodyContainerElement.innerHTML = '';
|
|
|
|
|
bodyContainerElement.append(bodyElement);
|
2023-09-05 23:03:18 +02:00
|
|
|
|
|
|
|
|
|
addRelationMagic(bodyElement);
|
2023-04-07 11:35:39 +02:00
|
|
|
|
}
|
|
|
|
|
if(triggerElement.dataset.day) {
|
2023-04-08 09:17:46 +02:00
|
|
|
|
let hiddenElement = <HTMLInputElement>bodyElement.querySelector('.day-js');
|
2023-04-07 11:35:39 +02:00
|
|
|
|
if(hiddenElement) {
|
|
|
|
|
hiddenElement.value = triggerElement.dataset.day;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let headerElement = sidebarElement.querySelector('.header-js');
|
|
|
|
|
if(headerElement) {
|
|
|
|
|
headerElement.innerHTML = triggerElement.dataset.header;
|
|
|
|
|
}
|
2023-10-30 13:39:58 +01:00
|
|
|
|
const selects = bodyElement.querySelectorAll('select[multiple]');
|
|
|
|
|
if(selects) {
|
|
|
|
|
Array.prototype.forEach.call(selects, (select: HTMLInputElement) => {
|
|
|
|
|
initNewChoice(select);
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-04-07 11:35:39 +02:00
|
|
|
|
}
|
2023-10-30 13:39:58 +01:00
|
|
|
|
const defaultDateTimes = <NodeListOf<HTMLInputElement>>document.querySelectorAll('.current-date-time');
|
|
|
|
|
defaultDateTimes.forEach((defaultDateTime) => {
|
|
|
|
|
setCurrentdate(defaultDateTime);
|
|
|
|
|
});
|
|
|
|
|
|
2023-04-07 11:35:39 +02:00
|
|
|
|
}
|
2023-04-10 22:56:47 +02:00
|
|
|
|
|
2023-09-05 23:03:18 +02:00
|
|
|
|
function addRelationMagic(bodyElement: HTMLElement) {
|
|
|
|
|
const fields = bodyElement.querySelectorAll('.set-distance-js');
|
2023-09-23 22:31:19 +02:00
|
|
|
|
|
2023-09-05 23:03:18 +02:00
|
|
|
|
if(fields) {
|
|
|
|
|
Array.prototype.forEach.call(fields, (field: HTMLInputElement) => {
|
|
|
|
|
if(field.dataset.relation){
|
|
|
|
|
const relatedField = <HTMLInputElement>bodyElement.querySelector('#' + field.dataset.relation);
|
|
|
|
|
if(relatedField) {
|
|
|
|
|
field.addEventListener('input', (e) => {
|
|
|
|
|
e.preventDefault();
|
2023-09-23 22:31:19 +02:00
|
|
|
|
const dataList = <HTMLDataListElement>document.querySelector('#destinations');
|
2023-09-05 23:03:18 +02:00
|
|
|
|
if(dataList) {
|
|
|
|
|
var option = Array.prototype.find.call(dataList.options, function(option) {
|
|
|
|
|
return option.value === field.value;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Get distance
|
|
|
|
|
const distance = option.getAttribute('distance');
|
|
|
|
|
if(distance) relatedField.value = distance;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-10 22:56:47 +02:00
|
|
|
|
function replaceStrings() {
|
|
|
|
|
const weekdays = document.querySelectorAll('.weekday-js');
|
|
|
|
|
Array.prototype.forEach.call(weekdays, (weekday: HTMLElement) => {
|
|
|
|
|
weekday.innerHTML = weekday.innerHTML.replace('Freitag', 'Markttag');
|
|
|
|
|
});
|
|
|
|
|
}
|