add prettier & format
This commit is contained in:
@@ -6,153 +6,171 @@ const ActionType = {
|
||||
Delivered: 4,
|
||||
Seen: 5,
|
||||
Signed: 6,
|
||||
Rejected: 7
|
||||
Rejected: 7,
|
||||
}
|
||||
|
||||
class App {
|
||||
constructor(container, envelopeKey) {
|
||||
this.container = container;
|
||||
this.envelopeKey = envelopeKey;
|
||||
this.container = container
|
||||
this.envelopeKey = envelopeKey
|
||||
|
||||
// Initialize classes
|
||||
console.debug("Initializing classes..")
|
||||
this.UI = new UI();
|
||||
this.Network = new Network();
|
||||
this.Annotation = new Annotation();
|
||||
console.debug('Initializing classes..')
|
||||
this.UI = new UI()
|
||||
this.Network = new Network()
|
||||
this.Annotation = new Annotation()
|
||||
|
||||
this.Instance = null;
|
||||
this.currentDocument = null;
|
||||
this.currentReceiver = null;
|
||||
this.Instance = null
|
||||
this.currentDocument = null
|
||||
this.currentReceiver = null
|
||||
}
|
||||
|
||||
// This function will be called in 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 envelopeObject = await this.Network.getEnvelope(this.envelopeKey);
|
||||
this.currentDocument = envelopeObject.envelope.documents[0];
|
||||
this.currentReceiver = envelopeObject.receiver;
|
||||
console.debug('Loading envelope from database..')
|
||||
const envelopeObject = await this.Network.getEnvelope(this.envelopeKey)
|
||||
this.currentDocument = envelopeObject.envelope.documents[0]
|
||||
this.currentReceiver = envelopeObject.receiver
|
||||
|
||||
console.log(envelopeObject)
|
||||
|
||||
// Load the document from the filestore
|
||||
console.debug("Loading document from filestore")
|
||||
console.debug('Loading document from filestore')
|
||||
let arrayBuffer
|
||||
try {
|
||||
arrayBuffer = await this.Network.getDocument(this.envelopeKey, this.currentDocument.id);
|
||||
arrayBuffer = await this.Network.getDocument(
|
||||
this.envelopeKey,
|
||||
this.currentDocument.id
|
||||
)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
|
||||
// Load PSPDFKit
|
||||
console.debug("Loading PSPDFKit..")
|
||||
console.debug('Loading PSPDFKit..')
|
||||
this.Instance = await this.UI.loadPSPDFKit(arrayBuffer, this.container)
|
||||
this.UI.configurePSPDFKit(this.Instance, this.handleClick.bind(this))
|
||||
|
||||
this.Instance.addEventListener("annotations.load", this.handleAnnotationsLoad)
|
||||
this.Instance.addEventListener("annotations.change", this.handleAnnotationsChange)
|
||||
this.Instance.addEventListener("annotations.create", this.handleAnnotationsCreate.bind(this))
|
||||
this.Instance.addEventListener(
|
||||
'annotations.load',
|
||||
this.handleAnnotationsLoad
|
||||
)
|
||||
this.Instance.addEventListener(
|
||||
'annotations.change',
|
||||
this.handleAnnotationsChange
|
||||
)
|
||||
this.Instance.addEventListener(
|
||||
'annotations.create',
|
||||
this.handleAnnotationsCreate.bind(this)
|
||||
)
|
||||
|
||||
// Load annotations into PSPDFKit
|
||||
console.debug("Loading annotations..")
|
||||
console.debug('Loading annotations..')
|
||||
|
||||
try {
|
||||
const annotations = this.Annotation.createAnnotations(this.currentDocument)
|
||||
const annotations = this.Annotation.createAnnotations(
|
||||
this.currentDocument
|
||||
)
|
||||
const createdAnnotations = await this.Instance.create(annotations)
|
||||
|
||||
await this.Network.postHistory(this.envelopeKey, ActionType.Seen)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
handleAnnotationsLoad(loadedAnnotations) {
|
||||
console.log("annotations loaded", loadedAnnotations.toJS());
|
||||
console.log('annotations loaded', loadedAnnotations.toJS())
|
||||
}
|
||||
|
||||
handleAnnotationsChange() {}
|
||||
|
||||
async handleAnnotationsCreate(createdAnnotations) {
|
||||
const annotation = createdAnnotations.toJS()[0];
|
||||
const isFormField = !!annotation.formFieldName;
|
||||
const isSignature = !!annotation.isSignature;
|
||||
const annotation = createdAnnotations.toJS()[0]
|
||||
const isFormField = !!annotation.formFieldName
|
||||
const isSignature = !!annotation.isSignature
|
||||
|
||||
if (isFormField === false && isSignature === true) {
|
||||
await this.Annotation.createFrameAnnotation(annotation, this.currentReceiver)
|
||||
}
|
||||
await this.Annotation.createFrameAnnotation(
|
||||
annotation,
|
||||
this.currentReceiver
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
async handleClick(eventType) {
|
||||
let result = false;
|
||||
let result = false
|
||||
|
||||
switch (eventType) {
|
||||
case "RESET":
|
||||
case 'RESET':
|
||||
result = await this.handleReset(null)
|
||||
|
||||
if (result == true) {
|
||||
alert("Dokument zurückgesetzt!");
|
||||
alert('Dokument zurückgesetzt!')
|
||||
} else {
|
||||
alert("Fehler beim Zurücksetzen des Dokuments!")
|
||||
alert('Fehler beim Zurücksetzen des Dokuments!')
|
||||
}
|
||||
|
||||
break;
|
||||
break
|
||||
|
||||
case "FINISH":
|
||||
case 'FINISH':
|
||||
result = await this.handleFinish(null)
|
||||
|
||||
if (result == true) {
|
||||
// TODO: Redirect to success page
|
||||
alert("Dokument erfolgreich signiert!")
|
||||
alert('Dokument erfolgreich signiert!')
|
||||
} else {
|
||||
alert("Fehler beim Abschließen des Dokuments!")
|
||||
alert('Fehler beim Abschließen des Dokuments!')
|
||||
}
|
||||
|
||||
break;
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
async handleFinish(event) {
|
||||
|
||||
// Save changes before doing anything
|
||||
try {
|
||||
await this.Instance.save();
|
||||
await this.Instance.save()
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return false;
|
||||
console.error(e)
|
||||
return false
|
||||
}
|
||||
|
||||
// Export annotation data and save to database
|
||||
try {
|
||||
const json = await this.Instance.exportInstantJSON()
|
||||
const postEnvelopeResult = await this.Network.postEnvelope(this.envelopeKey, this.currentDocument.id, JSON.stringify(json))
|
||||
const postEnvelopeResult = await this.Network.postEnvelope(
|
||||
this.envelopeKey,
|
||||
this.currentDocument.id,
|
||||
JSON.stringify(json)
|
||||
)
|
||||
|
||||
if (postEnvelopeResult === false) {
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
|
||||
// Redirect to success page after saving to database
|
||||
window.location.href = `/EnvelopeKey/${this.envelopeKey}/Success`
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return false;
|
||||
console.error(e)
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
async handleReset(event) {
|
||||
if (confirm("Wollen Sie das Dokument und alle erstellten Signaturen zurücksetzen?")) {
|
||||
async handleReset(event) {
|
||||
if (
|
||||
confirm(
|
||||
'Wollen Sie das Dokument und alle erstellten Signaturen zurücksetzen?'
|
||||
)
|
||||
) {
|
||||
const result = this.Annotation.deleteAnnotations(this.Instance)
|
||||
return true;
|
||||
return true
|
||||
} else {
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user