Bug 32030: Add 'Loading...' until the data is fetched
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / vue / fetch.js
1 export const fetchAgreement = async function (agreement_id) {
2     if (!agreement_id) return;
3     const apiUrl = "/api/v1/erm/agreements/" + agreement_id;
4     let agreement;
5     await fetch(apiUrl, {
6         headers: {
7             "x-koha-embed":
8                 "periods,user_roles,user_roles.patron,agreement_licenses,agreement_licenses.license",
9         },
10     })
11         .then((res) => res.json())
12         .then(
13             (result) => {
14                 agreement = result;
15             },
16             (error) => {
17                 this.setError(error);
18             }
19         );
20     return agreement;
21 };
22
23 export const fetchAgreements = async function () {
24     const apiUrl = "/api/v1/erm/agreements"
25     let agreements;
26     await fetch(apiUrl)
27         .then((res) => res.json())
28         .then(
29             (result) => {
30                 agreements = result;
31             },
32             (error) => {
33                 this.setError(error);
34             }
35         );
36     return agreements;
37 };
38
39 export const fetchLicense = async function (license_id) {
40     if (!license_id) return;
41     const apiUrl = "/api/v1/erm/licenses/" + license_id;
42     let license;
43     await fetch(apiUrl)
44         .then((res) => res.json())
45         .then(
46             (result) => {
47                 license = result;
48             },
49             (error) => {
50                 this.setError(error);
51             }
52         );
53     return license;
54 };