From f5ce3c81b0d65af325330d2bfe96cbc116255600 Mon Sep 17 00:00:00 2001 From: Hamza HRAMCHI <hamza.hramchi@xelians.fr> Date: Mon, 27 Feb 2023 11:52:56 +0100 Subject: [PATCH] FIX #23978 TIME 0:15 disable button if saving signature --- src/frontend/app/pad/pad.component.html | 2 +- src/frontend/app/pad/pad.component.ts | 35 +++++++++++++++---------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/frontend/app/pad/pad.component.html b/src/frontend/app/pad/pad.component.html index f6d209eb0f..7625ef5bdb 100755 --- a/src/frontend/app/pad/pad.component.html +++ b/src/frontend/app/pad/pad.component.html @@ -36,7 +36,7 @@ <ion-button color="danger" (click)="closePad()"> <ion-label>{{'lang.cancel' | translate}}</ion-label> </ion-button> - <ion-button color="success" (click)="saveSignature()"> + <ion-button color="success" (click)="saveSignature()" [disabled]="isSaving"> <ion-label>{{'lang.save' | translate}}</ion-label> </ion-button> </ion-footer> diff --git a/src/frontend/app/pad/pad.component.ts b/src/frontend/app/pad/pad.component.ts index 0162ac856a..941731191a 100755 --- a/src/frontend/app/pad/pad.component.ts +++ b/src/frontend/app/pad/pad.component.ts @@ -1,11 +1,11 @@ import { Component, ViewChild, Output, EventEmitter } from '@angular/core'; import { SignaturePad } from 'angular2-signaturepad'; -import { Observable } from 'rxjs'; +import { Observable, of } from 'rxjs'; import { SignaturesContentService } from '../service/signatures.service'; import { HttpClient } from '@angular/common/http'; import { NotificationService } from '../service/notification.service'; import { TranslateService } from '@ngx-translate/core'; -import { finalize } from 'rxjs/operators'; +import { catchError, finalize, tap } from 'rxjs/operators'; import { AuthService } from '../service/auth.service'; import { LocalStorageService } from '../service/local-storage.service'; import { ModalController } from '@ionic/angular'; @@ -28,6 +28,7 @@ export class SignaturePadPageComponent implements AfterViewInit { selectedColor: any; haveSigned: any; disableState = false; + isSaving: boolean = false; pad$: Observable<boolean>; @@ -84,6 +85,7 @@ export class SignaturePadPageComponent implements AfterViewInit { saveSignature() { this.disableState = true; this.haveSigned = true; + this.isSaving = true; const newEncodedSign = this.signaturePad.toDataURL('image/png').replace('data:image/png;base64,', ''); this.localStorage.save('signature', JSON.stringify(newEncodedSign)); @@ -96,21 +98,26 @@ export class SignaturePadPageComponent implements AfterViewInit { this.http.post('../rest/users/' + this.authService.user.id + '/signatures', newSign) .pipe( + tap((data: any) => { + newSign.id = data.signatureId; + this.signaturesService.signaturesList.unshift( + { + id: newSign.id, + encodedSignature: newSign.encodedSignature + } + ); + this.modalController.dismiss('reload'); + this.notificationService.success('lang.signatureRegistered'); + }), finalize(() => { this.disableState = false; + }), + catchError((err: any) => { + this.notificationService.handleErrors(err); + this.isSaving = false; + return of(false); }) - ) - .subscribe((data: any) => { - newSign.id = data.signatureId; - this.signaturesService.signaturesList.unshift( - { - id: newSign.id, - encodedSignature: newSign.encodedSignature - } - ); - this.modalController.dismiss('reload'); - this.notificationService.success('lang.signatureRegistered'); - }); + ).subscribe(); // BUG IMAGE CROPPED // this.localStorage.save('signature', JSON.stringify(this.signaturePad.toDataURL('image/svg+xml'))); -- GitLab