diff --git a/js/puestos.js b/js/puestos.js index acc9a9f..986f7a4 100644 --- a/js/puestos.js +++ b/js/puestos.js @@ -70,6 +70,34 @@ const app = createApp({ alert(`Error: ${error}`); } }, + async descargar() { + store.current.modal_state = 'Generando reporte en Excel...'; + $('div.modal#cargando').modal('show'); + this.loading = true; + try { + const res = await fetch('action/action_puestos_excel.php', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + }); + const blob = await res.blob(); + window.saveAs(blob, `puestos_${new Date().toISOString().slice(0, 10)}.xlsx`); + } + catch (error) { + if (error.response && error.response.status === 413) { + alert('Your request is too large! Please reduce the data size and try again.'); + } + else { + alert('An error occurred: ' + error.message); + } + } + finally { + $('#cargando').modal('hide'); + this.loading = false; + } + }, + async mounted() { this.puestos = await fetch('action/puesto.php').then(res => res.json()); this.carreras = await fetch('action/action_carreras.php').then(res => res.json()); diff --git a/puestos.php b/puestos.php index 18ab0e9..9f67166 100644 --- a/puestos.php +++ b/puestos.php @@ -47,6 +47,10 @@ Agregar puesto +