[TASK] refactor sidebar

This commit is contained in:
Marie Birner 2023-04-08 09:14:48 +02:00
parent b926605ab6
commit f1c812b436
3 changed files with 97 additions and 107 deletions

View File

@ -17,10 +17,6 @@ export class Sidebar {
this.isOpen = false; this.isOpen = false;
} }
checkStatus(): Boolean {
return this.isOpen;
}
toggle() { toggle() {
this.isOpen = !this.isOpen; this.isOpen = !this.isOpen;
if(this.trigger) { if(this.trigger) {

View File

@ -105,7 +105,7 @@ function initSidebar() {
triggerElement.addEventListener('click', (e) => { triggerElement.addEventListener('click', (e) => {
e.preventDefault(); e.preventDefault();
if(triggerElement.dataset.trigger === 'addTrip' && !sidebar.isOpen) { if(triggerElement.dataset.trigger === 'sidebar') {
initTripSidebar(triggerElement); initTripSidebar(triggerElement);
} }
@ -117,11 +117,11 @@ function initSidebar() {
} }
function initTripSidebar(triggerElement: HTMLElement) { function initTripSidebar(triggerElement: HTMLElement) {
const sidebarElement = <HTMLElement>document.querySelector('#addTrip'); const sidebarElement = <HTMLElement>document.querySelector('#sidebar');
if(sidebarElement && triggerElement.dataset.form && triggerElement.dataset.header) { if(sidebarElement && triggerElement.dataset.form && triggerElement.dataset.header) {
let form = <HTMLElement>document.querySelector(triggerElement.dataset.form); let form = <HTMLElement>document.querySelector(triggerElement.dataset.form);
let formElement = <HTMLElement>form.cloneNode(true); let formElement = <HTMLElement>form.cloneNode(true);
let formContainerElement = <HTMLElement>sidebarElement.querySelector('.form-js'); let formContainerElement = <HTMLElement>sidebarElement.querySelector('.body-js');
if(formContainerElement) { if(formContainerElement) {
formContainerElement.innerHTML = ''; formContainerElement.innerHTML = '';
formContainerElement.append(formElement); formContainerElement.append(formElement);

View File

@ -35,6 +35,7 @@
<small class="inline-block ml-1 text-xs text-gray-400">{{ day.day | date(format="%A", locale="de_AT") }}</small> <small class="inline-block ml-1 text-xs text-gray-400">{{ day.day | date(format="%A", locale="de_AT") }}</small>
</h2> </h2>
{# --- START Events --- #}
{% if day.planned_events | length > 0 %} {% if day.planned_events | length > 0 %}
<div class="grid grid-cols-1 gap-3 divide-y mb-3"> <div class="grid grid-cols-1 gap-3 divide-y mb-3">
{% for planned_event in day.planned_events %} {% for planned_event in day.planned_events %}
@ -43,10 +44,16 @@
<div> <div>
<strong class="text-primary-900">{{ planned_event.planned_starting_time }} Uhr</strong> <small <strong class="text-primary-900">{{ planned_event.planned_starting_time }} Uhr</strong> <small
class="text-gray-600">({{ planned_event.name }})</small><br /> class="text-gray-600">({{ planned_event.name }})</small><br />
<a href="#" data-sidebar="true" data-trigger="detailEvent{{ planned_event.id }}"
class="inline-block mr-3 link-primary">Details</a> <a href="#" data-sidebar="true" data-trigger="sidebar"
data-header="<strong>{{ planned_event.planned_starting_time }} Uhr</strong> ({{ planned_event.name }}){% if planned_event.notes %}<small class='block'>{{ planned_event.notes }}</small>{% endif %}"
data-form="#event{{ planned_event.trip_details_id }}"
class="inline-block link-primary mr-3">
Details
</a>
</div> </div>
<div class="text-right grid gap-2"> <div class="text-right grid gap-2">
{# --- START Row Buttons --- #}
{% set_global cur_user_participates = false %} {% set_global cur_user_participates = false %}
{% for rower in planned_event.rower%} {% for rower in planned_event.rower%}
{% if rower.name == loggedin_user.name %} {% if rower.name == loggedin_user.name %}
@ -61,9 +68,10 @@
<a href="/join/{{ planned_event.trip_details_id }}" class="btn btn-primary btn-fw">Mitrudern</a> <a href="/join/{{ planned_event.trip_details_id }}" class="btn btn-primary btn-fw">Mitrudern</a>
{% endif %} {% endif %}
{% endif %} {% endif %}
{# --- END Row Buttons --- #}
{# --- START Cox Buttons --- #}
{% if loggedin_user.is_cox %} {% if loggedin_user.is_cox %}
{% set_global cur_user_participates = false %} {% set_global cur_user_participates = false %}
{% for cox in planned_event.cox %} {% for cox in planned_event.cox %}
{% if cox.name == loggedin_user.name %} {% if cox.name == loggedin_user.name %}
@ -82,26 +90,13 @@
</a> </a>
{% endif %} {% endif %}
{% endif %} {% endif %}
{# --- END Cox Buttons --- #}
</div> </div>
</div> </div>
<div class="sidebar slide-in from-right" id="detailEvent{{ planned_event.id }}" aria-modal="false"> {# --- START Sidebar Content --- #}
<div class="bg-primary-900 text-white px-2 py-3 flex justify-between sidebar-header"> <div class="hidden">
<div class="ps-1"> <div id="event{{ planned_event.trip_details_id }}">
<strong>{{ planned_event.planned_starting_time }} Uhr</strong> ({{ planned_event.name }})
{% if planned_event.notes %}
<small class="block">{{ planned_event.notes }}</small>
{% endif %}
</div>
<div>
<button type="button" title="Details schließen" class="sidebar-close border-0 bg-primary-600 text-black"
data-trigger="detailEvent{{ planned_event.id }}">
x
</button>
</div>
</div>
<div class="px-2 pt-2" style="margin-top: 63px; margin-bottom: 157px">
{# --- START List Coxes --- #} {# --- START List Coxes --- #}
{% if planned_event.planned_amount_cox > 0 %} {% if planned_event.planned_amount_cox > 0 %}
{% set amount_cur_cox = planned_event.cox | length %} {% set amount_cur_cox = planned_event.cox | length %}
@ -132,13 +127,14 @@
{# --- END Delete Btn --- #} {# --- END Delete Btn --- #}
</div> </div>
</div> </div>
<div class="sidebar-overlay" data-trigger="detailEvent{{ planned_event.id }}"></div> {# --- END Sidebar Content --- #}
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
{% endif %} {% endif %}
{# --- END Events --- #}
{# --- START Trips --- #}
{% if day.trips | length > 0 %} {% if day.trips | length > 0 %}
<div class="grid grid-cols-1 gap-3 divide-y mb-3"> <div class="grid grid-cols-1 gap-3 divide-y mb-3">
{% for trip in day.trips %} {% for trip in day.trips %}
@ -147,9 +143,14 @@
<div> <div>
<strong class="text-primary-900">{{ trip.planned_starting_time }} Uhr</strong> <small <strong class="text-primary-900">{{ trip.planned_starting_time }} Uhr</strong> <small
class="text-gray-600">({{ trip.cox_name }})</small><br /> class="text-gray-600">({{ trip.cox_name }})</small><br />
<a href="#" data-sidebar="true" data-trigger="detailTrip{{ trip.trip_details_id }}" <a href="#" data-sidebar="true" data-trigger="sidebar"
class="inline-block link-primary mr-3">Details</a> data-header="<strong>{{ trip.planned_starting_time }} Uhr</strong> ({{ trip.cox_name }}){% if trip.notes %}<small class='block'>{{ trip.notes }}</small>{% endif %}"
data-form="#trip{{ trip.trip_details_id }}"
class="inline-block link-primary mr-3">
Details
</a>
</div> </div>
<div> <div>
{% set_global cur_user_participates = false %} {% set_global cur_user_participates = false %}
{% for rower in trip.rower %} {% for rower in trip.rower %}
@ -161,33 +162,22 @@
<a href="/remove/{{ trip.trip_details_id }}" <a href="/remove/{{ trip.trip_details_id }}"
class="inline-block rounded-md bg-[#f43f5e] px-3 py-2 text-sm font-semibold text-white hover:bg-[#ff0000] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#ff0000] cursor-pointer">Abmelden</a> class="inline-block rounded-md bg-[#f43f5e] px-3 py-2 text-sm font-semibold text-white hover:bg-[#ff0000] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#ff0000] cursor-pointer">Abmelden</a>
{% endif %} {% endif %}
{% if trip.max_people > trip.rower | length and trip.cox_id != loggedin_user.id and cur_user_participates {% if trip.max_people > trip.rower | length and trip.cox_id != loggedin_user.id and cur_user_participates == false%}
== false%}
<a href="/join/{{ trip.trip_details_id }}" <a href="/join/{{ trip.trip_details_id }}"
class="inline-block 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">Mitrudern</a> class="inline-block 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">Mitrudern</a>
{% endif %} {% endif %}
</div> </div>
</div> </div>
</div> </div>
<div class="sidebar slide-in from-right" id="detailTrip{{ trip.trip_details_id }}" aria-modal="false">
<div class="bg-primary-900 text-white px-2 py-3 flex justify-between sidebar-header"> {# --- START Sidebar Content --- #}
<div class="ps-1"> <div class="hidden">
<strong>{{ trip.planned_starting_time }} Uhr</strong> ({{ trip.cox_name }}) <div id="trip{{ trip.trip_details_id }}">
{% if trip.notes %}
<small class="block">{{ trip.notes }}</small>
{% endif %}
</div>
<div>
<button type="button" title="Details schließen" class="sidebar-close border-0 bg-primary-600 text-black"
data-trigger="detailTrip{{ trip.trip_details_id }}">
x
</button>
</div>
</div>
<div class="px-2 pt-2" style="margin-top: 63px; margin-bottom: 157px">
{% if trip.max_people > 0 %} {% if trip.max_people > 0 %}
{% set amount_cur_rower = trip.rower | length %} {% set amount_cur_rower = trip.rower | length %}
{{ macros::box(participants=trip.rower, empty_seats=trip.max_people - amount_cur_rower, bg='primary-100', color='black') }} {{ macros::box(participants=trip.rower, empty_seats=trip.max_people - amount_cur_rower, bg='primary-100', color='black') }}
{# --- START Edit Form --- #}
{% if trip.cox_id == loggedin_user.id %} {% if trip.cox_id == loggedin_user.id %}
<div class="bg-gray-100 p-3 mt-4 rounded-md"> <div class="bg-gray-100 p-3 mt-4 rounded-md">
<h3 class="text-primary-950 font-bold uppercase tracking-wide mb-2">Ausfahrt bearbeiten</h3> <h3 class="text-primary-950 font-bold uppercase tracking-wide mb-2">Ausfahrt bearbeiten</h3>
@ -206,19 +196,22 @@
</div> </div>
{% endif %} {% endif %}
{% endif %} {% endif %}
{# --- END Edit Form --- #}
{% endif %} {% endif %}
</div> </div>
</div> </div>
<div class="sidebar-overlay" data-trigger="detailTrip{{ trip.trip_details_id }}"></div> {# --- END Sidebar Content --- #}
{% endfor %} {% endfor %}
</div> </div>
{% endif %} {% endif %}
{# --- END Trips --- #}
</div> </div>
{# --- START Add Buttons --- #}
{% if loggedin_user.is_admin or loggedin_user.is_cox %} {% if loggedin_user.is_admin or loggedin_user.is_cox %}
<div class="-mb-3 -mx-3 grid {% if loggedin_user.is_admin %} grid-cols-2 {% endif %} text-center"> <div class="-mb-3 -mx-3 grid {% if loggedin_user.is_admin %} grid-cols-2 {% endif %} text-center">
{% if loggedin_user.is_admin %} {% if loggedin_user.is_admin %}
<a href="#" data-sidebar="true" data-trigger="addTrip" <a href="#" data-sidebar="true" data-trigger="sidebar"
data-header="<strong>Event</strong> am {{ day.day| date(format='%d.%m.%Y') }} erstellen" data-header="<strong>Event</strong> am {{ day.day| date(format='%d.%m.%Y') }} erstellen"
data-day="{{ day.day }}" data-day="{{ day.day }}"
data-form="#addEventForm" data-form="#addEventForm"
@ -231,10 +224,10 @@
{% endif %} {% endif %}
{% if loggedin_user.is_cox%} {% if loggedin_user.is_cox%}
<a href="#" data-sidebar="true" data-trigger="addTrip" <a href="#" data-sidebar="true" data-trigger="sidebar"
data-header="<strong>Ausfahrt</strong> am {{ day.day| date(format='%d.%m.%Y') }} erstellen" data-header="<strong>Ausfahrt</strong> am {{ day.day| date(format='%d.%m.%Y') }} erstellen"
data-day="{{ day.day }}" data-day="{{ day.day }}"
data-form="#addTripForm" data-form="#sidebarForm"
class="relative inline-block w-full py-2 text-primary-900 hover:text-primary-950 focus:text-primary-950 text-sm font-semibold bg-gray-100 hover:bg-gray-200 focus:bg-gray-200 {% if loggedin_user.is_admin %} rounded-br-md {% else %} rounded-b-md {% endif %}"> class="relative inline-block w-full py-2 text-primary-900 hover:text-primary-950 focus:text-primary-950 text-sm font-semibold bg-gray-100 hover:bg-gray-200 focus:bg-gray-200 {% if loggedin_user.is_admin %} rounded-br-md {% else %} rounded-b-md {% endif %}">
<span class="absolute inset-y-0 left-0 flex items-center pl-3"> <span class="absolute inset-y-0 left-0 flex items-center pl-3">
{% include "includes/plus-icon" %} {% include "includes/plus-icon" %}
@ -244,13 +237,14 @@
{% endif %} {% endif %}
</div> </div>
{% endif %} {% endif %}
{# --- END Add Buttons --- #}
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
{# --- START Add Trip Sidebar --- #} {# --- START Add Trip Sidebar --- #}
<div class="sidebar slide-in from-right" id="addTrip" aria-modal="false"> <div class="sidebar slide-in from-right" id="sidebar" aria-modal="false">
<div class="bg-primary-900 text-white px-2 py-3 flex justify-between sidebar-header"> <div class="bg-primary-900 text-white px-2 py-3 flex justify-between sidebar-header">
<div> <div>
<span class="ps-1 header-js"> <span class="ps-1 header-js">
@ -258,20 +252,20 @@
</span> </span>
</div> </div>
<button type="button" title="Ausfahrt erstellen schließen" class="sidebar-close border-0 bg-primary-600 text-black" <button type="button" title="Ausfahrt erstellen schließen" class="sidebar-close border-0 bg-primary-600 text-black"
data-trigger="addTrip"> data-trigger="sidebar">
x x
</button> </button>
</div> </div>
<div class="form-js px-2 pt-2" style="margin-top: 63px; margin-bottom: 157px"> <div class="body-js px-2 pt-2" style="margin-top: 63px; margin-bottom: 157px">
Formular wird ersetzt Formular wird ersetzt
</div> </div>
</div> </div>
<div class="sidebar-overlay" data-trigger="addTrip"></div> <div class="sidebar-overlay" data-trigger="sidebar"></div>
{# --- END Add Trip Sidebar --- #} {# --- END Add Trip Sidebar --- #}
{# --- START Form Add Trip --- #} {# --- START Form Add Trip --- #}
<div class="hidden"> <div class="hidden">
<form action="/cox/trip" method="post" class="grid gap-3" id="addTripForm"> <form action="/cox/trip" method="post" class="grid gap-3" id="sidebarForm">
<input class="day-js" type="hidden" name="day" value="" /> <input class="day-js" type="hidden" name="day" value="" />
{{ macros::input(label='Startzeit', name='planned_starting_time', type='input', required=true) }} {{ 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='Anzahl Ruderer', name='max_people', type='number', required=true) }}