]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
utils: api request: defer masking after layout
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 19 Mar 2024 08:51:38 +0000 (09:51 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 19 Mar 2024 17:05:13 +0000 (18:05 +0100)
Since recently (not sure when exactly), the 'load()' method of the
edit window did not correctly mask the window anymore

The reason seems to be that the API2Request tries to mask the
component before it's rendered, and that did never work correctly.

Instead of simply calling `setLoading`, test if the component is
rendered, and if not, mask it after it has finished it's layout.

Since we cannot guarantee that there is only one API2Request with the
waitMsgTarget set to it, nor that the 'afterlayout' and api call
responses come in a specific order, we count the loads, and only
ever unmask the component when the counter reaches zero again.

Since we're strictly in non-async code here and JavaScript is
single-threaded, this should not result in a data race.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
src/Utils.js

index ff7c1a75ebfab371a38c9a479cef59e9e21af691..2d4e1ddb8305b64b23fc10a6df4a4dd844c942f5 100644 (file)
@@ -458,6 +458,12 @@ utilities: {
            newopts.url = '/api2/extjs' + newopts.url;
        }
        delete newopts.callback;
+       let unmask = (target) => {
+           if (target.waitMsgTargetCount === undefined || --target.waitMsgTargetCount <= 0) {
+               target.setLoading(false);
+               delete target.waitMsgTargetCount;
+           }
+       };
 
        let createWrapper = function(successFn, callbackFn, failureFn) {
            Ext.apply(newopts, {
@@ -466,7 +472,7 @@ utilities: {
                        if (Proxmox.Utils.toolkit === 'touch') {
                            options.waitMsgTarget.setMasked(false);
                        } else {
-                           options.waitMsgTarget.setLoading(false);
+                           unmask(options.waitMsgTarget);
                        }
                    }
                    let result = Ext.decode(response.responseText);
@@ -488,7 +494,7 @@ utilities: {
                        if (Proxmox.Utils.toolkit === 'touch') {
                            options.waitMsgTarget.setMasked(false);
                        } else {
-                           options.waitMsgTarget.setLoading(false);
+                           unmask(options.waitMsgTarget);
                        }
                    }
                    response.result = {};
@@ -518,9 +524,16 @@ utilities: {
        if (target) {
            if (Proxmox.Utils.toolkit === 'touch') {
                target.setMasked({ xtype: 'loadmask', message: newopts.waitMsg });
-           } else {
-               // Note: ExtJS bug - this does not work when component is not rendered
+           } else if (target.rendered) {
+               target.waitMsgTargetCount = (target.waitMsgTargetCount ?? 0) + 1;
                target.setLoading(newopts.waitMsg);
+           } else {
+               target.waitMsgTargetCount = (target.waitMsgTargetCount ?? 0) + 1;
+               target.on('afterlayout', function() {
+                   if ((target.waitMsgTargetCount ?? 0) > 0) {
+                       target.setLoading(newopts.waitMsg);
+                   }
+               }, target, { single: true });
            }
        }
        Ext.Ajax.request(newopts);