{% block body %}
{{ form_start(form,{ 'attr': { 'id': 'agenda_new_form' } }) }}
<div class="row">
<div class="col-md-3 pc">
{{ form_row(form.inicio) }}
</div>
<div class="col-md-3 pc">
{{ form_row(form.fin) }}
</div>
<div class="col-md-3 pc">
{{ form_row(form.doctor) }}
</div>
<div class="col-md-3 pc">
{{ form_row(form.seguro) }}
</div>
<div class="col-md-3 pc">
{{ form_row(form.especialidad) }}
</div>
<div class="col-md-9 pc">
{{ form_row(form.procedimiento) }}
</div>
<div class="col-md-12 pc">
{{ form_row(form.validacion) }}
</div>
<div class="col-md-9 pc">
{{ form_row(form.observacion) }}
</div>
<div class="col-md-3 pc">
<br>
<button type="button" class="btn btn-success" onclick="guardar_agenda_form()">{{ button_label|default('Guardar') }}</button>
</div>
</div>
{{ form_end(form) }}
{% endblock %}
{% block javascripts %}
<script type="text/javascript">
$(document).ready(function() {
// you may need to change this code if you are not using Bootstrap Datepicker
//$('#agenda_inicio').val("2013-03-18T13:00");
$('.select2').select2({
dropdownParent: $('#id_modal_agendar')
});
$('#agenda_inicio').val($('#inicio').val());
$('#agenda_fin').val($('#fin').val());
{% if paciente.seguro %}
//$('#agenda_seguro option[value={{paciente.seguro.id}}]').attr('selected','selected');
{% endif %}
{% if sala.unidad %}
/* $('#agenda_especialidad option[value={{sala.unidad.id}}]').attr('selected','selected');*/
{% endif %}
});
function guardar_agenda_form(){
// ✅ Validación HTML5 (muestra "Completa este campo")
const form = document.getElementById('agenda_new_form');
if (form && !form.checkValidity()) {
form.reportValidity();
return;
}
$.ajax({
url: '{{path("agenda_new_modal_storage")}}',
type: 'POST',
data: $('#agenda_new_form').serialize(),
//dataType: 'json',
async: true,
success: function(data, status) {
if(data.estado == 'ok'){
alert("Agenda Guardada con Exito");
if(data.admision=='ok'){
location.href = '{{ asset('index.php/agenda') }}/'+data.agenda+'/edit';
}else{
if({{app.session.get('tipo_cal')}} > 0){
location.href = '{{ path('agenda_calendar_unidad',{'id':app.session.get('tipo_cal')}) }}';
}else{
location.href = '{{ path('agenda_calendar',{'id_sala':app.session.get('id_sala')}) }}';
}
}
}else{
alert(data.msn);
if({{app.session.get('tipo_cal')}} > 0){
location.href = '{{ path('agenda_calendar_unidad',{'id':app.session.get('tipo_cal')}) }}';
}else{
location.href = '{{ path('agenda_calendar',{'id_sala':app.session.get('id_sala')}) }}';
}
}
},
error : function(xhr, textStatus, errorThrown) {
console.log(xhr);
alert('Ajax request failed.');
}
});
}
$('#agenda_doctor').on('select2:select', function(e) {
let doctorId = $(this).val();
if(!doctorId) return;
$.ajax({
url: '{{ asset('index.php/user/ajax/especialidad-doctor') }}/' + doctorId,
type: 'GET',
success: function(response) {
if(response.success) {
console.log(response);
jqModern('#agenda_especialidad')
.val(response.id)
.trigger('change');
}
}
});
});
</script>
{% endblock %}