View | Details | Raw Unified | Return to bug 40172
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/js/fetch/http-client.js (-8 / +33 lines)
Lines 1-16 Link Here
1
function _ifDocumentAvailable(callback) {
2
    if (typeof document !== "undefined" && document.getElementById) {
3
        callback();
4
    }
5
}
6
1
class Dialog {
7
class Dialog {
2
    constructor(options = {}) {}
8
    constructor(options = {}) {}
3
9
10
    _appendMessage(type, message) {
11
        _ifDocumentAvailable(() => {
12
            const messagesContainer = document.getElementById("messages");
13
            if (!messagesContainer) {
14
                return;
15
            }
16
17
            const htmlString =
18
                `<div class="alert alert-${type}">%s</div>`.format(message);
19
            messagesContainer.insertAdjacentHTML("beforeend", htmlString);
20
        });
21
    }
22
4
    setMessage(message) {
23
    setMessage(message) {
5
        $("#messages").append(
24
        this._appendMessage("info", message);
6
            '<div class="alert alert-info">%s</div>'.format(message)
7
        );
8
    }
25
    }
9
26
10
    setError(error) {
27
    setError(error) {
11
        $("#messages").append(
28
        this._appendMessage("warning", error);
12
            '<div class="alert alert-warning">%s</div>'.format(error)
13
        );
14
    }
29
    }
15
}
30
}
16
31
Lines 22-28 class HttpClient { Link Here
22
            "Content-Type": "application/json;charset=utf-8",
37
            "Content-Type": "application/json;charset=utf-8",
23
            "X-Requested-With": "XMLHttpRequest",
38
            "X-Requested-With": "XMLHttpRequest",
24
        };
39
        };
25
        this.csrf_token = $('meta[name="csrf-token"]').attr("content");
40
        this.csrf_token = this._getCsrfToken(options);
41
    }
42
43
    _getCsrfToken(options) {
44
        let token = null;
45
        _ifDocumentAvailable(() => {
46
            const metaTag = document.querySelector('meta[name="csrf-token"]');
47
            if (metaTag) {
48
                token = metaTag.getAttribute("content");
49
            }
50
        });
51
        return token !== null ? token : options.csrfToken || null;
26
    }
52
    }
27
53
28
    async _fetchJSON(
54
    async _fetchJSON(
29
- 

Return to bug 40172