implement lineup send to gamechanger

This commit is contained in:
2022-06-08 14:08:33 -05:00
parent 50c9b70546
commit f788fb9932
21 changed files with 409 additions and 82 deletions

View File

@@ -25,7 +25,6 @@
<tbody>
<tr class="align-top mx-1">
{% for event_data in contexts %}
<td class="px-1">
{% include "lineup/widgets/lineup.html" with event=event_data.event event_id=event_data.event.data.id formset=event_data.formset formset_startinglineup=event_data.formset_startinglineup formset_bench=event_data.formset_bench formset_out=event_data.formset_out formset_startingpositionalonly=event_data.formset_startingpositionalonly %}
</td>
@@ -41,25 +40,24 @@
{% block inline_javascript %}
{{ block.super }}
<script src="{% static 'js/Sortable.js' %}"></script>
<script src="{% static 'js/lineup-table.js' %}"></script>
<script>
window.addEventListener('DOMContentLoaded', () => {
/* Run whatever you want */
const postForms = document.querySelectorAll("[id^=form-lineup]");
for (postForm of postForms) {
function handleSubmit(postForm) {
postForm.addEventListener("submit", e => {
const postSubmits = document.querySelectorAll("[id^=submit-lineup]");
for (postSubmit of postSubmits) {
function handleSubmit(postSubmit) {
postSubmit.addEventListener("click", e => {
e.preventDefault();
formData = new FormData(postForm);
fetch(postForm.action, {
formData = new FormData(postSubmit.form);
fetch(postSubmit.formAction, {
method: 'POST',
body: formData,
})
.then(response => response.json())
.then(response => response)
.then(data => {
{#postForm.reset();#}
document.querySelector("#popup-messages-content").innerHTML = `<div class="alert alert-dismissible alert-success" role="alert">
<strong>Success!</strong> ${data.formatted_title} <strong>saved</strong>.
<strong>Success!</strong>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div> `
})
@@ -69,7 +67,7 @@
})
}
handleSubmit(postForm)
handleSubmit(postSubmit)
}
});
</script>