diff --git a/src/Bundle/ChillPersonBundle/Resources/public/page/accompanying_course_index/person_locate.js b/src/Bundle/ChillPersonBundle/Resources/public/page/accompanying_course_index/person_locate.js new file mode 100644 index 000000000..b634bf146 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/public/page/accompanying_course_index/person_locate.js @@ -0,0 +1,49 @@ +const onSubmit = function(e) { + e.preventDefault(); + let + form = e.target, + formData = new FormData(form), + url = form.action, + payload = { + type: 'accompanying_period', + id: Number.parseInt(formData.get('periodId'), 10), + personLocation: { + type: 'person', + id: Number.parseInt(formData.get('personLocation'), 10) + } + } + ; + + console.log('event', e); + console.log('form', form); + console.log('formData', formData); + console.log('url', url); + console.log('payload', payload); + + window.fetch(url, { + method: 'PATCH', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(payload), + }) + .then(r => { + if (r.ok) { + console.log('response ok'); + window.location.reload(); + } else { + console.err("could not patch accompanying course"); + } + }); +} + +window.addEventListener('DOMContentLoaded', function(e) { + let forms = document.querySelectorAll('.quickLocationForm'); + + console.log(forms); + + forms.forEach(function(form){ + console.log('form quickLocation found', form); + form.addEventListener('submit', onSubmit); + }) +}); diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/_warning_address.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/_warning_address.html.twig index f8e2dad92..490a91b59 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/_warning_address.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/_warning_address.html.twig @@ -1,4 +1,20 @@ -{%- set hasPersonLocation = accompanyingCourse.availablePersonLocation|length > 0 -%} +{%- set countPersonLocation = accompanyingCourse.availablePersonLocation|length -%} +{%- set hasPersonLocation = countPersonLocation|length > 0 -%} +{% macro quickLocationForm(accompanyingCourse, person, whichButton) %} +
+{% endmacro %}