validation client and server
This commit is contained in:
@@ -23,17 +23,17 @@ class App {
|
||||
this.Instance = null
|
||||
this.currentDocument = null
|
||||
this.currentReceiver = null
|
||||
this.signatureCount = 0
|
||||
}
|
||||
|
||||
// This function will be called in the ShowEnvelope.razor page
|
||||
// This function will be called from the ShowEnvelope.razor page
|
||||
// and will trigger loading of the Editor Interface
|
||||
async init() {
|
||||
// Load the envelope from the database
|
||||
console.debug('Loading envelope from database..')
|
||||
const envelopeResponse = await this.Network.getEnvelope(this.envelopeKey)
|
||||
const envelopeError = !!envelopeResponse.error
|
||||
|
||||
if (envelopeError) {
|
||||
if (envelopeResponse.fatal) {
|
||||
return Swal.fire({
|
||||
title: 'Fehler',
|
||||
text: 'Umschlag konnte nicht geladen werden!',
|
||||
@@ -41,6 +41,14 @@ class App {
|
||||
})
|
||||
}
|
||||
|
||||
if (envelopeResponse.error) {
|
||||
return Swal.fire({
|
||||
title: 'Warnung',
|
||||
text: 'Umschlag ist nicht mehr verfügbar.',
|
||||
icon: 'warning',
|
||||
})
|
||||
}
|
||||
|
||||
this.currentDocument = envelopeResponse.data.envelope.documents[0]
|
||||
this.currentReceiver = envelopeResponse.data.receiver
|
||||
|
||||
@@ -50,9 +58,8 @@ class App {
|
||||
this.envelopeKey,
|
||||
this.currentDocument.id
|
||||
)
|
||||
const documentError = !!documentResponse.error
|
||||
|
||||
if (documentError) {
|
||||
if (documentResponse.fatal || documentResponse.error) {
|
||||
console.error(documentResponse.error)
|
||||
return Swal.fire({
|
||||
title: 'Fehler',
|
||||
@@ -85,12 +92,21 @@ class App {
|
||||
console.debug('Loading annotations..')
|
||||
|
||||
try {
|
||||
this.signatureCount = this.currentDocument.elements.length
|
||||
const annotations = this.Annotation.createAnnotations(
|
||||
this.currentDocument
|
||||
)
|
||||
const createdAnnotations = await this.Instance.create(annotations)
|
||||
await this.Instance.create(annotations)
|
||||
|
||||
await this.Network.openDocument(this.envelopeKey)
|
||||
const openResponse = await this.Network.openDocument(this.envelopeKey)
|
||||
|
||||
if (openResponse.fatal || openResponse.error) {
|
||||
return Swal.fire({
|
||||
title: 'Fehler',
|
||||
text: 'Umschlag konnte nicht geöffnet werden!',
|
||||
icon: 'error',
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
@@ -169,8 +185,6 @@ class App {
|
||||
if (result == true) {
|
||||
// Redirect to success page after saving to database
|
||||
window.location.href = `/EnvelopeKey/${this.envelopeKey}/Success`
|
||||
} else {
|
||||
alert('Fehler beim Abschließen des Dokuments!')
|
||||
}
|
||||
|
||||
break
|
||||
@@ -181,11 +195,28 @@ class App {
|
||||
}
|
||||
|
||||
async handleFinish(event) {
|
||||
|
||||
const validationResult = await this.validateAnnotations(this.signatureCount)
|
||||
if (validationResult === false) {
|
||||
Swal.fire({
|
||||
title: 'Warnung',
|
||||
text: 'Es wurden nicht alle Signaturfelder ausgefüllt!',
|
||||
icon: 'warning',
|
||||
})
|
||||
return false
|
||||
|
||||
}
|
||||
|
||||
// Save changes before doing anything
|
||||
try {
|
||||
await this.Instance.save()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
Swal.fire({
|
||||
title: 'Fehler',
|
||||
text: 'Umschlag konnte nicht signiert werden!',
|
||||
icon: 'error',
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -195,20 +226,64 @@ class App {
|
||||
const postEnvelopeResult = await this.Network.postEnvelope(
|
||||
this.envelopeKey,
|
||||
this.currentDocument.id,
|
||||
JSON.stringify(json)
|
||||
json
|
||||
)
|
||||
|
||||
console.log(postEnvelopeResult)
|
||||
|
||||
if (postEnvelopeResult === false) {
|
||||
if (postEnvelopeResult.fatal) {
|
||||
Swal.fire({
|
||||
title: 'Fehler',
|
||||
text: 'Umschlag konnte nicht signiert werden!',
|
||||
icon: 'error',
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
if (postEnvelopeResult.error) {
|
||||
Swal.fire({
|
||||
title: 'Warnung',
|
||||
text: 'Umschlag ist nicht mehr verfügbar.',
|
||||
icon: 'warning',
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
async validateAnnotations(totalSignatures) {
|
||||
const annotations = await this.Annotation.getAnnotations(this.Instance)
|
||||
const filtered = annotations
|
||||
.map(a => a.toJS())
|
||||
.filter(a => a.isSignature)
|
||||
|
||||
console.log(filtered.length, "Signatures signed!")
|
||||
|
||||
if (totalSignatures > filtered.length) {
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
|
||||
/*this.Instance.getFormFields().then(formFields => {
|
||||
formFields.forEach(formField => {
|
||||
console.log(formField.name, formField.toJS());
|
||||
});
|
||||
|
||||
// Filter form fields by type
|
||||
formFields.filter(formField => (
|
||||
formField instanceof PSPDFKit.FormFields.TextFormField
|
||||
));
|
||||
|
||||
// Get the total number of form fields
|
||||
const totalFormFields = formFields.size;
|
||||
|
||||
console.log(totalFormFields)
|
||||
})*/
|
||||
}
|
||||
|
||||
async handleReset(event) {
|
||||
|
||||
Reference in New Issue
Block a user