Die Datei „api-service.js“ für HTTP-Anfragen erstellt. HTTP-POST-Anforderung erstellt, um die generierten Umschläge zurückzuweisen.
This commit is contained in:
41
EnvelopeGenerator.Web/wwwroot/js/api-service.js
Normal file
41
EnvelopeGenerator.Web/wwwroot/js/api-service.js
Normal file
@@ -0,0 +1,41 @@
|
||||
class Content {
|
||||
static get JSON () {
|
||||
return 'application/json';
|
||||
}
|
||||
}
|
||||
|
||||
class API {
|
||||
static get REJECT_URL () {
|
||||
return `/api/envelope/reject`;
|
||||
}
|
||||
|
||||
static __XSRF_TOKEN
|
||||
static get XSRF_TOKEN() {
|
||||
API.__XSRF_TOKEN ??= document.getElementsByName('__RequestVerificationToken')[0].value;
|
||||
return API.__XSRF_TOKEN;
|
||||
}
|
||||
}
|
||||
|
||||
const submitForm = async form => await fetch(form.action, {
|
||||
method: form.method,
|
||||
body: new FormData(form),
|
||||
headers: {
|
||||
"X-Requested-With": "XMLHttpRequest"
|
||||
}
|
||||
})
|
||||
|
||||
const createRequest = async (method, url, body, contentType) => {
|
||||
return fetch(url, {
|
||||
credentials: 'include',
|
||||
method: method,
|
||||
headers: {
|
||||
'Content-Type': contentType,
|
||||
'X-XSRF-TOKEN': API.XSRF_TOKEN
|
||||
},
|
||||
body: JSON.stringify(body)
|
||||
})
|
||||
}
|
||||
|
||||
const createPost = (url, body, contentType) => createRequest('POST', url, body, contentType);
|
||||
|
||||
const rejectEnvelope = (reason) => createPost(API.REJECT_URL, reason, Content.JSON);
|
||||
@@ -1,7 +0,0 @@
|
||||
const submitForm = async form => await fetch(form.action, {
|
||||
method: form.method,
|
||||
body: new FormData(form),
|
||||
headers: {
|
||||
"X-Requested-With": "XMLHttpRequest"
|
||||
}
|
||||
})
|
||||
@@ -180,14 +180,14 @@ class App {
|
||||
}
|
||||
|
||||
return Swal.fire({
|
||||
title: localized.Confirmation,
|
||||
html: `<div class="text-start fs-6 p-0 m-0">${localized.SigAgree}</div>`,
|
||||
title: localized.confirmation,
|
||||
html: `<div class="text-start fs-6 p-0 m-0">${localized.sigAgree}</div>`,
|
||||
icon: "question",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#3085d6",
|
||||
cancelButtonColor: "#d33",
|
||||
confirmButtonText: localized.Finalize,
|
||||
cancelButtonText: localized.Back
|
||||
confirmButtonText: localized.finalize,
|
||||
cancelButtonText: localized.back
|
||||
}).then(async (result) => {
|
||||
if (result.isConfirmed) {
|
||||
//---
|
||||
|
||||
37
EnvelopeGenerator.Web/wwwroot/js/event-binder.js
Normal file
37
EnvelopeGenerator.Web/wwwroot/js/event-binder.js
Normal file
@@ -0,0 +1,37 @@
|
||||
$('.btn_reject').click(_ =>
|
||||
Swal.fire({
|
||||
title: localized.rejection,
|
||||
html: `<div class="text-start fs-6 p-0 m-0">${localized.rejectionReasonQ}</div>`,
|
||||
icon: "question",
|
||||
input: "text",
|
||||
inputAttributes: {
|
||||
autocapitalize: "off"
|
||||
},
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#3085d6",
|
||||
cancelButtonColor: "#d33",
|
||||
confirmButtonText: localized.complete,
|
||||
cancelButtonText: localized.back,
|
||||
showLoaderOnConfirm: true,
|
||||
preConfirm: async (reason) => {
|
||||
try {
|
||||
var res = await rejectEnvelope(reason);
|
||||
return res;
|
||||
} catch (error) {
|
||||
Swal.showValidationMessage(`
|
||||
Request failed: ${error}
|
||||
`);
|
||||
}
|
||||
},
|
||||
allowOutsideClick: () => !Swal.isLoading()
|
||||
}).then((result) => {
|
||||
if (!result.isConfirmed)
|
||||
return;
|
||||
const res = result.value;
|
||||
console.log(res)
|
||||
if (res.ok) {
|
||||
alert('rejected')
|
||||
}
|
||||
else
|
||||
alert('fail')
|
||||
}));
|
||||
Reference in New Issue
Block a user