pve-manager/www/manager6/form/FileSelector.js
Dominik Csapak acd0d10a2a add new DiskStorageSelector.js
this is a wrapper for selecting a storage/disk image

it is a simple container with 4 form fields inside
which can be reused, whenever we need to select a storage for a disk,
image etc.

we have code similar to this four times already
(qemu image creation, lxc mp creation, qemu cloning, qemu efidisk
creation)

so it was time to refactor this and use the storage information from the
backend instead of hardcoding values in the frontend

for this we need to pass the format=1 parameter to the storage api call,
and to not load the fileselector when it is initially disabled

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2017-11-14 13:27:03 +01:00

84 lines
1.5 KiB
JavaScript

Ext.define('PVE.form.FileSelector', {
extend: 'PVE.form.ComboGrid',
alias: 'widget.pveFileSelector',
editable: true,
anyMatch: true,
forceSelection: true,
setStorage: function(storage, nodename) {
var me = this;
var change = false;
if (storage && (me.storage !== storage)) {
me.storage = storage;
change = true;
}
if (nodename && (me.nodename !== nodename)) {
me.nodename = nodename;
change = true;
}
if (!(me.storage && me.nodename && change)) {
return;
}
var url = '/api2/json/nodes/' + me.nodename + '/storage/' + me.storage + '/content';
if (me.storageContent) {
url += '?content=' + me.storageContent;
}
me.store.setProxy({
type: 'pve',
url: url
});
me.store.load();
},
initComponent: function() {
var me = this;
var store = Ext.create('Ext.data.Store', {
model: 'pve-storage-content'
});
Ext.apply(me, {
store: store,
allowBlank: false,
autoSelect: false,
valueField: 'volid',
displayField: 'text',
listConfig: {
width: 600,
columns: [
{
header: gettext('Name'),
dataIndex: 'text',
hideable: false,
flex: 1
},
{
header: gettext('Format'),
width: 60,
dataIndex: 'format'
},
{
header: gettext('Size'),
width: 100,
dataIndex: 'size',
renderer: PVE.Utils.format_size
}
]
}
});
me.callParent();
if (!me.disabled) {
me.setStorage(me.storage, me.nodename);
}
}
});