ui: tape/ChangerStatus: shortcut 'load-media' for single drive

if a changer only has a single drive, there is no point in showing
a window with a DriveSelector, just do want the user wanted.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2021-04-08 13:39:17 +02:00 committed by Dietmar Maurer
parent 88e1f7997c
commit dff8ea92aa
1 changed files with 52 additions and 30 deletions

View File

@ -163,40 +163,62 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
let label = record.data['label-text']; let label = record.data['label-text'];
let changer = encodeURIComponent(view.changer); let changer = encodeURIComponent(view.changer);
let singleDrive = me.drives.length === 1 ? me.drives[0] : undefined;
Ext.create('Proxmox.window.Edit', { if (singleDrive !== undefined) {
isCreate: true, Proxmox.Utils.API2Request({
autoShow: true, method: 'POST',
submitText: gettext('OK'), params: {
title: gettext('Load Media into Drive'), 'label-text': label,
url: `/api2/extjs/tape/drive`,
method: 'POST',
submitUrl: function(url, values) {
let drive = values.drive;
delete values.drive;
return `${url}/${encodeURIComponent(drive)}/load-media`;
},
items: [
{
xtype: 'displayfield',
name: 'label-text',
value: label,
submitValue: true,
fieldLabel: gettext('Media'),
}, },
{ url: `/api2/extjs/tape/drive/${singleDrive}/load-media`,
xtype: 'pbsDriveSelector', success: function(response, opt) {
fieldLabel: gettext('Drive'), Ext.create('Proxmox.window.TaskProgress', {
changer: changer, upid: response.result.data,
name: 'drive', taskDone: function(success) {
me.reload();
},
}).show();
}, },
], failure: function(response, opt) {
listeners: { Ext.Msg.alert(gettext('Error'), response.htmlStatus);
destroy: function() {
me.reload();
}, },
}, });
}); } else {
Ext.create('Proxmox.window.Edit', {
isCreate: true,
autoShow: true,
submitText: gettext('OK'),
title: gettext('Load Media into Drive'),
url: `/api2/extjs/tape/drive`,
method: 'POST',
submitUrl: function(url, values) {
let drive = values.drive;
delete values.drive;
return `${url}/${encodeURIComponent(drive)}/load-media`;
},
items: [
{
xtype: 'displayfield',
name: 'label-text',
value: label,
submitValue: true,
fieldLabel: gettext('Media'),
},
{
xtype: 'pbsDriveSelector',
fieldLabel: gettext('Drive'),
changer: changer,
name: 'drive',
},
],
listeners: {
destroy: function() {
me.reload();
},
},
});
}
}, },
unload: async function(v, rI, cI, button, el, record) { unload: async function(v, rI, cI, button, el, record) {