Skip to content

Commit 4e90ac2

Browse files
committed
Allow monitoring the AJAX queue via event loki-components.ajax.loading
1 parent 05ce7ac commit 4e90ac2

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

view/base/templates/script/ajax-queue.phtml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ if ($interval < 10) {
2727
const LokiAjaxQueue = {
2828
requests: [],
2929
interval: <?= (int)$interval ?>,
30+
loading: false,
3031
add(component, update) {
3132
this.requests.push({
3233
component,
@@ -38,6 +39,10 @@ if ($interval < 10) {
3839
this.post();
3940
}, this.interval);
4041
},
42+
setLoading(loading) {
43+
this.loading = loading;
44+
document.dispatchEvent(new CustomEvent('loki-components.ajax.loading', {detail: loading}));
45+
},
4146
async post() {
4247
if (!this.requests.length > 0) {
4348
return;
@@ -53,6 +58,7 @@ if ($interval < 10) {
5358
request.component.beforePost();
5459
});
5560

61+
this.setLoading(true);
5662
this.requests = [];
5763

5864
await fetch('<?= $escaper->escapeUrl($componentUtil->getPostUrl(
@@ -92,6 +98,8 @@ if ($interval < 10) {
9298
requests.forEach(request => {
9399
request.component.afterPostFinally();
94100
});
101+
102+
this.setLoading(false);
95103
});
96104
},
97105
getPostHeaders() {

0 commit comments

Comments
 (0)