Adding a confirmation before deletion
This commit is contained in:
@@ -2,11 +2,26 @@
|
|||||||
<form cForm [formGroup]="form" (ngSubmit)="onSubmit(model)">
|
<form cForm [formGroup]="form" (ngSubmit)="onSubmit(model)">
|
||||||
<span class="col col-form-label" *ngIf="formLoading$ || modelLoading$ | async">Loading...</span>
|
<span class="col col-form-label" *ngIf="formLoading$ || modelLoading$ | async">Loading...</span>
|
||||||
<formly-form [form]="form" [fields]="fields" [model]="model"></formly-form>
|
<formly-form [form]="form" [fields]="fields" [model]="model"></formly-form>
|
||||||
<button class="btn btn-success btn-lg" type="submit" [disabled]="!form.valid">
|
<div class="d-grid gap-2 d-md-flex">
|
||||||
|
<button class="btn btn-success btn-lg" type="submit"
|
||||||
|
[disabled]="!form.valid && (formLoading$ || modelLoading$ | async)">
|
||||||
{{ this.isCreateForm() ? "Create" : "Update" }}
|
{{ this.isCreateForm() ? "Create" : "Update" }}
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-danger btn-lg float-end" type="button" *ngIf="!this.isCreateForm()" (click)="onDelete()">
|
<button class="btn btn-danger btn-lg" type="button" *ngIf="!this.isCreateForm()"
|
||||||
|
[disabled]="formLoading$ || modelLoading$ | async"
|
||||||
|
(click)="open(confirmDeleteModal)">
|
||||||
Delete
|
Delete
|
||||||
</button>
|
</button>
|
||||||
|
<ng-template #confirmDeleteModal let-modal>
|
||||||
|
<div class="modal-header">
|
||||||
|
<h4 class="modal-title" id="modal-basic-title">Are you sure you want to delete this {{ this.schema }}?</h4>
|
||||||
|
<button type="button" class="btn-close" aria-label="Cancel" (click)="modal.dismiss('Cancel Deletion')"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-light" aria-label="Cancel" (click)="modal.dismiss('Cancel Deletion')">Cancel</button>
|
||||||
|
<button type="button" class="btn btn-danger" (click)="modal.close('Save click')">Delete</button>
|
||||||
|
</div>
|
||||||
|
</ng-template>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router';
|
|||||||
import { CrudService } from '../crud.service'
|
import { CrudService } from '../crud.service'
|
||||||
import {BehaviorSubject, NotFoundError} from "rxjs";
|
import {BehaviorSubject, NotFoundError} from "rxjs";
|
||||||
import { CrudFormlyJsonschemaService } from "../crud-formly-jsonschema.service";
|
import { CrudFormlyJsonschemaService } from "../crud-formly-jsonschema.service";
|
||||||
|
import {NgbModal} from "@ng-bootstrap/ng-bootstrap";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'crud-card',
|
selector: 'crud-card',
|
||||||
@@ -44,6 +45,7 @@ export class CardComponent implements OnInit {
|
|||||||
private formlyJsonschema: CrudFormlyJsonschemaService,
|
private formlyJsonschema: CrudFormlyJsonschemaService,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
|
private modalService: NgbModal,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
@@ -99,7 +101,18 @@ export class CardComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDuplicate() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
isCreateForm() {
|
isCreateForm() {
|
||||||
return this.resource_id === null;
|
return this.resource_id === null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open(content: any) {
|
||||||
|
this.modalService.open(content, { ariaLabelledBy: 'modal-basic-title' }).result.then(
|
||||||
|
(result) => { this.onDelete() },
|
||||||
|
(reason) => {},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user