Dar de alta sistmeas en ajax popup

This commit is contained in:
fjrodriguez
2023-02-16 10:38:28 -06:00
parent 3aaa0cd909
commit 0de2d8a735
9 changed files with 401 additions and 68 deletions

View File

@@ -0,0 +1,60 @@
<!-- sistema_create_form.html -->
{% block content %}
<h1>Create a new Sistema</h1>
<form id="sistema-form" method="post" action="{% url 'create_sistemas_form' %}">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Create</button>
</form>
{% endblock %}
{% block scripts %}
<script>
document.addEventListener('DOMContentLoaded', function() {
document.querySelector('#sistema-form').addEventListener('submit', function(event) {
event.preventDefault();
var form = event.target;
var url = form.getAttribute('action');
var data = new FormData(form);
fetch(url, {
method: 'POST',
body: data
})
.then(response => response.json())
.then(response => {
window.opener.postMessage({data:response, windowName:'sistemaWindow'}, window.location.origin);
window.close();
})
.catch(error => console.log(error));
});
});
/*
<!--script src="https://code.jquery.com/jquery-3.6.0.min.js">
$(function() {
$('#sistema-form').submit(function(event) {
event.preventDefault();
var form = $(this);
var url = form.attr('action');
var data = form.serialize();
$.ajax({
url: url,
data: data,
type: 'post',
dataType: 'json',
success: function(response) {
window.opener.postMessage(response, '*');
window.close();
},
error: function(xhr, status, error) {
console.log(xhr.responseText);
}
});
});
});*/
</script>
{% endblock scripts %}