diff --git a/lang/en.json b/lang/en.json index 3044b5feead6d7e150231e634d77e1da77f93030..827c627b374528b577596aefd5ee84e43087e67c 100755 --- a/lang/en.json +++ b/lang/en.json @@ -249,6 +249,7 @@ "addUser" : "Add user", "privileges" : "Privileges", "groupWarnMsg" : "You may no longer be able to access this page!", - "groupDeleted" : "Group deleted" + "groupDeleted" : "Group deleted", + "importNewSignature" : "Import a new signature" } } diff --git a/lang/fr.json b/lang/fr.json index 6b8065586d5296ec36a47bdb0f3a180f7b87aa9b..e143e7ba39376fbe3cd49a9fee8999101c0a97fb 100755 --- a/lang/fr.json +++ b/lang/fr.json @@ -250,6 +250,7 @@ "addUser" : "Ajouter un utilisateur", "privileges" : "Privilèges", "groupWarnMsg" : "Vous risquez de ne plus pouvoir accéder à cette page !", - "groupDeleted" : "Groupe supprimé" + "groupDeleted" : "Groupe supprimé", + "importNewSignature" : "Importer une signature" } } diff --git a/src/frontend/app/signatures/signatures.component.html b/src/frontend/app/signatures/signatures.component.html index 6f8275331be8fbf400aff1c6933c4b8b3c406ca6..6d5d45ffd6b5aee0555a9eb12721e4a0fa34eaca 100755 --- a/src/frontend/app/signatures/signatures.component.html +++ b/src/frontend/app/signatures/signatures.component.html @@ -3,6 +3,11 @@ {{'lang.doubletapSignatureToAddDocument' | translate}} </div> <section class="list"> + <div class="list-item create" (click)="uploadFile.click()"> + <i class="fas fa-upload fa-2x"></i> + {{'lang.importNewSignature' | translate}} + </div> + <input #uploadFile type="file" style="display:none;" (change)="handleFileInput($event.target.files)"> <div class="list-item create" (click)="openPad()"> <i class="fas fa-pen-nib fa-2x"></i> {{'lang.createNewSignature' | translate}} diff --git a/src/frontend/app/signatures/signatures.component.ts b/src/frontend/app/signatures/signatures.component.ts index 3f70dbdffafa82cc9e08eb89e5be5b8c2a567acb..3f2cdadbee8a6c9a649c4a973359315d338197bf 100755 --- a/src/frontend/app/signatures/signatures.component.ts +++ b/src/frontend/app/signatures/signatures.component.ts @@ -117,4 +117,46 @@ export class SignaturesComponent implements OnInit { } }, 250); } + + handleFileInput(files: FileList) { + const fileToUpload = files.item(0); + + if (fileToUpload.size <= 2000000) { + if (['image/png', 'image/jpg', 'image/jpeg', 'image/gif'].indexOf(fileToUpload.type) !== -1) { + console.log(fileToUpload.type); + const myReader: FileReader = new FileReader(); + myReader.onloadend = (e) => { + console.log(myReader.result.toString()); + + const newEncodedSign = myReader.result.toString().replace('data:' + fileToUpload.type + ';base64,', ''); + localStorage.setItem('signature', JSON.stringify(newEncodedSign)); + + // Save signature in BDD + const newSign = { + 'id': 0, + 'encodedSignature': newEncodedSign, + 'format': 'png' + }; + this.http.post('../rest/users/' + this.signaturesService.userLogged.id + '/signatures', newSign) + .subscribe((data: any) => { + newSign.id = data.signatureId; + this.signaturesService.newSign = newSign; + this.reloadSignatures(); + this.notificationService.success('lang.signatureRegistered'); + this.bottomSheetRef.dismiss(); + const config: MatBottomSheetConfig = { + disableClose: false, + direction: 'ltr' + }; + this.bottomSheetRef.open(SignaturesComponent, config); + }); + }; + myReader.readAsDataURL(fileToUpload); + } else { + this.notificationService.error('lang.notAnImage'); + } + } else { + this.notificationService.error('lang.imageTooBig'); + } + } }