|
|
@@ -161,44 +161,49 @@ export class ModalEvent implements OnInit, OnDestroy {
|
|
|
public modoEdicion = !!this.data?.evento;
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
- this.editor = new Editor();
|
|
|
-
|
|
|
- if (this.data?.evento) {
|
|
|
- const evento = this.data.evento;
|
|
|
-
|
|
|
- this.form.patchValue({
|
|
|
- titulo: evento.titulo,
|
|
|
- fechaInicio: evento.fechaInicio ? evento.fechaInicio.split(' ')[0] : '',
|
|
|
- fechaFin: evento.fechaFin ? evento.fechaFin.split(' ')[0] : '',
|
|
|
- horaInicio: evento.fechaInicio ? evento.fechaInicio.split(' ')[1] : '',
|
|
|
- horaFinal: evento.fechaFin ? evento.fechaFin.split(' ')[1] : '',
|
|
|
- todoDia: evento.diaCompleto === 'Sí' || evento.diaCompleto === 'Si' || evento.diaCompleto === 'Yes',
|
|
|
- categoria: evento.colorEvento,
|
|
|
- contenido: evento.descripcion
|
|
|
- });
|
|
|
+ this.editor = new Editor();
|
|
|
+
|
|
|
+ if (this.data?.evento) {
|
|
|
+ const evento = this.data.evento;
|
|
|
+
|
|
|
+ this.form.patchValue({
|
|
|
+ titulo: evento.titulo,
|
|
|
+ fechaInicio: evento.fechaInicio ? evento.fechaInicio.split(' ')[0] : '',
|
|
|
+ fechaFin: evento.fechaFin ? evento.fechaFin.split(' ')[0] : '',
|
|
|
+ horaInicio: evento.fechaInicio ? evento.fechaInicio.split(' ')[1] : '',
|
|
|
+ horaFinal: evento.fechaFin ? evento.fechaFin.split(' ')[1] : '',
|
|
|
+ todoDia: evento.diaCompleto === 'Sí' || evento.diaCompleto === 'Si' || evento.diaCompleto === 'Yes',
|
|
|
+ categoria: evento.colorEvento,
|
|
|
+ contenido: evento.descripcion
|
|
|
+ });
|
|
|
|
|
|
- console.log(evento.fechaInicio.split(' ')[1]);
|
|
|
+ // 🔒 Deshabilitar los campos de audiencia y destino al editar
|
|
|
+ this.form.get('audiencia')?.disable();
|
|
|
+ this.form.get('destinos')?.disable();
|
|
|
|
|
|
- // Si era todo el día, deshabilita campos
|
|
|
- if (evento.diaCompleto === 'Si') {
|
|
|
- this.form.get('fechaInicio')?.disable();
|
|
|
- this.form.get('fechaFin')?.disable();
|
|
|
- this.form.get('horaInicio')?.disable();
|
|
|
- this.form.get('horaFinal')?.disable();
|
|
|
- }
|
|
|
+ // Si era todo el día, deshabilita campos de fecha/hora
|
|
|
+ if (evento.diaCompleto === 'Si') {
|
|
|
+ this.form.get('fechaInicio')?.disable();
|
|
|
+ this.form.get('fechaFin')?.disable();
|
|
|
+ this.form.get('horaInicio')?.disable();
|
|
|
+ this.form.get('horaFinal')?.disable();
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- // Escuchar cambios en el campo de audiencia
|
|
|
- this.form.get('audiencia')?.valueChanges.subscribe((value) => {
|
|
|
+ // Escuchar cambios en el campo de audiencia (solo si no está deshabilitado)
|
|
|
+ this.form.get('audiencia')?.valueChanges.subscribe((value) => {
|
|
|
+ if (!this.form.get('audiencia')?.disabled) {
|
|
|
if (value === 'TD') {
|
|
|
this.form.get('destinos')?.disable();
|
|
|
- this.form.get('destinos')?.setValue('todos'); // valor por defecto
|
|
|
+ this.form.get('destinos')?.setValue('todos');
|
|
|
} else {
|
|
|
this.form.get('destinos')?.enable();
|
|
|
- this.form.get('destinos')?.setValue('');
|
|
|
+ this.form.get('destinos')?.setValue('');
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
this.editor.destroy();
|
|
|
@@ -425,31 +430,41 @@ export class ModalEvent implements OnInit, OnDestroy {
|
|
|
}
|
|
|
|
|
|
actualizarEvento() {
|
|
|
- const formattedFechaInicio = moment(this.form.value.fechaInicio).format("YYYY-MM-DD");
|
|
|
- const formattedFechaFinal = moment(this.form.value.fechaFin).format("YYYY-MM-DD");
|
|
|
+ const formattedFechaInicio = moment(this.form.value.fechaInicio).format("YYYY-MM-DD");
|
|
|
+ const formattedFechaFinal = moment(this.form.value.fechaFin).format("YYYY-MM-DD");
|
|
|
|
|
|
- const dataActualizada = {
|
|
|
- idEvento: this.data.evento.idEvento,
|
|
|
- ...this.form.value,
|
|
|
- fechaInicio: `${formattedFechaInicio} ${this.form.value.horaInicio}`,
|
|
|
- fechaFin: `${formattedFechaFinal} ${this.form.value.horaFinal}`,
|
|
|
- };
|
|
|
-
|
|
|
- Swal.fire({ title: 'Actualizando...', didOpen: () => Swal.showLoading() });
|
|
|
+ let horaInicio = this.form.value.horaInicio;
|
|
|
+ let horaFinal = this.form.value.horaFinal;
|
|
|
|
|
|
- this.eventoService.actualizarEvento(dataActualizada).subscribe(
|
|
|
- () => {
|
|
|
- Swal.close();
|
|
|
- Swal.fire('Actualizado', 'El evento se actualizó correctamente.', 'success');
|
|
|
- this.dialogRef.close('refresh');
|
|
|
- },
|
|
|
- (error) => {
|
|
|
- console.error(error);
|
|
|
- Swal.fire('Error', 'No se pudo actualizar el evento.', 'error');
|
|
|
- }
|
|
|
- );
|
|
|
+ // Si es "todo el día", forzar las horas a rango completo
|
|
|
+ if (this.form.value.todoDia) {
|
|
|
+ horaInicio = '00:00:00';
|
|
|
+ horaFinal = '23:30:00';
|
|
|
}
|
|
|
|
|
|
+ const dataActualizada = {
|
|
|
+ idEvento: this.data.evento.idEvento,
|
|
|
+ ...this.form.value,
|
|
|
+ fechaInicio: `${formattedFechaInicio} ${horaInicio}`,
|
|
|
+ fechaFin: `${formattedFechaFinal} ${horaFinal}`,
|
|
|
+ };
|
|
|
+
|
|
|
+ Swal.fire({ title: 'Actualizando...', didOpen: () => Swal.showLoading() });
|
|
|
+
|
|
|
+ this.eventoService.actualizarEvento(dataActualizada).subscribe(
|
|
|
+ () => {
|
|
|
+ Swal.close();
|
|
|
+ Swal.fire('Actualizado', 'El evento se actualizó correctamente.', 'success');
|
|
|
+ this.dialogRef.close('refresh');
|
|
|
+ },
|
|
|
+ (error) => {
|
|
|
+ console.error(error);
|
|
|
+ Swal.fire('Error', 'No se pudo actualizar el evento.', 'error');
|
|
|
+ }
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
guardarEvento(formattedData: any) {
|
|
|
this.eventoService.crearEvento(formattedData).subscribe(
|
|
|
(response: any) => {
|