Files
AS_timbres/Templates/Sistemas/Xclientes/sistema_create.html
2023-02-16 10:38:28 -06:00

110 lines
3.9 KiB
HTML

<!-- sistema_create.html -->
{% extends 'base.html' %}
{% block content %}
<h1>Create a new sistemas por cliente</h1>
<form method="post">
{% csrf_token %}
<div class="">
<div class="form-group">
<div class="form">
{{ form.id_sistema.label }}
{{ form.id_sistema }}
<button id="add-sistema-btn" type="button" class="btn btn-info">Add Sistema</button>
</div>
</div>
<div class="form-group">
{{ form.cliente.label}}
{{ form.cliente }}
<button id="add-cliente-btn" type="button" class="btn btn-info">Add Cliente</button>
</div>
<div class="form-group">
{{ form.num_licencias.label }}
{{ form.num_licencias }}
</div>
<button class="btn btn-success" type="submit">Create</button>
</div>
</form>
{% endblock %}
{% block scripts %}
<script>
document.addEventListener('DOMContentLoaded', function() {
/*add Sistema*/
document.querySelector('#add-sistema-btn').addEventListener('click', function() {
let parentWidth = window.innerWidth;
let parentHeight = window.innerHeight;
let childWidth = 800;
let childHeight = 600;
let left =(parentWidth - childWidth);
let top = (parentHeight - childHeight);
//let popupWin = window.open("{% url 'create_sistemas_form' %}", "popupWin", "width=800,height=600");
let popupWin = window.open("{% url 'create_sistemas_form' %}", "popupWin", "width=" + childWidth + ",height=" + childHeight + ",left=" + left + ",top=" + top);
popupWin.focus();
});
/*Add cliente*/
document.querySelector("#add-cliente-btn").addEventListener('click',()=>{
let parentWidth = window.innerWidth;
let parentHeight = window.innerHeight;
let childWidth = 800;
let childHeight = 600;
let left =(parentWidth - childWidth);
let top = (parentHeight - childHeight);
let popupWin = window.open("{% url 'add_cliente' %}", "popupWin", "width=" + childWidth + ",height=" + childHeight + ",left=" + left + ",top=" + top);
popupWin.focus();
});
window.addEventListener('message', function(event) {
let response = event.data.data;
let windowName = event.data.windowName;
if(windowName==='clientWindow'){
let id_cliente = response.id;
let Nombre = response.Nombre;
let option= `<option value="${id_cliente}" selected> ${Nombre}</option>`;
document.querySelector("#id_cliente").insertAdjacentHTML('beforeend',option);
}
else if (windowName==='sistemaWindow'){
let id_sistema = response.id;
let nombre_sistema = response.nombre_sistema;
let version = response.version;
let option = '<option value="' + id_sistema + '" selected>' + nombre_sistema + ', version ' + version + '</option>';
document.querySelector('#id_id_sistema').insertAdjacentHTML('beforeend', option);
}
});
});
/*
$(function() {
$('#add-sistema-btn').click(function() {
let popupWin = window.open("{% url 'create_sistemas_form' %}", "popupWin", "width=800,height=600");
popupWin.focus();
});
window.addEventListener('message', function(event) {
let response = event.data;
let id_sistema = response.id;
let nombre_sistema = response.nombre_sistema;
let version = response.version;
let option = '<option value="' + id_sistema + '" selected>' + nombre_sistema + ', version ' + version + '</option>';
$('#id_id_sistema').append(option);
$('#sistema-modal').modal('hide');
});
});
*/
</script>
{% endblock scripts %}