re-enable submit button in finally block

This commit is contained in:
2021-09-07 16:02:09 +02:00
parent d21a5986a8
commit 356c8c0bbd
6 changed files with 98 additions and 64 deletions

View File

@ -63,16 +63,22 @@ export class FlatDetailsComponent implements OnInit {
}
async saveFlat() {
this.submitButton.disabled = true
this.messageService.add(`saveFlat: ${ JSON.stringify(this.flat, undefined, 4) }`)
if (this.flat.id == 0) {
this.messageService.add("about to insert new flat")
this.flat = await this.flatService.postFlat(this.flat)
this.messageService.add(`Successfully added flat with id ${this.flat.id}`)
} else {
this.messageService.add("about to update existing flat")
try {
this.submitButton.disabled = true
this.messageService.add(`saveFlat: ${ JSON.stringify(this.flat, undefined, 4) }`)
if (this.flat.id == 0) {
this.messageService.add("about to insert new flat")
this.flat = await this.flatService.postFlat(this.flat)
this.messageService.add(`Successfully added flat with id ${this.flat.id}`)
} else {
this.messageService.add("about to update existing flat")
this.flat = await this.flatService.putFlat(this.flat)
this.messageService.add(`Successfully changed flat with id ${this.flat.id}`)
}
this.router.navigate(['/flats'])
} finally {
this.submitButton.disabled = false
}
this.router.navigate(['/flats'])
}
ngOnInit(): void {