Add delete question confirmation dialog
This commit is contained in:
parent
4ccf240bd1
commit
0932e0c7b6
|
@ -0,0 +1,25 @@
|
|||
<form name="deleteForm" (ngSubmit)="confirmDelete()">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title" data-cy="encuestaDeleteDialogHeading" jhiTranslate="entity.delete.title">Confirm delete operation</h4>
|
||||
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true" (click)="cancel()">×</button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<jhi-alert-error></jhi-alert-error>
|
||||
|
||||
<p id="jhi-delete-encuesta-heading" jhiTranslate="dataSurveyApp.encuesta.delete.deletequestion">
|
||||
Are you sure you want to delete this question?
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal" (click)="cancel()">
|
||||
<fa-icon icon="ban"></fa-icon> <span jhiTranslate="entity.action.cancel">Cancel</span>
|
||||
</button>
|
||||
|
||||
<button id="jhi-confirm-delete-encuesta" data-cy="entityConfirmDeleteButton" type="submit" class="btn btn-danger">
|
||||
<fa-icon icon="times"></fa-icon> <span jhiTranslate="entity.action.delete">Delete</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
|
@ -0,0 +1,17 @@
|
|||
import { Component } from '@angular/core';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
@Component({
|
||||
templateUrl: './encuesta-delete-question-dialog.component.html',
|
||||
})
|
||||
export class EncuestaDeleteQuestionDialogComponent {
|
||||
constructor(protected activeModal: NgbActiveModal) {}
|
||||
|
||||
cancel(): void {
|
||||
this.activeModal.dismiss();
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
this.activeModal.close('confirm');
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import { EncuestaDeleteDialogComponent } from './delete/encuesta-delete-dialog.c
|
|||
import { EncuestaRoutingModule } from './route/encuesta-routing.module';
|
||||
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
|
||||
import { EncuestaPublishDialogComponent } from './encuesta-publish-dialog/encuesta-publish-dialog.component';
|
||||
import { EncuestaDeleteQuestionDialogComponent } from './encuesta-delete-dialog/encuesta-delete-question-dialog.component';
|
||||
|
||||
@NgModule({
|
||||
imports: [SharedModule, EncuestaRoutingModule, FontAwesomeModule],
|
||||
|
@ -16,6 +17,7 @@ import { EncuestaPublishDialogComponent } from './encuesta-publish-dialog/encues
|
|||
EncuestaUpdateComponent,
|
||||
EncuestaDeleteDialogComponent,
|
||||
EncuestaPublishDialogComponent,
|
||||
EncuestaDeleteQuestionDialogComponent,
|
||||
],
|
||||
entryComponents: [EncuestaDeleteDialogComponent],
|
||||
})
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { EncuestaDeleteQuestionDialogComponent } from './../encuesta-delete-dialog/encuesta-delete-question-dialog.component';
|
||||
import { EPreguntaCerrada } from './../../e-pregunta-cerrada/e-pregunta-cerrada.model';
|
||||
import { EPreguntaCerradaOpcion, IEPreguntaCerradaOpcion } from './../../e-pregunta-cerrada-opcion/e-pregunta-cerrada-opcion.model';
|
||||
import { EPreguntaAbiertaService } from './../../e-pregunta-abierta/service/e-pregunta-abierta.service';
|
||||
|
@ -26,7 +27,6 @@ import { EPreguntaCerradaDeleteDialogComponent } from 'app/entities/e-pregunta-c
|
|||
|
||||
import { faTimes, faPlus } from '@fortawesome/free-solid-svg-icons';
|
||||
import { PreguntaCerradaTipo } from 'app/entities/enumerations/pregunta-cerrada-tipo.model';
|
||||
|
||||
@Component({
|
||||
selector: 'jhi-encuesta-update',
|
||||
templateUrl: './encuesta-update.component.html',
|
||||
|
@ -99,6 +99,7 @@ export class EncuestaUpdateComponent implements OnInit, AfterViewChecked {
|
|||
(res: any) => {
|
||||
this.isLoading = false;
|
||||
this.ePreguntas = res.body ?? [];
|
||||
console.log(this.ePreguntas);
|
||||
},
|
||||
() => {
|
||||
this.isLoading = false;
|
||||
|
@ -188,41 +189,46 @@ export class EncuestaUpdateComponent implements OnInit, AfterViewChecked {
|
|||
}
|
||||
|
||||
deleteQuestion(event: any) {
|
||||
const id = event.target.dataset.id;
|
||||
if (event.target.dataset.type) {
|
||||
// Delete closed question
|
||||
const questionElement = (event.target as HTMLElement).parentElement?.parentElement;
|
||||
const optionIdsToDelete: number[] = [];
|
||||
const modalRef = this.modalService.open(EncuestaDeleteQuestionDialogComponent, { size: 'lg', backdrop: 'static' });
|
||||
modalRef.closed.subscribe(reason => {
|
||||
if (reason === 'confirm') {
|
||||
const id = event.target.dataset.id;
|
||||
if (event.target.dataset.type) {
|
||||
// Delete closed question
|
||||
const questionElement = (event.target as HTMLElement).parentElement?.parentElement;
|
||||
const optionIdsToDelete: number[] = [];
|
||||
|
||||
// Get options IDs
|
||||
questionElement?.childNodes.forEach((e, i) => {
|
||||
if (e.nodeName !== 'DIV') return;
|
||||
if (i === 0) return;
|
||||
if ((e as HTMLElement).dataset.id === undefined) return;
|
||||
if (!(e as HTMLElement).classList.contains('can-delete')) return;
|
||||
let optionId = (e as HTMLElement).dataset.id;
|
||||
optionIdsToDelete.push(+optionId!);
|
||||
});
|
||||
// Get options IDs
|
||||
questionElement?.childNodes.forEach((e, i) => {
|
||||
if (e.nodeName !== 'DIV') return;
|
||||
if (i === 0) return;
|
||||
if ((e as HTMLElement).dataset.id === undefined) return;
|
||||
if (!(e as HTMLElement).classList.contains('can-delete')) return;
|
||||
let optionId = (e as HTMLElement).dataset.id;
|
||||
optionIdsToDelete.push(+optionId!);
|
||||
});
|
||||
|
||||
if (optionIdsToDelete.length === 0) {
|
||||
this.ePreguntaCerradaService.delete(id).subscribe(e => {
|
||||
this.loadAll();
|
||||
});
|
||||
} else {
|
||||
// Delete question options
|
||||
this.ePreguntaCerradaOpcionService.deleteMany(optionIdsToDelete).subscribe(e => {
|
||||
// Delete question
|
||||
this.ePreguntaCerradaService.delete(id).subscribe(e => {
|
||||
if (optionIdsToDelete.length === 0) {
|
||||
this.ePreguntaCerradaService.delete(id).subscribe(e => {
|
||||
this.loadAll();
|
||||
});
|
||||
} else {
|
||||
// Delete question options
|
||||
this.ePreguntaCerradaOpcionService.deleteMany(optionIdsToDelete).subscribe(e => {
|
||||
// Delete question
|
||||
this.ePreguntaCerradaService.delete(id).subscribe(e => {
|
||||
this.loadAll();
|
||||
});
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Delete open question
|
||||
this.ePreguntaAbiertaService.delete(id).subscribe(e => {
|
||||
this.loadAll();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Delete open question
|
||||
this.ePreguntaAbiertaService.delete(id).subscribe(e => {
|
||||
this.loadAll();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
deleteOption(event: any): void {
|
||||
|
|
|
@ -12,7 +12,8 @@
|
|||
"updated": "Una encuesta ha sido actualizado con el identificador {{ param }}",
|
||||
"deleted": "Una encuesta ha sido eliminada con el identificador {{ param }}",
|
||||
"delete": {
|
||||
"question": "¿Seguro que quiere eliminar la encuesta {{ id }}?"
|
||||
"question": "¿Seguro que quiere eliminar la encuesta {{ id }}?",
|
||||
"deletequestion": "¿Seguro que quiere eliminar esta pregunta?"
|
||||
},
|
||||
"detail": {
|
||||
"title": "Encuesta"
|
||||
|
|
Loading…
Reference in New Issue