From 2d75e7696df5ede3705bd973b152b156b6832d2f Mon Sep 17 00:00:00 2001 From: Marie Birner Date: Fri, 7 Apr 2023 11:35:39 +0200 Subject: [PATCH 1/3] [TASK] refactor sidebar forms (reduced size dramatically) --- frontend/js/sidebar.ts | 2 +- frontend/main.ts | 28 +++++++++- templates/index.html.tera | 112 ++++++++++++++++++-------------------- 3 files changed, 80 insertions(+), 62 deletions(-) diff --git a/frontend/js/sidebar.ts b/frontend/js/sidebar.ts index 6dad1b0..c2cb7f6 100644 --- a/frontend/js/sidebar.ts +++ b/frontend/js/sidebar.ts @@ -17,7 +17,7 @@ export class Sidebar { this.isOpen = false; } - checkStatus() { + checkStatus(): Boolean { return this.isOpen; } diff --git a/frontend/main.ts b/frontend/main.ts index e09f22a..58268db 100644 --- a/frontend/main.ts +++ b/frontend/main.ts @@ -51,10 +51,36 @@ 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 = document.querySelector('#addTrip'); + if(sidebarElement && triggerElement.dataset.form && triggerElement.dataset.header) { + let formElement = document.querySelector(triggerElement.dataset.form); + let formContainerElement = sidebarElement.querySelector('.form-js'); + if(formContainerElement) { + formContainerElement.innerHTML = ''; + formContainerElement.append(formElement); + } + if(triggerElement.dataset.day) { + let hiddenElement = formElement.querySelector('.day-js'); + if(hiddenElement) { + hiddenElement.value = triggerElement.dataset.day; + } + } + + let headerElement = sidebarElement.querySelector('.header-js'); + if(headerElement) { + headerElement.innerHTML = triggerElement.dataset.header; + } + } +} diff --git a/templates/index.html.tera b/templates/index.html.tera index a3211e7..befde40 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -188,75 +188,67 @@
{% if loggedin_user.is_admin %} - Event hinzufügen - - - - - {% endif %} {% if loggedin_user.is_cox%} - Ausfahrt hinzufügen - - - {% endif %}
{% endfor %} + +{# --- START Add Trip Sidebar --- #} + + +{# --- END Add Trip Sidebar --- #} + +{# --- START Form Add Trip --- #} +
+ + {{ 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') }} + +
+{# --- END Form Add Trip --- #} + +{# --- START Form Add Event --- #} +
+ + {{ 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') }} + +
+{# --- END Form Add Event --- #} + {% endblock content %} \ No newline at end of file From 3b04cdc5cab0acfbb1729783a24ec909b92994ed Mon Sep 17 00:00:00 2001 From: Marie Birner Date: Fri, 7 Apr 2023 11:39:23 +0200 Subject: [PATCH 2/3] [BUGFIX] hide forms if not used --- templates/index.html.tera | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/templates/index.html.tera b/templates/index.html.tera index de6092f..fa224c8 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -235,26 +235,30 @@ {# --- END Add Trip Sidebar --- #} {# --- START Form Add Trip --- #} -
- - {{ 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') }} - -
+ {# --- END Form Add Trip --- #} {# --- START Form Add Event --- #} -
- - {{ 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') }} - -
+ {# --- END Form Add Event --- #} {% endblock content %} From 0c25f37a2f1c5fed78d46da2f7be79a2bdf073ec Mon Sep 17 00:00:00 2001 From: Marie Birner Date: Fri, 7 Apr 2023 11:45:12 +0200 Subject: [PATCH 3/3] [BUGFIX] clone node form element --- frontend/main.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/main.ts b/frontend/main.ts index 58268db..890decb 100644 --- a/frontend/main.ts +++ b/frontend/main.ts @@ -65,7 +65,8 @@ function initSidebar() { function initTripSidebar(triggerElement: HTMLElement) { const sidebarElement = document.querySelector('#addTrip'); if(sidebarElement && triggerElement.dataset.form && triggerElement.dataset.header) { - let formElement = document.querySelector(triggerElement.dataset.form); + let form = document.querySelector(triggerElement.dataset.form); + let formElement = form.cloneNode(true); let formContainerElement = sidebarElement.querySelector('.form-js'); if(formContainerElement) { formContainerElement.innerHTML = '';