parent
cd6a139daf
commit
f6334397dc
|
@ -16,6 +16,7 @@
|
|||
<button
|
||||
type="button"
|
||||
class="focus:border-black focus:ring-2 focus:ring-black text-white text-sm py-2.5 px-5 rounded-md bg-blue-500 hover:bg-blue-600 hover:shadow-lg"
|
||||
@click="get_certificate"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
|
@ -258,6 +259,7 @@ const state = reactive({
|
|||
group: "",
|
||||
activetab: "profile",
|
||||
delete_active: false,
|
||||
fullobject: {}
|
||||
})
|
||||
const toast = useToast();
|
||||
const props = defineProps({
|
||||
|
@ -272,6 +274,7 @@ axios.get(`${config.baseurl}api/runners/me/${accesstoken}`)
|
|||
state.middlename = data.middlename;
|
||||
state.lastname = data.lastname;
|
||||
state.group = data.group;
|
||||
state.fullobject = data;
|
||||
}).catch((error) => {
|
||||
toast.error("An error occured while loading your profile data");
|
||||
})
|
||||
|
@ -298,4 +301,54 @@ function delete_me() {
|
|||
toast.error("An error occured while deleting your profile data");
|
||||
});
|
||||
}
|
||||
function get_certificate() {
|
||||
toast("Generation in progress...");
|
||||
const browserlocale = ((navigator.languages && navigator.languages[0]) || '').substr(0, 2);
|
||||
let url = `${config.baseurl}documents/certificates?locale=${browserlocale}&download=true&key=${config.documentserver_key}`;
|
||||
let postdata = Object.assign({}, state.fullobject);
|
||||
postdata.group = {
|
||||
name: postdata.group
|
||||
}
|
||||
postdata = [{
|
||||
"responseType": "SELFSERVICRUNNER",
|
||||
"id": 49,
|
||||
"firstname": "string",
|
||||
"middlename": "string",
|
||||
"lastname": "string",
|
||||
"phone": null,
|
||||
"email": "me@me.nig.gl",
|
||||
"address": {
|
||||
"address1": null,
|
||||
"address2": null,
|
||||
"postalcode": null,
|
||||
"city": null,
|
||||
"country": null
|
||||
},
|
||||
"distance": 0,
|
||||
"donationAmount": 0,
|
||||
"group": { "name": "Citizen" },
|
||||
"distanceDonations": []
|
||||
}]
|
||||
axios.post(url, postdata)
|
||||
.then((response) => {
|
||||
if (response.status != "200") {
|
||||
toast.error("An error occured while generateing your certificate!");
|
||||
} else {
|
||||
var fileURL = window.URL.createObjectURL(new Blob([response.data]));
|
||||
var fileLink = document.createElement('a');
|
||||
|
||||
fileLink.href = fileURL;
|
||||
fileLink.setAttribute('download', 'Certificate.pdf');
|
||||
document.body.appendChild(fileLink);
|
||||
|
||||
fileLink.click();
|
||||
fileLink.remove();
|
||||
toast("Document generated!");
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
toast.error("An error occured while deleting your profile data");
|
||||
});
|
||||
}
|
||||
</script>
|
Loading…
Reference in New Issue