Bug 30719: ILL Batches
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / ill-batch.js
1 (function () {
2     // Enable the modal to be opened from anywhere
3     // If we're working with an existing batch, set the ID so the
4     // modal can access it
5     window.openBatchModal = function (id, backend) {
6         var idEl = document.getElementById('ill-batch-details');
7         idEl.dataset.backend = backend;
8         if (id) {
9             idEl.dataset.batchId = id;
10         }
11         $('#ill-batch-modal').modal({ show: true });
12     };
13
14     // Make a batch API call, returning the resulting promise
15     window.doBatchApiRequest = function (url, options) {
16         var batchListApi = '/api/v1/illbatches';
17         var fullUrl = batchListApi + (url ? url : '');
18         return doApiRequest(fullUrl, options);
19     };
20
21     // Make a "create local ILL submission" call
22     window.doCreateSubmission = function (body, options) {
23         options = Object.assign(
24             options || {},
25             {
26                 headers: {
27                     'Content-Type': 'application/json'
28                 },
29                 method: 'POST',
30                 body: JSON.stringify(body)
31             }
32         );
33         return doApiRequest(
34             '/api/v1/ill/requests',
35             options
36         )
37     }
38
39     // Make an API call, returning the resulting promise
40     window.doApiRequest = function (url, options) {
41         return fetch(url, options);
42     };
43
44     // Display an API error
45     window.handleApiError = function (error) {
46         alert(error);
47     };
48
49 })();