tape: restore: cope with not fully instantiated components

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2021-05-21 15:24:52 +02:00
parent 104ae6093a
commit 5128ae48a0
1 changed files with 32 additions and 22 deletions

View File

@ -22,6 +22,17 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
layout: 'fit', layout: 'fit',
bodyPadding: 0, bodyPadding: 0,
viewModel: {
data: {
singleDatastore: true,
},
formulas: {
singleSelectorLabel: get =>
get('singleDatastore') ? gettext('Target Datastore') : gettext('Default Datastore'),
singleSelectorEmptyText: get => get('singleDatastore') ? '' : Proxmox.Utils.NoneText,
},
},
controller: { controller: {
xclass: 'Ext.app.ViewController', xclass: 'Ext.app.ViewController',
@ -31,7 +42,11 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
checkValidity: function() { checkValidity: function() {
let me = this; let me = this;
let tabpanel = me.lookup('tabpanel'); let tabpanel = me.lookup('tabpanel');
if (!tabpanel) {
return; // can get triggered early, when the tabpanel is not yet available
}
let items = tabpanel.items; let items = tabpanel.items;
let indexOfActiveTab = items.indexOf(tabpanel.getActiveTab()); let indexOfActiveTab = items.indexOf(tabpanel.getActiveTab());
@ -174,26 +189,13 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
datastores = me.datastores; datastores = me.datastores;
} }
let label = me.lookup('mappingLabel'); const singleDatastore = !datastores || datastores.length <= 1;
me.getViewModel().set('singleDatastore', singleDatastore);
let grid = me.lookup('mappingGrid'); let grid = me.lookup('mappingGrid');
let defaultField = me.lookup('defaultDatastore'); if (!singleDatastore && grid) {
grid.setDataStores(datastores);
if (!datastores || datastores.length <= 1) {
label.setVisible(false);
grid.setVisible(false);
defaultField.setFieldLabel(gettext('Target Datastore'));
defaultField.setAllowBlank(false);
defaultField.setEmptyText("");
return;
} }
label.setVisible(true);
defaultField.setFieldLabel(gettext('Default Datastore'));
defaultField.setAllowBlank(true);
defaultField.setEmptyText(Proxmox.Utils.NoneText);
grid.setDataStores(datastores);
grid.setVisible(true);
}, },
updateSnapshots: function() { updateSnapshots: function() {
@ -370,10 +372,14 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
}, },
{ {
xtype: 'pbsDataStoreSelector', xtype: 'pbsDataStoreSelector',
fieldLabel: gettext('Target Datastore'), name: 'store',
labelWidth: 120, labelWidth: 120,
reference: 'defaultDatastore', reference: 'defaultDatastore',
name: 'store', bind: {
fieldLabel: '{singleSelectorLabel}',
emptyText: '{singleSelectorEmptyText}',
allowBlank: '{!singleDatastore}',
},
listeners: { listeners: {
change: function(field, value) { change: function(field, value) {
this.up('window').lookup('mappingGrid').setNeedStores(!value); this.up('window').lookup('mappingGrid').setNeedStores(!value);
@ -388,7 +394,9 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
reference: 'mappingLabel', reference: 'mappingLabel',
fieldLabel: gettext('Datastore Mapping'), fieldLabel: gettext('Datastore Mapping'),
labelWidth: 200, labelWidth: 200,
hidden: true, bind: {
hidden: '{singleDatastore}',
},
}, },
{ {
xtype: 'pbsDataStoreMappingField', xtype: 'pbsDataStoreMappingField',
@ -396,7 +404,9 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
reference: 'mappingGrid', reference: 'mappingGrid',
height: 260, height: 260,
defaultBindProperty: 'value', defaultBindProperty: 'value',
hidden: true, bind: {
hidden: '{singleDatastore}',
},
}, },
], ],
}, },