This commit is contained in:
philipp 2023-04-07 11:58:00 +02:00
commit 0b961ca1b8
4 changed files with 91 additions and 64 deletions

View File

@ -17,7 +17,7 @@ export class Sidebar {
this.isOpen = false;
}
checkStatus() {
checkStatus(): Boolean {
return this.isOpen;
}

View File

@ -51,10 +51,37 @@ function initSidebar() {
const sidebar = new Sidebar(triggerElement.dataset.trigger);
triggerElement.addEventListener('click', () => {
if(triggerElement.dataset.trigger === 'addTrip') {
initTripSidebar(triggerElement);
}
sidebar.toggle();
});
}
});
}
}
function initTripSidebar(triggerElement: HTMLElement) {
const sidebarElement = <HTMLElement>document.querySelector('#addTrip');
if(sidebarElement && triggerElement.dataset.form && triggerElement.dataset.header) {
let form = <HTMLElement>document.querySelector(triggerElement.dataset.form);
let formElement = <HTMLElement>form.cloneNode(true);
let formContainerElement = <HTMLElement>sidebarElement.querySelector('.form-js');
if(formContainerElement) {
formContainerElement.innerHTML = '';
formContainerElement.append(formElement);
}
if(triggerElement.dataset.day) {
let hiddenElement = <HTMLInputElement>formElement.querySelector('.day-js');
if(hiddenElement) {
hiddenElement.value = triggerElement.dataset.day;
}
}
let headerElement = sidebarElement.querySelector('.header-js');
if(headerElement) {
headerElement.innerHTML = triggerElement.dataset.header;
}
}
}

View File

@ -31,7 +31,6 @@ async fn index(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage<'_
.signed_duration_since(Local::now().date_naive())
.num_days();
}
show_next_n_days = 2;
for i in 0..show_next_n_days + 1 {
let date = (Local::now() + Duration::days(i)).date_naive();

View File

@ -179,7 +179,12 @@
</div>
{% if trip.cox_id == loggedin_user.id %}
{% if trip.rower | length == 0 %}
<a href="/cox/remove/trip/{{ trip.id }}">LÖSCHEN</a>
<div class="text-right mt-2">
<a href="/cox/remove/trip/{{ trip.id }}" class="inline-block btn btn-alert">
{% include "includes/delete-icon" %}
Termin löschen
</a>
</div>
{% endif %}
<div>
<h3>Edit trip</h3>
@ -201,75 +206,71 @@
<div>
{% if loggedin_user.is_admin %}
<a href="#" data-sidebar="true" data-trigger="plannedTrip{{ loop.index }}"
<a href="#" data-sidebar="true" data-trigger="addTrip"
data-header="<strong>Event</strong> am {{ day.day| date(format='%d.%m.%Y') }} erstellen"
data-day="{{ day.day }}"
data-form="#addEventForm"
class="inline-block link-dark mr-3">Event hinzufügen</a>
<!-- START Sidebar plannedTrip -->
<div class="sidebar slide-in from-right" id="plannedTrip{{ loop.index }}" aria-modal="false">
<div class="bg-primary-900 text-white px-2 py-3 flex justify-between sidebar-header">
<div>
<span class="ps-1">
<strong>Event</strong> am {{ day.day| date(format="%d.%m.%Y") }} erstellen
</span>
</div>
<button type="button" title="Add planned event schließen"
class="sidebar-close border-0 bg-primary-600 text-black" data-trigger="plannedTrip{{ loop.index }}">
x
</button>
</div>
<div class="px-2 pt-2" style="margin-top: 63px; margin-bottom: 157px">
<form action="/admin/planned-event" method="post" class="grid gap-3">
<input type="hidden" name="day" value="{{ day.day }}" />
{{ macros::input(label='Titel (z.B. Firmenrudern)', name='name', type='text', required=true) }}
{{ macros::input(label='Startzeit', name='planned_starting_time', type='text', required=true) }}
{{ macros::input(label='Anzahl Steuerleute', name='planned_amount_cox', type='number', required=true) }}
{{ macros::input(label='Anzahl Ruderer', name='max_people', type='number', required=true) }}
{{ macros::checkbox(label='Gäste erlauben', name='max_allow_guestspeople') }}
{{ macros::input(label='Anmerkungen', name='notes', type='text') }}
<input value="Erstellen"
class="w-full rounded-md bg-primary-600 px-3 py-2 text-sm font-semibold text-white hover:bg-primary-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600 cursor-pointer"
type="submit" />
</form>
</div>
</div>
<div class="sidebar-overlay" data-trigger="plannedTrip{{ loop.index }}"></div>
<!-- END Sidebar plannedTrip -->
{% endif %}
{% if loggedin_user.is_cox%}
<a href="#" data-sidebar="true" data-trigger="trip{{ loop.index }}"
<a href="#" data-sidebar="true" data-trigger="addTrip"
data-header="<strong>Ausfahrt</strong> am {{ day.day| date(format='%d.%m.%Y') }} erstellen"
data-day="{{ day.day }}"
data-form="#addTripForm"
class="inline-block link-primary">Ausfahrt hinzufügen</a>
<div class="sidebar slide-in from-right" id="trip{{ loop.index }}" aria-modal="false">
<div class="bg-primary-900 text-white px-2 py-3 flex justify-between sidebar-header">
<div>
<span class="ps-1">
<strong>Ausfahrt</strong> am {{ day.day| date(format="%d.%m.%Y") }} erstellen
</span>
</div>
<button type="button" title="Add trip schließen" class="sidebar-close border-0 bg-primary-600 text-black"
data-trigger="trip{{ loop.index }}">
x
</button>
</div>
<div class="px-2 pt-2" style="margin-top: 63px; margin-bottom: 157px">
<form action="/cox/trip" method="post" class="grid gap-3">
<input type="hidden" name="day" value="{{ day.day }}" />
{{ macros::input(label='Startzeit', name='planned_starting_time', type='text', required=true) }}
{{ macros::input(label='Anzahl Ruderer', name='max_people', type='number', required=true) }}
{{ macros::input(label='Anmerkungen', name='notes', type='text') }}
<input value="Erstellen"
class="w-full rounded-md bg-primary-600 px-3 py-2 text-sm font-semibold text-white hover:bg-primary-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600 cursor-pointer"
type="submit" />
</form>
</div>
</div>
<div class="sidebar-overlay" data-trigger="trip{{ loop.index }}"></div>
{% endif %}
</div>
</div>
{% endfor %}
</div>
</div>
{# --- START Add Trip Sidebar --- #}
<div class="sidebar slide-in from-right" id="addTrip" aria-modal="false">
<div class="bg-primary-900 text-white px-2 py-3 flex justify-between sidebar-header">
<div>
<span class="ps-1 header-js">
Überschrift (wird ersetzt)
</span>
</div>
<button type="button" title="Ausfahrt erstellen schließen" class="sidebar-close border-0 bg-primary-600 text-black"
data-trigger="addTrip">
x
</button>
</div>
<div class="form-js px-2 pt-2" style="margin-top: 63px; margin-bottom: 157px">
Formular wird ersetzt
</div>
</div>
<div class="sidebar-overlay" data-trigger="addTrip"></div>
{# --- END Add Trip Sidebar --- #}
{# --- START Form Add Trip --- #}
<div class="hidden">
<form action="/cox/trip" method="post" class="grid gap-3" id="addTripForm">
<input class="day-js" type="hidden" name="day" value="" />
{{ macros::input(label='Startzeit', name='planned_starting_time', type='input', required=true) }}
{{ macros::input(label='Anzahl Ruderer', name='max_people', type='number', required=true) }}
{{ macros::input(label='Anmerkungen', name='notes', type='input') }}
<input value="Erstellen" class="w-full btn btn-primary" type="submit" />
</form>
</div>
{# --- END Form Add Trip --- #}
{# --- START Form Add Event --- #}
<div class="hidden">
<form action="/admin/planned-event" method="post" class="grid gap-3" id="addEventForm">
<input class="day-js" type="hidden" name="day" value="" />
{{ macros::input(label='Titel (z.B. Firmenrudern)', name='name', type='text', required=true) }}
{{ macros::input(label='Startzeit', name='planned_starting_time', type='text', required=true) }}
{{ macros::input(label='Anzahl Steuerleute', name='planned_amount_cox', type='number', required=true) }}
{{ macros::input(label='Anzahl Ruderer', name='max_people', type='number', required=true) }}
{{ macros::checkbox(label='Gäste erlauben', name='max_allow_guestspeople') }}
{{ macros::input(label='Anmerkungen', name='notes', type='text') }}
<input value="Erstellen" class="w-full btn btn-primary" type="submit" />
</form>
</div>
{# --- END Form Add Event --- #}
{% endblock content %}