Lines 1-3
Link Here
|
|
|
1 |
/* keep tidy */ |
1 |
class Dialog { |
2 |
class Dialog { |
2 |
constructor(options = {}) {} |
3 |
constructor(options = {}) {} |
3 |
|
4 |
|
Lines 17-25
class Dialog {
Link Here
|
17 |
class HttpClient { |
18 |
class HttpClient { |
18 |
constructor(options = {}) { |
19 |
constructor(options = {}) { |
19 |
this._baseURL = options.baseURL || ""; |
20 |
this._baseURL = options.baseURL || ""; |
20 |
this._headers = options.headers || { // FIXME we actually need to merge the headers |
21 |
this._headers = options.headers || { |
|
|
22 |
// FIXME we actually need to merge the headers |
21 |
"Content-Type": "application/json;charset=utf-8", |
23 |
"Content-Type": "application/json;charset=utf-8", |
22 |
"X-Requested-With": "XMLHttpRequest" |
24 |
"X-Requested-With": "XMLHttpRequest", |
23 |
}; |
25 |
}; |
24 |
this.csrf_token = $('meta[name="csrf-token"]').attr("content"); |
26 |
this.csrf_token = $('meta[name="csrf-token"]').attr("content"); |
25 |
} |
27 |
} |
Lines 38-44
class HttpClient {
Link Here
|
38 |
headers: { ...this._headers, ...headers }, |
40 |
headers: { ...this._headers, ...headers }, |
39 |
}) |
41 |
}) |
40 |
.then(response => { |
42 |
.then(response => { |
41 |
const is_json = response.headers.get("content-type")?.includes("application/json"); |
43 |
const is_json = response.headers |
|
|
44 |
.get("content-type") |
45 |
?.includes("application/json"); |
42 |
if (!response.ok) { |
46 |
if (!response.ok) { |
43 |
return response.text().then(text => { |
47 |
return response.text().then(text => { |
44 |
let message; |
48 |
let message; |
Lines 54-60
class HttpClient {
Link Here
|
54 |
throw new Error(message); |
58 |
throw new Error(message); |
55 |
}); |
59 |
}); |
56 |
} |
60 |
} |
57 |
if ( return_response || !is_json ) { |
61 |
if (return_response || !is_json) { |
58 |
return response; |
62 |
return response; |
59 |
} |
63 |
} |
60 |
return response.json(); |
64 |
return response.json(); |
Lines 133-139
class HttpClient {
Link Here
|
133 |
true |
137 |
true |
134 |
); |
138 |
); |
135 |
} |
139 |
} |
136 |
|
|
|
137 |
} |
140 |
} |
138 |
|
141 |
|
139 |
export default HttpClient; |
142 |
export default HttpClient; |