const env = { xsrfToken: document.getElementsByName('__RequestVerificationToken')[0].value, envKey: document.querySelector('meta[name="env-key"]').getAttribute('content') } const url = { reject: `/api/annotation/reject`, rejectRedir: `/envelope/${env.envKey}`, share: `/api/readonly` }; //#region request helper methods function submitForm(form) { fetch(form.action, { method: form.method, body: new FormData(form), headers: { "X-Requested-With": "XMLHttpRequest" } }) } function createRequest(method, url, body, contentType = 'application/json') { return fetch(url, { credentials: 'include', method: method, headers: { 'Content-Type': contentType, 'X-XSRF-TOKEN': env.xsrfToken }, body: JSON.stringify(body) }) } function createPost(url, body, contentType = 'application/json') { return createRequest('POST', url, body, contentType); } function redirect(url) { return window.location.href = url; } //#endregion function signEnvelope(annotations) { return createPost(`/api/annotation`, annotations, contentType) } function rejectEnvelope(reason) { return createPost(url.reject, reason, Content.JSON); } function redirRejected() { return redirect(url.rejectRedir); } function shareEnvelope(receiverMail, dateValid) { return createPost(url.share, { receiverMail: receiverMail, dateValid: dateValid }, Content.JSON); }