ui: tape: small code/style cleanups

It was not actually bad, so they're quite opinionated to be honest,
but at least xtypes props must go first and variable declaration
should try to be as near as possible to the actual use as long as
code stays sensible readable/short.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2021-05-21 15:18:54 +02:00
parent e830d63f6a
commit 104ae6093a
2 changed files with 19 additions and 27 deletions

View File

@ -13,20 +13,19 @@ Ext.define('PBS.TapeManagement.BackupOverview', {
me.reload(); me.reload();
}, },
}, },
}).show(); autoShow: true,
});
}, },
restore: function(view, rI, cI, item, e, rec) { restoreBackups: function(view, rI, cI, item, e, rec) {
let me = this; let me = this;
let mediaset = rec.data.is_media_set ? rec.data.text : rec.data['media-set']; let mediaset = rec.data.is_media_set ? rec.data.text : rec.data['media-set'];
let uuid = rec.data['media-set-uuid'];
let prefilter = rec.data.prefilter;
Ext.create('PBS.TapeManagement.TapeRestoreWindow', { Ext.create('PBS.TapeManagement.TapeRestoreWindow', {
autoShow: true, autoShow: true,
uuid: rec.data['media-set-uuid'],
prefilter: rec.data.prefilter,
mediaset, mediaset,
uuid,
prefilter,
}); });
}, },
@ -269,7 +268,7 @@ Ext.define('PBS.TapeManagement.BackupOverview', {
xtype: 'actioncolumn', xtype: 'actioncolumn',
items: [ items: [
{ {
handler: 'restore', handler: 'restoreBackups',
tooltip: gettext('Restore'), tooltip: gettext('Restore'),
getClass: (v, m, rec) => rec.data.restore ? 'fa fa-fw fa-undo' : 'pmx-hidden', getClass: (v, m, rec) => rec.data.restore ? 'fa fa-fw fa-undo' : 'pmx-hidden',
isDisabled: (v, r, c, i, rec) => !rec.data.restore, isDisabled: (v, r, c, i, rec) => !rec.data.restore,

View File

@ -34,11 +34,10 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
let tabpanel = me.lookup('tabpanel'); let tabpanel = me.lookup('tabpanel');
let items = tabpanel.items; let items = tabpanel.items;
let checkValidity = true;
let indexOfActiveTab = items.indexOf(tabpanel.getActiveTab()); let indexOfActiveTab = items.indexOf(tabpanel.getActiveTab());
let indexOfLastValidTab = 0; let indexOfLastValidTab = 0;
let checkValidity = true;
items.each((panel) => { items.each((panel) => {
if (checkValidity) { if (checkValidity) {
panel.setDisabled(false); panel.setDisabled(false);
@ -168,8 +167,7 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
setDataStores: function(datastores, initial) { setDataStores: function(datastores, initial) {
let me = this; let me = this;
// save all datastores on the first setting, and // save all datastores on the first setting, and restore them if we selected all
// restore them if we selected all
if (initial) { if (initial) {
me.datastores = datastores; me.datastores = datastores;
} else if (datastores.length === 0) { } else if (datastores.length === 0) {
@ -309,8 +307,7 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
reference: 'snapshotGrid', reference: 'snapshotGrid',
name: 'snapshots', name: 'snapshots',
height: 322, height: 322,
// will be shown/enabled on successful load disabled: true, // will be shown/enabled on successful load
disabled: true,
hidden: true, hidden: true,
listeners: { listeners: {
change: 'updateDatastores', change: 'updateDatastores',
@ -367,9 +364,9 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
column2: [ column2: [
{ {
xtype: 'pbsDriveSelector', xtype: 'pbsDriveSelector',
name: 'drive',
fieldLabel: gettext('Drive'), fieldLabel: gettext('Drive'),
labelWidth: 120, labelWidth: 120,
name: 'drive',
}, },
{ {
xtype: 'pbsDataStoreSelector', xtype: 'pbsDataStoreSelector',
@ -379,9 +376,7 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
name: 'store', name: 'store',
listeners: { listeners: {
change: function(field, value) { change: function(field, value) {
let me = this; this.up('window').lookup('mappingGrid').setNeedStores(!value);
let grid = me.up('window').lookup('mappingGrid');
grid.setNeedStores(!value);
}, },
}, },
}, },
@ -389,16 +384,16 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
columnB: [ columnB: [
{ {
xtype: 'displayfield',
reference: 'mappingLabel',
fieldLabel: gettext('Datastore Mapping'), fieldLabel: gettext('Datastore Mapping'),
labelWidth: 200, labelWidth: 200,
hidden: true, hidden: true,
reference: 'mappingLabel',
xtype: 'displayfield',
}, },
{ {
xtype: 'pbsDataStoreMappingField', xtype: 'pbsDataStoreMappingField',
reference: 'mappingGrid',
name: 'mapping', name: 'mapping',
reference: 'mappingGrid',
height: 260, height: 260,
defaultBindProperty: 'value', defaultBindProperty: 'value',
hidden: true, hidden: true,
@ -424,9 +419,8 @@ Ext.define('PBS.TapeManagement.DataStoreMappingGrid', {
getValue: function() { getValue: function() {
let me = this; let me = this;
let datastores = []; let datastores = [];
me.getStore().each((rec) => { me.getStore().each(rec => {
let source = rec.data.source; let { source, target } = rec.data;
let target = rec.data.target;
if (target && target !== "") { if (target && target !== "") {
datastores.push(`${source}=${target}`); datastores.push(`${source}=${target}`);
} }
@ -463,7 +457,7 @@ Ext.define('PBS.TapeManagement.DataStoreMappingGrid', {
if (me.getViewModel().get('needStores')) { if (me.getViewModel().get('needStores')) {
error = true; error = true;
me.getStore().each((rec) => { me.getStore().each(rec => {
if (rec.data.target) { if (rec.data.target) {
error = false; error = false;
} }
@ -489,9 +483,8 @@ Ext.define('PBS.TapeManagement.DataStoreMappingGrid', {
setDataStores: function(datastores) { setDataStores: function(datastores) {
let me = this; let me = this;
let store = me.getStore();
let data = [];
let data = [];
for (const datastore of datastores) { for (const datastore of datastores) {
data.push({ data.push({
source: datastore, source: datastore,
@ -499,7 +492,7 @@ Ext.define('PBS.TapeManagement.DataStoreMappingGrid', {
}); });
} }
store.setData(data); me.getStore().setData(data);
}, },
viewConfig: { viewConfig: {