Thomas Lamprecht 8f60ee4cca ui: add storage plugin base class
This removes *a lot* of code duplication.

I add a base class for the storage edit window and for its containing
input panel, they implement the shared stuff. Especially the window
was mostly a 1:1 copy...

I look hard for a way to split up this patch, but I did not really
found one which would not generate a lot of work for no value added
(value being 'revertability' and better git history here).
nd actually not too much happens, the same thing happens just over
and over again.
Thus, I've thrown in the dynamic creation of the storage add menu
items here too.

I remove all storage specific Edit windows, they where all just >95%
duplicates of each other.
Special functionallity, i.e. some data deletion/transforming before
submitting gets done with onGetValues.

For the RBD external vs PVE plugin I just added a minimal child class
to RBD which only tells it'S parent that it is the pve one, this is
nice for the mapping and should be easy to understand when reading
the code.

Tried to test an add and an edit of all visible storage plugins,
seems to be OK now.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-03-28 13:19:41 +02:00

106 lines
2.0 KiB
JavaScript

Ext.define('PVE.panel.StorageBase', {
extend: 'Proxmox.panel.InputPanel',
controller: 'storageEdit',
type: '',
onGetValues: function(values) {
var me = this;
if (me.isCreate) {
values.type = me.type;
} else {
delete values.storage;
}
values.disable = values.enable ? 0 : 1;
delete values.enable;
return values;
},
initComponent : function() {
var me = this;
me.column1.unshift({
xtype: me.isCreate ? 'textfield' : 'displayfield',
name: 'storage',
value: me.storageId || '',
fieldLabel: 'ID',
vtype: 'StorageId',
allowBlank: false
});
me.column2.unshift(
{
xtype: 'pveNodeSelector',
name: 'nodes',
disabled: me.storageId === 'local',
fieldLabel: gettext('Nodes'),
emptyText: gettext('All') + ' (' + gettext('No restrictions') +')',
multiSelect: true,
autoSelect: false
},
{
xtype: 'proxmoxcheckbox',
name: 'enable',
checked: true,
uncheckedValue: 0,
fieldLabel: gettext('Enable')
}
);
me.callParent();
}
});
Ext.define('PVE.storage.BaseEdit', {
extend: 'Proxmox.window.Edit',
initComponent : function() {
var me = this;
me.isCreate = !me.storageId;
if (me.isCreate) {
me.url = '/api2/extjs/storage';
me.method = 'POST';
} else {
me.url = '/api2/extjs/storage/' + me.storageId;
me.method = 'PUT';
}
var ipanel = Ext.create(me.paneltype, {
type: me.type,
isCreate: me.isCreate,
storageId: me.storageId
});
Ext.apply(me, {
subject: PVE.Utils.format_storage_type(me.type),
isAdd: true,
items: [ ipanel ]
});
me.callParent();
if (!me.isCreate) {
me.load({
success: function(response, options) {
var values = response.result.data;
var ctypes = values.content || '';
values.content = ctypes.split(',');
if (values.nodes) {
values.nodes = values.nodes.split(',');
}
values.enable = values.disable ? 0 : 1;
ipanel.setValues(values);
}
});
}
}
});