]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
FileBrowser: show errors in messagebox and allow expand 'all'
authorStefan Reiter <s.reiter@proxmox.com>
Thu, 22 Apr 2021 15:34:57 +0000 (17:34 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 22 Apr 2021 15:52:52 +0000 (17:52 +0200)
If an error is received upon expanding a node, chances are the rest of
the tree is still valid (i.e. opening a partition fails because it
doesn't contain a supported filesystem). Only show an error box for the
user, but don't mask the component in that case. Additionally, disable
the download button.

Also support an archive set to 'all' to expand all children, useful for
initializing a file-restore VM on initial load.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
src/window/FileBrowser.js

index d138d1be9fd555e882faa7f126946ea6d4303626..99a7a854fee90fb983473d4861d9c4f27c577617 100644 (file)
@@ -123,6 +123,16 @@ Ext.define("Proxmox.window.FileBrowser", {
            me.lookup('downloadBtn').setDisabled(!canDownload);
        },
 
+       errorHandler: function(error, msg) {
+           let me = this;
+           me.lookup('downloadBtn').setDisabled(true);
+           if (me.initialLoadDone) {
+               Ext.Msg.alert(gettext('Error'), msg);
+               return true;
+           }
+           return false;
+       },
+
        init: function(view) {
            let me = this;
            let tree = me.lookup('tree');
@@ -134,13 +144,16 @@ Ext.define("Proxmox.window.FileBrowser", {
            let store = tree.getStore();
            let proxy = store.getProxy();
 
-           Proxmox.Utils.monStoreErrors(tree, store, true);
+           let errorCallback = (error, msg) => me.errorHandler(error, msg);
+           Proxmox.Utils.monStoreErrors(tree, store, true, errorCallback);
            proxy.setUrl(view.listURL);
            proxy.setExtraParams(view.extraParams);
-           store.load(() => {
+           store.load((rec, op, success) => {
                let root = store.getRoot();
                root.expand(); // always expand invisible root node
-               if (view.archive) {
+               if (view.archive === 'all') {
+                   root.expandChildren(false);
+               } else if (view.archive) {
                    let child = root.findChild('text', view.archive);
                    if (child) {
                        child.expand();
@@ -152,6 +165,7 @@ Ext.define("Proxmox.window.FileBrowser", {
                } else if (root.childNodes.length === 1) {
                    root.firstChild.expand();
                }
+               me.initialLoadDone = success;
            });
        },