diff --git a/EnvelopeGenerator.Web/wwwroot/js/api-service.js b/EnvelopeGenerator.Web/wwwroot/js/api-service.js index 8d382362..81d88cac 100644 --- a/EnvelopeGenerator.Web/wwwroot/js/api-service.js +++ b/EnvelopeGenerator.Web/wwwroot/js/api-service.js @@ -1,31 +1,31 @@ -const Url = { - get REJECT_URL() { +const url = { + get reject() { return `/api/annotation/reject`; }, - get REJECT_REDIR_URL() { - return `/envelope/${Url.ENV_KEY}`; + get rejectRedir() { + return `/envelope/${url.envKey}`; }, - get SHARE_URL() { + get share() { return `/api/readonly`; }, - get XSRF_TOKEN() { - if (!this.__XSRF_TOKEN) { - this.__XSRF_TOKEN = document.getElementsByName('__RequestVerificationToken')[0].value; + get xsrfToken() { + if (!this.__xsrfToken) { + this.__xsrfToken = document.getElementsByName('__RequestVerificationToken')[0].value; } - return this.__XSRF_TOKEN; + return this.__xsrfToken; }, - get ENV_KEY() { - if (!this.__ENV_KEY) { - this.__ENV_KEY = - typeof ENV_KEY !== "undefined" - ? ENV_KEY + get envKey() { + if (!this.__envKey) { + this.__envKey = + typeof envKey !== "undefined" + ? envKey : document.querySelector('meta[name="env-key"]').getAttribute('content'); } - return this.__ENV_KEY; + return this.__envKey; } }; @@ -45,7 +45,7 @@ function createRequest(method, url, body, contentType = 'application/json') { method: method, headers: { 'Content-Type': contentType, - 'X-XSRF-TOKEN': Url.XSRF_TOKEN + 'X-XSRF-TOKEN': url.xsrfToken }, body: JSON.stringify(body) }) @@ -56,7 +56,7 @@ function createPost(url, body, contentType = 'application/json') { } function rejectEnvelope(reason) { - return createPost(Url.REJECT_URL, reason, Content.JSON); + return createPost(url.reject, reason, Content.JSON); } function redirect(url) { @@ -64,9 +64,9 @@ function redirect(url) { } function redirRejected() { - return redirect(Url.REJECT_REDIR_URL); + return redirect(url.rejectRedir); } function shareEnvelope(receiverMail, dateValid) { - return createPost(Url.SHARE_URL, { receiverMail: receiverMail, dateValid: dateValid }, Content.JSON); + return createPost(url.share, { receiverMail: receiverMail, dateValid: dateValid }, Content.JSON); } \ No newline at end of file diff --git a/EnvelopeGenerator.Web/wwwroot/js/api-service.min.js b/EnvelopeGenerator.Web/wwwroot/js/api-service.min.js index f621f2ee..9c0d03aa 100644 --- a/EnvelopeGenerator.Web/wwwroot/js/api-service.min.js +++ b/EnvelopeGenerator.Web/wwwroot/js/api-service.min.js @@ -1 +1 @@ -function submitForm(n){fetch(n.action,{method:n.method,body:new FormData(n),headers:{"X-Requested-With":"XMLHttpRequest"}})}function createRequest(n,t,i,r="application/json"){return fetch(t,{credentials:"include",method:n,headers:{"Content-Type":r,"X-XSRF-TOKEN":Url.XSRF_TOKEN},body:JSON.stringify(i)})}function createPost(n,t,i="application/json"){return createRequest("POST",n,t,i)}function rejectEnvelope(n){return createPost(Url.REJECT_URL,n,Content.JSON)}function redirect(n){return window.location.href=n}function redirRejected(){return redirect(Url.REJECT_REDIR_URL)}function shareEnvelope(n,t){return createPost(Url.SHARE_URL,{receiverMail:n,dateValid:t},Content.JSON)}const Url={get REJECT_URL(){return`/api/annotation/reject`},get REJECT_REDIR_URL(){return`/envelope/${Url.ENV_KEY}`},get SHARE_URL(){return`/api/readonly`},get XSRF_TOKEN(){return this.__XSRF_TOKEN||(this.__XSRF_TOKEN=document.getElementsByName("__RequestVerificationToken")[0].value),this.__XSRF_TOKEN},get ENV_KEY(){return this.__ENV_KEY||(this.__ENV_KEY=typeof ENV_KEY!="undefined"?ENV_KEY:document.querySelector('meta[name="env-key"]').getAttribute("content")),this.__ENV_KEY}}; \ No newline at end of file +function submitForm(n){fetch(n.action,{method:n.method,body:new FormData(n),headers:{"X-Requested-With":"XMLHttpRequest"}})}function createRequest(n,t,i,r="application/json"){return fetch(t,{credentials:"include",method:n,headers:{"Content-Type":r,"X-XSRF-TOKEN":t.xsrfToken},body:JSON.stringify(i)})}function createPost(n,t,i="application/json"){return createRequest("POST",n,t,i)}function rejectEnvelope(n){return createPost(url.reject,n,Content.JSON)}function redirect(n){return window.location.href=n}function redirRejected(){return redirect(url.rejectRedir)}function shareEnvelope(n,t){return createPost(url.share,{receiverMail:n,dateValid:t},Content.JSON)}const url={get reject(){return`/api/annotation/reject`},get rejectRedir(){return`/envelope/${url.envKey}`},get share(){return`/api/readonly`},get xsrfToken(){return this.__xsrfToken||(this.__xsrfToken=document.getElementsByName("__RequestVerificationToken")[0].value),this.__xsrfToken},get envKey(){return this.__envKey||(this.__envKey=typeof envKey!="undefined"?envKey:document.querySelector('meta[name="env-key"]').getAttribute("content")),this.__envKey}}; \ No newline at end of file