diff --git a/app/controllers/external_trainings_controller.rb b/app/controllers/external_trainings_controller.rb index ca8f1e45e..b16d29a28 100644 --- a/app/controllers/external_trainings_controller.rb +++ b/app/controllers/external_trainings_controller.rb @@ -21,6 +21,7 @@ class ExternalTrainingsController < CrudController # load parents before authorization prepend_before_action :parent + before_render_form :load_event_kinds def create super(location: history_group_person_path(@group, @person)) @@ -36,4 +37,7 @@ def build_entry @person.external_trainings.build end + def load_event_kinds + @event_kinds ||= Event::Kind.list + end end diff --git a/app/views/external_trainings/_event_kind_field_with_info.html.haml b/app/views/external_trainings/_event_kind_field_with_info.html.haml new file mode 100644 index 000000000..4720b18ec --- /dev/null +++ b/app/views/external_trainings/_event_kind_field_with_info.html.haml @@ -0,0 +1,11 @@ +- id = :event_kind_turbo_frame +- form_action = new_group_person_external_training_path(@group, @person) +- prolonging_qualis = entry.kind&.qualification_kinds(%w(qualification prolongation), 'participant') + += turbo_frame_tag(id) do + = f.labeled_input_fields :event_kind_id, data: { action: 'forwarder#click' } + - if entry.kind && entry.qualification_date && prolonging_qualis.present? + %p.col-md-9.offset-md-3.offset-xl-2.mb-2 + = entry.kind.decorate.issued_qualifications_info_for_participants(entry.qualification_date) + += render 'shared/hidden_submit', label: 'Load qualification info', formaction: form_action, turbo_frame: id diff --git a/app/views/external_trainings/_form.html.haml b/app/views/external_trainings/_form.html.haml index 301bb865d..9b86dd807 100644 --- a/app/views/external_trainings/_form.html.haml +++ b/app/views/external_trainings/_form.html.haml @@ -1,2 +1,6 @@ -= entry_form(cancel_url: history_group_person_path(@group, @person)) do |f| - = f.labeled_input_fields :event_kind_id, :name, :provider, :start_at, :finish_at, :training_days, :link, :remarks += entry_form(cancel_url: history_group_person_path(@group, @person), data: { controller: :forwarder }) do |f| + = f.labeled_input_fields :name, :provider + = f.labeled_input_field :start_at + = f.labeled_input_field :finish_at + = render 'event_kind_field_with_info', f: f + = f.labeled_input_fields :training_days, :link, :remarks diff --git a/app/views/external_trainings/_qualification_infos.html.haml b/app/views/external_trainings/_qualification_infos.html.haml new file mode 100644 index 000000000..e69de29bb diff --git a/spec/features/external_training_model_spec.rb b/spec/features/external_training_model_spec.rb index f253600ca..13d6b5c5e 100644 --- a/spec/features/external_training_model_spec.rb +++ b/spec/features/external_training_model_spec.rb @@ -26,10 +26,26 @@ fill_in 'Link', with: 'https://wasser.example.com' fill_in 'Bemerkung', with: 'Bla' all('button', text: 'Speichern').first.click + expect(page).to have_css('.alert-success', text: "Schwimmkurs wurde erfolgreich erstellt.") within('#external_trainings') { click_on 'Löschen' } accept_alert - expect(page).to have_css('.alert-success', text: "Externe Ausbildung Schwimmkurs wurde erfolgreich gelöscht.") + expect(page).to have_css('.alert-success', +text: "Externe Ausbildung Schwimmkurs wurde erfolgreich gelöscht.") + end + + it "reloads qualification infos", js: true do + sign_in(admin) + visit history_group_person_path(group_id: mitglieder, id: mitglied) + click_on 'Erstellen' + fill_in 'Name', with: 'Skikurs' + fill_in 'Startdatum', with: '01.03.2024' + fill_in 'Enddatum', with: '06.03.2024' + select 'Dummy', from: 'external_training_event_kind_id' + expect(page).to have_css 'turbo-frame p', text: 'Verlängert existierende Qualifikation ' \ + 'Ski Leiter unmittelbar per 06.03.2024 (letztes Kursdatum).' + select '(keine)', from: 'external_training_event_kind_id' + expect(page).not_to have_css 'turbo-frame p' end end