loading works again
This commit is contained in:
@@ -44,25 +44,31 @@ var App = /** @class */ (function () {
|
||||
}
|
||||
// This function will be called in the ShowEnvelope.razor page
|
||||
// and will trigger loading of the Editor Interface
|
||||
App.loadPDFFromUrl = function (container, envelopeKey) {
|
||||
App.init = function (container, envelopeKey) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var envelopeObject, arrayBuffer, e_1, _a, annotations, createdAnnotations;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
// Initialize classes
|
||||
console.debug("Initializing classes..");
|
||||
App.UI = new UI();
|
||||
App.Network = new Network();
|
||||
App.Annotation = new Annotation();
|
||||
console.debug("Loading PSPDFKit..");
|
||||
return [4 /*yield*/, App.Network.loadData(envelopeKey)];
|
||||
// Load the envelope from the database
|
||||
console.debug("Loading envelope from database..");
|
||||
return [4 /*yield*/, App.Network.getEnvelope(envelopeKey)];
|
||||
case 1:
|
||||
envelopeObject = _b.sent();
|
||||
console.debug(envelopeObject);
|
||||
App.envelopeKey = envelopeKey;
|
||||
App.currentDocument = envelopeObject.envelope.documents[0];
|
||||
// Load the document from the filestore
|
||||
console.debug("Loading document from filestore");
|
||||
_b.label = 2;
|
||||
case 2:
|
||||
_b.trys.push([2, 4, , 5]);
|
||||
return [4 /*yield*/, App.Network.loadDocument(envelopeKey, App.currentDocument.id)];
|
||||
return [4 /*yield*/, App.Network.getDocument(envelopeKey, App.currentDocument.id)];
|
||||
case 3:
|
||||
arrayBuffer = _b.sent();
|
||||
return [3 /*break*/, 5];
|
||||
@@ -71,24 +77,19 @@ var App = /** @class */ (function () {
|
||||
console.error(e_1);
|
||||
return [3 /*break*/, 5];
|
||||
case 5:
|
||||
// Load PSPDFKit
|
||||
console.debug("Loading PSPDFKit..");
|
||||
_a = App;
|
||||
return [4 /*yield*/, App.UI.loadPSPDFKit(arrayBuffer, container)];
|
||||
case 6:
|
||||
_a.Instance = _b.sent();
|
||||
App.UI.configurePSPDFKit(this.Instance, App.handleClick);
|
||||
console.debug(envelopeObject.envelope);
|
||||
console.debug("PSPDFKit configured!");
|
||||
annotations = [];
|
||||
App.currentDocument.elements.forEach(function (element) {
|
||||
console.log("Creating annotation for element", element.id);
|
||||
var _a = App.Annotation.createAnnotationFromElement(element), annotation = _a[0], formField = _a[1];
|
||||
annotations.push(annotation);
|
||||
annotations.push(formField);
|
||||
});
|
||||
// Load annotations into PSPDFKit
|
||||
console.debug("Loading annotations..");
|
||||
annotations = App.Annotation.createAnnotations(App.currentDocument);
|
||||
return [4 /*yield*/, App.Instance.create(annotations)];
|
||||
case 7:
|
||||
createdAnnotations = _b.sent();
|
||||
console.debug(createdAnnotations);
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
@@ -198,21 +199,16 @@ export { App };
|
||||
var Annotation = /** @class */ (function () {
|
||||
function Annotation() {
|
||||
}
|
||||
Annotation.prototype.createAnnotationFromElement = function (element) {
|
||||
var id = PSPDFKit.generateInstantId();
|
||||
var width = this.inchToPoint(element.width);
|
||||
var height = this.inchToPoint(element.height);
|
||||
var top = this.inchToPoint(element.top) - (height / 2);
|
||||
var left = this.inchToPoint(element.left) - (width / 2);
|
||||
var page = element.page - 1;
|
||||
var annotation = this.createSignatureAnnotation(id, width, height, top, left, page);
|
||||
console.log(annotation);
|
||||
var formField = new SignatureFormField({
|
||||
name: id,
|
||||
annotationIds: List([annotation.id])
|
||||
Annotation.prototype.createAnnotations = function (document) {
|
||||
var _this = this;
|
||||
var annotations = [];
|
||||
document.elements.forEach(function (element) {
|
||||
console.log("Creating annotation for element", element.id);
|
||||
var _a = _this.createAnnotationFromElement(element), annotation = _a[0], formField = _a[1];
|
||||
annotations.push(annotation);
|
||||
annotations.push(formField);
|
||||
});
|
||||
console.log(formField);
|
||||
return [annotation, formField];
|
||||
return annotations;
|
||||
};
|
||||
Annotation.prototype.deleteAnnotations = function (instance) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
@@ -234,6 +230,22 @@ var Annotation = /** @class */ (function () {
|
||||
});
|
||||
});
|
||||
};
|
||||
Annotation.prototype.createAnnotationFromElement = function (element) {
|
||||
var id = PSPDFKit.generateInstantId();
|
||||
var width = this.inchToPoint(element.width);
|
||||
var height = this.inchToPoint(element.height);
|
||||
var top = this.inchToPoint(element.top) - (height / 2);
|
||||
var left = this.inchToPoint(element.left) - (width / 2);
|
||||
var page = element.page - 1;
|
||||
var annotation = this.createSignatureAnnotation(id, width, height, top, left, page);
|
||||
console.log(annotation);
|
||||
var formField = new SignatureFormField({
|
||||
name: id,
|
||||
annotationIds: List([annotation.id])
|
||||
});
|
||||
console.log(formField);
|
||||
return [annotation, formField];
|
||||
};
|
||||
Annotation.prototype.createSignatureAnnotation = function (id, width, height, top, left, pageIndex) {
|
||||
var annotation = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||
id: id,
|
||||
@@ -251,18 +263,20 @@ var Annotation = /** @class */ (function () {
|
||||
var Network = /** @class */ (function () {
|
||||
function Network() {
|
||||
}
|
||||
// Makes a call to the supplied url and fetches the binary response as an array buffer
|
||||
Network.prototype.loadDocument = function (envelopeKey, documentId) {
|
||||
return fetch("/api/file/".concat(envelopeKey, "?id=").concat(documentId), { credentials: "include" })
|
||||
.then(function (res) { return res.arrayBuffer(); });
|
||||
};
|
||||
// Makes a call to the supplied url and fetches the json response as an object
|
||||
Network.prototype.loadData = function (envelopeKey) {
|
||||
Network.prototype.getEnvelope = function (envelopeKey) {
|
||||
return fetch("/api/envelope/".concat(envelopeKey), { credentials: "include" })
|
||||
.then(function (res) { return res.json(); });
|
||||
};
|
||||
Network.prototype.getDocument = function (envelopeKey, documentId) {
|
||||
return fetch("/api/document/".concat(envelopeKey, "?index=").concat(documentId), { credentials: "include" })
|
||||
.then(function (res) { return res.arrayBuffer(); });
|
||||
};
|
||||
Network.prototype.postDocument = function (envelopeKey, documentId, buffer) {
|
||||
return fetch("/api/upload/".concat(envelopeKey, "/").concat(documentId), { credentials: "include", method: "POST", body: buffer })
|
||||
return fetch("/api/document/".concat(envelopeKey, "/").concat(documentId), { credentials: "include", method: "POST", body: buffer })
|
||||
.then(function (res) { return res.json(); });
|
||||
};
|
||||
Network.prototype.postEnvelope = function (envelopeKey, documentId, buffer) {
|
||||
return fetch("/api/envelope/".concat(envelopeKey, "/").concat(documentId), { credentials: "include", method: "POST", body: buffer })
|
||||
.then(function (res) { return res.json(); });
|
||||
};
|
||||
return Network;
|
||||
@@ -339,6 +353,7 @@ var UI = /** @class */ (function () {
|
||||
}); });
|
||||
var toolbarItems = this.getToolbarItems(instance, handler);
|
||||
instance.setToolbarItems(toolbarItems);
|
||||
console.debug("PSPDFKit configured!");
|
||||
};
|
||||
UI.prototype.getToolbarItems = function (instance, handler) {
|
||||
var customItems = this.getCustomItems(handler);
|
||||
|
||||
Reference in New Issue
Block a user