[pve-devel] [PATCH manager 3/3] ui: add storage plugin base class
Thomas Lamprecht
t.lamprecht at proxmox.com
Mon Mar 26 08:18:24 CEST 2018
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.
The only "problematic" things is that I used ECMAScript6 feature, an
arrow function for an higher order function generator in the
addMenuItems assembly. jshint does not likes that at all...
But honestyl I'd look for a more capable (h/l)inter and go for the
cool ES6 features than vice versa :)
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
www/manager6/Makefile | 1 +
www/manager6/dc/StorageView.js | 192 +++++++---------------------------
www/manager6/storage/Base.js | 105 +++++++++++++++++++
www/manager6/storage/CIFSEdit.js | 89 +---------------
www/manager6/storage/DirEdit.js | 94 +----------------
www/manager6/storage/GlusterFsEdit.js | 90 +---------------
www/manager6/storage/IScsiEdit.js | 92 ++--------------
www/manager6/storage/LVMEdit.js | 93 +---------------
www/manager6/storage/LvmThinEdit.js | 96 +----------------
www/manager6/storage/NFSEdit.js | 82 +--------------
www/manager6/storage/RBDEdit.js | 99 ++----------------
www/manager6/storage/SheepdogEdit.js | 87 +--------------
www/manager6/storage/ZFSEdit.js | 87 ++-------------
www/manager6/storage/ZFSPoolEdit.js | 95 +----------------
14 files changed, 179 insertions(+), 1123 deletions(-)
create mode 100644 www/manager6/storage/Base.js
diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index ac9f6481..a01880f7 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -148,6 +148,7 @@ JSSRC= \
pool/StatusView.js \
pool/Summary.js \
pool/Config.js \
+ storage/Base.js \
storage/ContentView.js \
storage/StatusView.js \
storage/Summary.js \
diff --git a/www/manager6/dc/StorageView.js b/www/manager6/dc/StorageView.js
index ba6faafb..5ca6476e 100644
--- a/www/manager6/dc/StorageView.js
+++ b/www/manager6/dc/StorageView.js
@@ -1,4 +1,3 @@
-
Ext.define('PVE.dc.StorageView', {
extend: 'Ext.grid.GridPanel',
@@ -9,6 +8,23 @@ Ext.define('PVE.dc.StorageView', {
stateful: true,
stateId: 'grid-dc-storage',
+ createStorageEditWindow: function(type, sid) {
+ var schema = PVE.Utils.storageSchema[type];
+ if (!schema || !schema.ipanel) {
+ throw "no editor registered for storage type: " + type;
+ }
+
+ Ext.create('PVE.storage.BaseEdit', {
+ paneltype: 'PVE.storage.' + schema.ipanel,
+ type: type,
+ storageId: sid,
+ autoShow: true,
+ listeners: {
+ destroy: this.reloadStore
+ }
+ });
+ },
+
initComponent : function() {
var me = this;
@@ -35,41 +51,14 @@ Ext.define('PVE.dc.StorageView', {
if (!rec) {
return;
}
- var type = rec.data.type;
+ var type = rec.data.type,
+ sid = rec.data.storage;
- var editor;
- if (type === 'dir') {
- editor = 'PVE.storage.DirEdit';
- } else if (type === 'nfs') {
- editor = 'PVE.storage.NFSEdit';
- } else if (type === 'cifs') {
- editor = 'PVE.storage.CIFSEdit';
- } else if (type === 'glusterfs') {
- editor = 'PVE.storage.GlusterFsEdit';
- } else if (type === 'lvm') {
- editor = 'PVE.storage.LVMEdit';
- } else if (type === 'lvmthin') {
- editor = 'PVE.storage.LvmThinEdit';
- } else if (type === 'iscsi') {
- editor = 'PVE.storage.IScsiEdit';
- } else if (type === 'rbd') {
- editor = 'PVE.storage.RBDEdit';
- } else if (type === 'sheepdog') {
- editor = 'PVE.storage.SheepdogEdit';
- } else if (type === 'zfs') {
- editor = 'PVE.storage.ZFSEdit';
- } else if (type === 'zfspool') {
- editor = 'PVE.storage.ZFSPoolEdit';
- } else {
- return;
+ if (type === 'rbd' && !rec.data.monhost) {
+ type = 'pveceph';
}
- var win = Ext.create(editor, {
- storageId: rec.data.storage,
- pveceph: !rec.data.monhost
- });
- win.show();
- win.on('destroy', reload);
+ me.createStorageEditWindow(type, sid);
};
var edit_btn = new Proxmox.button.Button({
@@ -82,13 +71,26 @@ Ext.define('PVE.dc.StorageView', {
var remove_btn = Ext.create('Proxmox.button.StdRemoveButton', {
selModel: sm,
baseurl: '/storage/',
- callback: function() {
- reload();
- }
+ callback: reload
});
+ var addHandleGenerator = type => function() { me.createStorageEditWindow(type); }
+ var addMenuItems = [];
+ for (var type in PVE.Utils.storageSchema) {
+ var storage = PVE.Utils.storageSchema[type];
+ if (storage.hideAdd) {
+ continue;
+ }
+ addMenuItems.push({
+ text: PVE.Utils.format_storage_type(type),
+ iconCls: 'fa fa-fw fa-' + storage.faIcon,
+ handler: addHandleGenerator(type)
+ });
+ }
+
Ext.apply(me, {
store: store,
+ reloadStore: reload,
selModel: sm,
viewConfig: {
trackOver: false
@@ -97,123 +99,7 @@ Ext.define('PVE.dc.StorageView', {
{
text: gettext('Add'),
menu: new Ext.menu.Menu({
- items: [
- {
- text: PVE.Utils.format_storage_type('dir'),
- iconCls: 'fa fa-fw fa-folder',
- handler: function() {
- var win = Ext.create('PVE.storage.DirEdit', {});
- win.on('destroy', reload);
- win.show();
- }
-
- },
- {
- text: PVE.Utils.format_storage_type('lvm'),
- iconCls: 'fa fa-fw fa-folder',
- handler: function() {
- var win = Ext.create('PVE.storage.LVMEdit', {});
- win.on('destroy', reload);
- win.show();
- }
- },
- {
- text: PVE.Utils.format_storage_type('lvmthin'),
- iconCls: 'fa fa-fw fa-folder',
- handler: function() {
- var win = Ext.create('PVE.storage.LvmThinEdit', {});
- win.on('destroy', reload);
- win.show();
- }
- },
- {
- text: PVE.Utils.format_storage_type('nfs'),
- iconCls: 'fa fa-fw fa-building',
- handler: function() {
- var win = Ext.create('PVE.storage.NFSEdit', {});
- win.on('destroy', reload);
- win.show();
- }
- },
- {
- text: PVE.Utils.format_storage_type('cifs'),
- iconCls: 'fa fa-fw fa-building',
- handler: function() {
- var win = Ext.create('PVE.storage.CIFSEdit', {});
- win.on('destroy', reload);
- win.show();
- }
- },
- {
- text: PVE.Utils.format_storage_type('iscsi'),
- iconCls: 'fa fa-fw fa-building',
- handler: function() {
- var win = Ext.create('PVE.storage.IScsiEdit', {});
- win.on('destroy', reload);
- win.show();
- }
- },
- {
- text: PVE.Utils.format_storage_type('glusterfs'),
- iconCls: 'fa fa-fw fa-building',
- handler: function() {
- var win = Ext.create('PVE.storage.GlusterFsEdit', {});
- win.on('destroy', reload);
- win.show();
- }
- },
- {
- text: PVE.Utils.format_storage_type('pveceph'),
- iconCls: 'fa fa-fw fa-building',
- handler: function() {
- var win = Ext.create('PVE.storage.RBDEdit', {
- pveceph: 1
- });
- win.on('destroy', reload);
- win.show();
- }
- },
- {
- text: PVE.Utils.format_storage_type('rbd_ext'),
- iconCls: 'fa fa-fw fa-building',
- handler: function() {
- var win = Ext.create('PVE.storage.RBDEdit', {});
- win.on('destroy', reload);
- win.show();
- }
- },
- {
- text: PVE.Utils.format_storage_type('zfs'),
- iconCls: 'fa fa-fw fa-building',
- handler: function() {
- var win = Ext.create('PVE.storage.ZFSEdit', {});
- win.on('destroy', reload);
- win.show();
- }
- },
- {
- text: PVE.Utils.format_storage_type('zfspool'),
- iconCls: 'fa fa-fw fa-folder',
- handler: function() {
- var win = Ext.create('PVE.storage.ZFSPoolEdit', {});
- win.on('destroy', reload);
- win.show();
- }
- }
-
-/* the following type are conidered unstable
- * so we do not enable that on the GUI for now
- {
- text: PVE.Utils.format_storage_type('sheepdog'),
- iconCls: 'fa fa-fw fa-building',
- handler: function() {
- var win = Ext.create('PVE.storage.SheepdogEdit', {});
- win.on('destroy', reload);
- win.show();
- }
- }
-*/
- ]
+ items: addMenuItems
})
},
remove_btn,
diff --git a/www/manager6/storage/Base.js b/www/manager6/storage/Base.js
new file mode 100644
index 00000000..71d7b5bb
--- /dev/null
+++ b/www/manager6/storage/Base.js
@@ -0,0 +1,105 @@
+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);
+ }
+ });
+ }
+ }
+});
diff --git a/www/manager6/storage/CIFSEdit.js b/www/manager6/storage/CIFSEdit.js
index 83f5c664..f75745b4 100644
--- a/www/manager6/storage/CIFSEdit.js
+++ b/www/manager6/storage/CIFSEdit.js
@@ -86,24 +86,9 @@ Ext.define('PVE.storage.CIFSScan', {
});
Ext.define('PVE.storage.CIFSInputPanel', {
- extend: 'Proxmox.panel.InputPanel',
+ extend: 'PVE.panel.StorageBase',
controller: 'storageEdit',
- onGetValues: function(values) {
- var me = this;
-
- if (me.isCreate) {
- values.type = 'cifs';
- } else {
- delete values.storage;
- }
-
- values.disable = values.enable ? 0 : 1;
- delete values.enable;
-
- return values;
- },
-
initComponent : function() {
var me = this;
@@ -126,14 +111,6 @@ Ext.define('PVE.storage.CIFSInputPanel', {
});
me.column1 = [
- {
- xtype: me.isCreate ? 'textfield' : 'displayfield',
- name: 'storage',
- value: me.storageId || '',
- fieldLabel: 'ID',
- vtype: 'StorageId',
- allowBlank: false
- },
{
xtype: me.isCreate ? 'textfield' : 'displayfield',
name: 'server',
@@ -189,22 +166,6 @@ Ext.define('PVE.storage.CIFSInputPanel', {
];
me.column2 = [
- {
- xtype: 'pveNodeSelector',
- name: 'nodes',
- fieldLabel: gettext('Nodes'),
- emptyText: gettext('All') + ' (' +
- gettext('No restrictions') +')',
- multiSelect: true,
- autoSelect: false
- },
- {
- xtype: 'proxmoxcheckbox',
- name: 'enable',
- checked: true,
- uncheckedValue: 0,
- fieldLabel: gettext('Enable')
- },
{
xtype: 'proxmoxintegerfield',
fieldLabel: gettext('Max Backups'),
@@ -237,51 +198,3 @@ Ext.define('PVE.storage.CIFSInputPanel', {
me.callParent();
}
});
-
-Ext.define('PVE.storage.CIFSEdit', {
- 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('PVE.storage.CIFSInputPanel', {
- isCreate: me.isCreate,
- storageId: me.storageId
- });
-
- Ext.apply(me, {
- subject: 'CIFS',
- 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);
- }
- });
- }
- }
-});
diff --git a/www/manager6/storage/DirEdit.js b/www/manager6/storage/DirEdit.js
index f17a3689..fd02f13f 100644
--- a/www/manager6/storage/DirEdit.js
+++ b/www/manager6/storage/DirEdit.js
@@ -1,35 +1,11 @@
Ext.define('PVE.storage.DirInputPanel', {
- extend: 'Proxmox.panel.InputPanel',
+ extend: 'PVE.panel.StorageBase',
controller: 'storageEdit',
- onGetValues: function(values) {
- var me = this;
-
- if (me.isCreate) {
- values.type = 'dir';
- } else {
- delete values.storage;
- }
-
- values.disable = values.enable ? 0 : 1;
- delete values.enable;
-
- return values;
- },
-
initComponent : function() {
var me = this;
-
me.column1 = [
- {
- xtype: me.isCreate ? 'textfield' : 'displayfield',
- name: 'storage',
- value: me.storageId || '',
- fieldLabel: 'ID',
- vtype: 'StorageId',
- allowBlank: false
- },
{
xtype: me.isCreate ? 'textfield' : 'displayfield',
name: 'path',
@@ -48,13 +24,6 @@ Ext.define('PVE.storage.DirInputPanel', {
];
me.column2 = [
- {
- xtype: 'proxmoxcheckbox',
- name: 'enable',
- checked: true,
- uncheckedValue: 0,
- fieldLabel: gettext('Enable')
- },
{
xtype: 'proxmoxcheckbox',
name: 'shared',
@@ -74,67 +43,6 @@ Ext.define('PVE.storage.DirInputPanel', {
}
];
- if (me.isCreate || me.storageId !== 'local') {
- me.column2.unshift({
- xtype: 'pveNodeSelector',
- name: 'nodes',
- fieldLabel: gettext('Nodes'),
- emptyText: gettext('All') + ' (' +
- gettext('No restrictions') +')',
- multiSelect: true,
- autoSelect: false
- });
- }
-
me.callParent();
}
});
-
-Ext.define('PVE.storage.DirEdit', {
- 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('PVE.storage.DirInputPanel', {
- isCreate: me.isCreate,
- storageId: me.storageId
- });
-
- Ext.apply(me, {
- subject: PVE.Utils.format_storage_type('dir'),
- 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);
- }
- });
- }
- }
-});
diff --git a/www/manager6/storage/GlusterFsEdit.js b/www/manager6/storage/GlusterFsEdit.js
index 11ff3223..f02bc6e8 100644
--- a/www/manager6/storage/GlusterFsEdit.js
+++ b/www/manager6/storage/GlusterFsEdit.js
@@ -58,37 +58,13 @@ Ext.define('PVE.storage.GlusterFsScan', {
});
Ext.define('PVE.storage.GlusterFsInputPanel', {
- extend: 'Proxmox.panel.InputPanel',
+ extend: 'PVE.panel.StorageBase',
controller: 'storageEdit',
- onGetValues: function(values) {
- var me = this;
-
- if (me.isCreate) {
- values.type = 'glusterfs';
- } else {
- delete values.storage;
- }
-
- values.disable = values.enable ? 0 : 1;
- delete values.enable;
-
- return values;
- },
-
initComponent : function() {
var me = this;
-
me.column1 = [
- {
- xtype: me.isCreate ? 'textfield' : 'displayfield',
- name: 'storage',
- value: me.storageId || '',
- fieldLabel: 'ID',
- vtype: 'StorageId',
- allowBlank: false
- },
{
xtype: me.isCreate ? 'textfield' : 'displayfield',
name: 'server',
@@ -131,22 +107,6 @@ Ext.define('PVE.storage.GlusterFsInputPanel', {
];
me.column2 = [
- {
- xtype: 'pveNodeSelector',
- name: 'nodes',
- fieldLabel: gettext('Nodes'),
- emptyText: gettext('All') + ' (' +
- gettext('No restrictions') +')',
- multiSelect: true,
- autoSelect: false
- },
- {
- xtype: 'proxmoxcheckbox',
- name: 'enable',
- checked: true,
- uncheckedValue: 0,
- fieldLabel: gettext('Enable')
- },
{
xtype: 'proxmoxintegerfield',
fieldLabel: gettext('Max Backups'),
@@ -163,51 +123,3 @@ Ext.define('PVE.storage.GlusterFsInputPanel', {
me.callParent();
}
});
-
-Ext.define('PVE.storage.GlusterFsEdit', {
- 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('PVE.storage.GlusterFsInputPanel', {
- isCreate: me.isCreate,
- storageId: me.storageId
- });
-
- Ext.apply(me, {
- subject: PVE.Utils.format_storage_type('glusterfs'),
- 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);
- }
- });
- }
- }
-});
diff --git a/www/manager6/storage/IScsiEdit.js b/www/manager6/storage/IScsiEdit.js
index b673bc3a..c7e8ecaf 100644
--- a/www/manager6/storage/IScsiEdit.js
+++ b/www/manager6/storage/IScsiEdit.js
@@ -57,39 +57,26 @@ Ext.define('PVE.storage.IScsiScan', {
});
Ext.define('PVE.storage.IScsiInputPanel', {
- extend: 'Proxmox.panel.InputPanel',
+ extend: 'PVE.panel.StorageBase',
onGetValues: function(values) {
var me = this;
- if (me.isCreate) {
- values.type = 'iscsi';
- } else {
- delete values.storage;
- }
-
values.content = values.luns ? 'images' : 'none';
delete values.luns;
- values.disable = values.enable ? 0 : 1;
- delete values.enable;
+ me.callParent([values]);
+ },
- return values;
+ setValues: function(values) {
+ values.luns = (values.content === 'images') ? true : false;
+ this.callParent();
},
initComponent : function() {
var me = this;
-
me.column1 = [
- {
- xtype: me.isCreate ? 'textfield' : 'displayfield',
- name: 'storage',
- value: me.storageId || '',
- fieldLabel: 'ID',
- vtype: 'StorageId',
- allowBlank: false
- },
{
xtype: me.isCreate ? 'textfield' : 'displayfield',
name: 'portal',
@@ -117,22 +104,6 @@ Ext.define('PVE.storage.IScsiInputPanel', {
];
me.column2 = [
- {
- xtype: 'pveNodeSelector',
- name: 'nodes',
- fieldLabel: gettext('Nodes'),
- emptyText: gettext('All') + ' (' +
- gettext('No restrictions') +')',
- multiSelect: true,
- autoSelect: false
- },
- {
- xtype: 'proxmoxcheckbox',
- name: 'enable',
- checked: true,
- uncheckedValue: 0,
- fieldLabel: gettext('Enable')
- },
{
xtype: 'checkbox',
name: 'luns',
@@ -144,54 +115,3 @@ Ext.define('PVE.storage.IScsiInputPanel', {
me.callParent();
}
});
-
-Ext.define('PVE.storage.IScsiEdit', {
- 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('PVE.storage.IScsiInputPanel', {
- isCreate: me.isCreate,
- storageId: me.storageId
- });
-
- Ext.apply(me, {
- subject: PVE.Utils.format_storage_type('iscsi'),
- isAdd: true,
- items: [ ipanel ]
- });
-
- me.callParent();
-
- if (!me.isCreate) {
- me.load({
- success: function(response, options) {
- var values = response.result.data;
- var ctypes = values.content || '';
-
- if (values.storage === 'local') {
- values.content = ctypes.split(',');
- }
- if (values.nodes) {
- values.nodes = values.nodes.split(',');
- }
- values.enable = values.disable ? 0 : 1;
- values.luns = (values.content === 'images') ? true : false;
-
- ipanel.setValues(values);
- }
- });
- }
- }
-});
diff --git a/www/manager6/storage/LVMEdit.js b/www/manager6/storage/LVMEdit.js
index b822d226..af79c527 100644
--- a/www/manager6/storage/LVMEdit.js
+++ b/www/manager6/storage/LVMEdit.js
@@ -84,37 +84,12 @@ Ext.define('PVE.storage.BaseStorageSelector', {
});
Ext.define('PVE.storage.LVMInputPanel', {
- extend: 'Proxmox.panel.InputPanel',
-
- onGetValues: function(values) {
- var me = this;
-
- if (me.isCreate) {
- values.type = 'lvm';
- } else {
- delete values.storage;
- }
-
- values.disable = values.enable ? 0 : 1;
- delete values.enable;
-
- return values;
- },
+ extend: 'PVE.panel.StorageBase',
initComponent : function() {
var me = this;
- me.column1 = [
- {
- xtype: me.isCreate ? 'textfield' : 'displayfield',
- name: 'storage',
- value: me.storageId || '',
- fieldLabel: 'ID',
- vtype: 'StorageId',
- submitValue: !!me.isCreate,
- allowBlank: false
- }
- ];
+ me.column1 = [];
var vgnameField = Ext.createWidget(me.isCreate ? 'textfield' : 'displayfield', {
name: 'vgname',
@@ -191,22 +166,6 @@ Ext.define('PVE.storage.LVMInputPanel', {
/*jslint confusion: false*/
me.column2 = [
- {
- xtype: 'pveNodeSelector',
- name: 'nodes',
- fieldLabel: gettext('Nodes'),
- emptyText: gettext('All') + ' (' +
- gettext('No restrictions') +')',
- multiSelect: true,
- autoSelect: false
- },
- {
- xtype: 'proxmoxcheckbox',
- name: 'enable',
- checked: true,
- uncheckedValue: 0,
- fieldLabel: gettext('Enable')
- },
{
xtype: 'proxmoxcheckbox',
name: 'shared',
@@ -218,51 +177,3 @@ Ext.define('PVE.storage.LVMInputPanel', {
me.callParent();
}
});
-
-Ext.define('PVE.storage.LVMEdit', {
- 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('PVE.storage.LVMInputPanel', {
- isCreate: me.isCreate,
- storageId: me.storageId
- });
-
- Ext.apply(me, {
- subject: PVE.Utils.format_storage_type('lvm'),
- 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);
- }
- });
- }
- }
-});
diff --git a/www/manager6/storage/LvmThinEdit.js b/www/manager6/storage/LvmThinEdit.js
index bb9a4f1e..6ec51ed8 100644
--- a/www/manager6/storage/LvmThinEdit.js
+++ b/www/manager6/storage/LvmThinEdit.js
@@ -92,37 +92,12 @@ Ext.define('PVE.storage.BaseVGSelector', {
});
Ext.define('PVE.storage.LvmThinInputPanel', {
- extend: 'Proxmox.panel.InputPanel',
-
- onGetValues: function(values) {
- var me = this;
-
- if (me.isCreate) {
- values.type = 'lvmthin';
- } else {
- delete values.storage;
- }
-
- values.disable = values.enable ? 0 : 1;
- delete values.enable;
-
- return values;
- },
+ extend: 'PVE.panel.StorageBase',
initComponent : function() {
var me = this;
- me.column1 = [
- {
- xtype: me.isCreate ? 'textfield' : 'displayfield',
- name: 'storage',
- value: me.storageId || '',
- fieldLabel: 'ID',
- vtype: 'StorageId',
- submitValue: !!me.isCreate,
- allowBlank: false
- }
- ];
+ me.column1 = [];
var vgnameField = Ext.createWidget(me.isCreate ? 'textfield' : 'displayfield', {
name: 'vgname',
@@ -184,73 +159,8 @@ Ext.define('PVE.storage.LvmThinInputPanel', {
});
/*jslint confusion: false*/
- me.column2 = [
- {
- xtype: 'pveNodeSelector',
- name: 'nodes',
- 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.column2 = [];
me.callParent();
}
});
-
-Ext.define('PVE.storage.LvmThinEdit', {
- 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('PVE.storage.LvmThinInputPanel', {
- isCreate: me.isCreate,
- storageId: me.storageId
- });
-
- Ext.apply(me, {
- subject: PVE.Utils.format_storage_type('lvmthin'),
- 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);
- }
- });
- }
- }
-});
diff --git a/www/manager6/storage/NFSEdit.js b/www/manager6/storage/NFSEdit.js
index b230ec34..bbcaf1cc 100644
--- a/www/manager6/storage/NFSEdit.js
+++ b/www/manager6/storage/NFSEdit.js
@@ -58,25 +58,19 @@ Ext.define('PVE.storage.NFSScan', {
});
Ext.define('PVE.storage.NFSInputPanel', {
- extend: 'Proxmox.panel.InputPanel',
+ extend: 'PVE.panel.StorageBase',
controller: 'storageEdit',
onGetValues: function(values) {
var me = this;
if (me.isCreate) {
- values.type = 'nfs';
// hack: for now we always create nvf v3
// fixme: make this configurable
values.options = 'vers=3';
- } else {
- delete values.storage;
}
- values.disable = values.enable ? 0 : 1;
- delete values.enable;
-
- return values;
+ return me.callParent([values]);
},
initComponent : function() {
@@ -84,14 +78,6 @@ Ext.define('PVE.storage.NFSInputPanel', {
me.column1 = [
- {
- xtype: me.isCreate ? 'textfield' : 'displayfield',
- name: 'storage',
- value: me.storageId || '',
- fieldLabel: 'ID',
- vtype: 'StorageId',
- allowBlank: false
- },
{
xtype: me.isCreate ? 'textfield' : 'displayfield',
name: 'server',
@@ -126,22 +112,6 @@ Ext.define('PVE.storage.NFSInputPanel', {
];
me.column2 = [
- {
- xtype: 'pveNodeSelector',
- name: 'nodes',
- fieldLabel: gettext('Nodes'),
- emptyText: gettext('All') + ' (' +
- gettext('No restrictions') +')',
- multiSelect: true,
- autoSelect: false
- },
- {
- xtype: 'proxmoxcheckbox',
- name: 'enable',
- checked: true,
- uncheckedValue: 0,
- fieldLabel: gettext('Enable')
- },
{
xtype: 'proxmoxintegerfield',
fieldLabel: gettext('Max Backups'),
@@ -158,51 +128,3 @@ Ext.define('PVE.storage.NFSInputPanel', {
me.callParent();
}
});
-
-Ext.define('PVE.storage.NFSEdit', {
- 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('PVE.storage.NFSInputPanel', {
- isCreate: me.isCreate,
- storageId: me.storageId
- });
-
- Ext.apply(me, {
- subject: 'NFS',
- 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);
- }
- });
- }
- }
-});
diff --git a/www/manager6/storage/RBDEdit.js b/www/manager6/storage/RBDEdit.js
index 1e46f9ee..d26a6ac3 100644
--- a/www/manager6/storage/RBDEdit.js
+++ b/www/manager6/storage/RBDEdit.js
@@ -1,20 +1,5 @@
Ext.define('PVE.storage.RBDInputPanel', {
- extend: 'Proxmox.panel.InputPanel',
-
- onGetValues: function(values) {
- var me = this;
-
- if (me.isCreate) {
- values.type = 'rbd';
- } else {
- delete values.storage;
- }
-
- values.disable = values.enable ? 0 : 1;
- delete values.enable;
-
- return values;
- },
+ extend: 'PVE.panel.StorageBase',
initComponent : function() {
var me = this;
@@ -22,17 +7,9 @@ Ext.define('PVE.storage.RBDInputPanel', {
if (!me.nodename) {
me.nodename = 'localhost';
}
+ me.type = 'rbd';
- me.column1 = [
- {
- xtype: me.isCreate ? 'textfield' : 'displayfield',
- name: 'storage',
- value: me.storageId || '',
- fieldLabel: 'ID',
- vtype: 'StorageId',
- allowBlank: false
- }
- ];
+ me.column1 = [];
if (me.pveceph) {
me.column1.push(
@@ -75,13 +52,6 @@ Ext.define('PVE.storage.RBDInputPanel', {
// while before it was a string
/*jslint confusion: true*/
me.column2 = [
- {
- xtype: 'proxmoxcheckbox',
- name: 'enable',
- checked: true,
- uncheckedValue: 0,
- fieldLabel: gettext('Enable')
- },
{
xtype: 'pveContentTypeSelector',
cts: ['images', 'rootdir'],
@@ -100,69 +70,12 @@ Ext.define('PVE.storage.RBDInputPanel', {
];
/*jslint confusion: false*/
- if (me.isCreate) {
- me.column2.unshift({
- xtype: 'pveNodeSelector',
- name: 'nodes',
- fieldLabel: gettext('Nodes'),
- emptyText: gettext('All') + ' (' +
- gettext('No restrictions') +')',
- multiSelect: true,
- autoSelect: false
- });
- }
-
me.callParent();
}
});
-Ext.define('PVE.storage.RBDEdit', {
- 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('PVE.storage.RBDInputPanel', {
- isCreate: me.isCreate,
- storageId: me.storageId,
- nodename: me.nodename,
- pveceph: me.pveceph
- });
-
- Ext.apply(me, {
- subject: PVE.Utils.format_storage_type(me.pveceph?'pveceph':'rbd'),
- isAdd: true,
- items: [ ipanel ]
- });
+Ext.define('PVE.storage.PVERBDInputPanel', {
+ extend: 'PVE.storage.RBDInputPanel',
- 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);
- }
- });
- }
- }
+ pveceph: 1
});
diff --git a/www/manager6/storage/SheepdogEdit.js b/www/manager6/storage/SheepdogEdit.js
index 90d87337..aae837d8 100644
--- a/www/manager6/storage/SheepdogEdit.js
+++ b/www/manager6/storage/SheepdogEdit.js
@@ -1,36 +1,20 @@
Ext.define('PVE.storage.SheepdogInputPanel', {
- extend: 'Proxmox.panel.InputPanel',
+ extend: 'PVE.panel.StorageBase',
onGetValues: function(values) {
var me = this;
if (me.isCreate) {
- values.type = 'sheepdog';
values.content = 'images';
-
- } else {
- delete values.storage;
}
- values.disable = values.enable ? 0 : 1;
- delete values.enable;
-
- return values;
+ return me.callParent([values]);
},
initComponent : function() {
var me = this;
-
me.column1 = [
- {
- xtype: me.isCreate ? 'textfield' : 'displayfield',
- name: 'storage',
- value: me.storageId || '',
- fieldLabel: 'ID',
- vtype: 'StorageId',
- allowBlank: false
- },
{
xtype: me.isCreate ? 'textfield' : 'displayfield',
name: 'portal',
@@ -39,73 +23,8 @@ Ext.define('PVE.storage.SheepdogInputPanel', {
allowBlank: false
}
];
-
- me.column2 = [
- {
- xtype: 'proxmoxcheckbox',
- name: 'enable',
- checked: true,
- uncheckedValue: 0,
- fieldLabel: gettext('Enable')
- }
- ];
-
- if (me.isCreate || me.storageId !== 'local') {
- me.column2.unshift({
- xtype: 'pveNodeSelector',
- name: 'nodes',
- fieldLabel: gettext('Nodes'),
- emptyText: gettext('All') + ' (' +
- gettext('No restrictions') +')',
- multiSelect: true,
- autoSelect: false
- });
- }
+ me.column2 = [];
me.callParent();
}
});
-
-Ext.define('PVE.storage.SheepdogEdit', {
- 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('PVE.storage.SheepdogInputPanel', {
- isCreate: me.isCreate,
- storageId: me.storageId
- });
-
- Ext.apply(me, {
- subject: PVE.Utils.format_storage_type('sheepdog'),
- isAdd: true,
- items: [ ipanel ]
- });
-
- me.callParent();
-
- if (!me.isCreate) {
- me.load({
- success: function(response, options) {
- var values = response.result.data;
- if (values.nodes) {
- values.nodes = values.nodes.split(',');
- }
- values.enable = values.disable ? 0 : 1;
- ipanel.setValues(values);
- }
- });
- }
- }
-});
diff --git a/www/manager6/storage/ZFSEdit.js b/www/manager6/storage/ZFSEdit.js
index ac85b359..3906be76 100644
--- a/www/manager6/storage/ZFSEdit.js
+++ b/www/manager6/storage/ZFSEdit.js
@@ -1,37 +1,28 @@
Ext.define('PVE.storage.ZFSInputPanel', {
- extend: 'Proxmox.panel.InputPanel',
+ extend: 'PVE.panel.StorageBase',
onGetValues: function(values) {
var me = this;
if (me.isCreate) {
- values.type = 'zfs';
values.content = 'images';
- } else {
- delete values.storage;
}
- values.disable = values.enable ? 0 : 1;
- delete values.enable;
-
values.nowritecache = values.writecache ? 0 : 1;
delete values.writecache;
- return values;
+ return me.callParent([values]);
+ },
+
+ setValues: function diff(values) {
+ values.writecache = values.nowritecache ? 0 : 1;
+ this.callParent([values]);
},
initComponent : function() {
var me = this;
me.column1 = [
- {
- xtype: me.isCreate ? 'textfield' : 'displayfield',
- name: 'storage',
- value: me.storageId || '',
- fieldLabel: 'ID',
- vtype: 'StorageId',
- allowBlank: false
- },
{
xtype: me.isCreate ? 'textfield' : 'displayfield',
name: 'portal',
@@ -70,13 +61,6 @@ Ext.define('PVE.storage.ZFSInputPanel', {
];
me.column2 = [
- {
- xtype: 'proxmoxcheckbox',
- name: 'enable',
- checked: true,
- uncheckedValue: 0,
- fieldLabel: gettext('Enable')
- },
{
xtype: me.isCreate ? 'pveiScsiProviderSelector' : 'displayfield',
name: 'iscsiprovider',
@@ -107,63 +91,6 @@ Ext.define('PVE.storage.ZFSInputPanel', {
}
];
- if (me.isCreate || me.storageId !== 'local') {
- me.column2.unshift({
- xtype: 'pveNodeSelector',
- name: 'nodes',
- fieldLabel: gettext('Nodes'),
- emptyText: gettext('All') + ' (' +
- gettext('No restrictions') +')',
- multiSelect: true,
- autoSelect: false
- });
- }
-
me.callParent();
}
});
-
-Ext.define('PVE.storage.ZFSEdit', {
- 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('PVE.storage.ZFSInputPanel', {
- isCreate: me.isCreate,
- storageId: me.storageId
- });
-
- Ext.apply(me, {
- subject: 'ZFS Storage',
- isAdd: true,
- items: [ ipanel ]
- });
-
- me.callParent();
-
- if (!me.isCreate) {
- me.load({
- success: function(response, options) {
- var values = response.result.data;
- if (values.nodes) {
- values.nodes = values.nodes.split(',');
- }
- values.enable = values.disable ? 0 : 1;
- values.writecache = values.nowritecache ? 0 : 1;
- ipanel.setValues(values);
- }
- });
- }
- }
-});
diff --git a/www/manager6/storage/ZFSPoolEdit.js b/www/manager6/storage/ZFSPoolEdit.js
index 56ed0f84..69d03817 100644
--- a/www/manager6/storage/ZFSPoolEdit.js
+++ b/www/manager6/storage/ZFSPoolEdit.js
@@ -35,36 +35,12 @@ Ext.define('PVE.storage.ZFSPoolSelector', {
});
Ext.define('PVE.storage.ZFSPoolInputPanel', {
- extend: 'Proxmox.panel.InputPanel',
-
- onGetValues: function(values) {
- var me = this;
-
- if (me.isCreate) {
- values.type = 'zfspool';
- } else {
- delete values.storage;
- }
-
- values.disable = values.enable ? 0 : 1;
- delete values.enable;
-
- return values;
- },
+ extend: 'PVE.panel.StorageBase',
initComponent : function() {
var me = this;
- me.column1 = [
- {
- xtype: me.isCreate ? 'textfield' : 'displayfield',
- name: 'storage',
- value: me.storageId || '',
- fieldLabel: 'ID',
- vtype: 'StorageId',
- allowBlank: false
- }
- ];
+ me.column1 = [];
if (me.isCreate) {
me.column1.push(Ext.create('PVE.storage.ZFSPoolSelector', {
@@ -95,13 +71,6 @@ Ext.define('PVE.storage.ZFSPoolInputPanel', {
});
/*jslint confusion: false*/
me.column2 = [
- {
- xtype: 'proxmoxcheckbox',
- name: 'enable',
- checked: true,
- uncheckedValue: 0,
- fieldLabel: gettext('Enable')
- },
{
xtype: 'proxmoxcheckbox',
name: 'sparse',
@@ -118,66 +87,6 @@ Ext.define('PVE.storage.ZFSPoolInputPanel', {
}
];
- if (me.isCreate || me.storageId !== 'local') {
- me.column2.unshift({
- xtype: 'pveNodeSelector',
- name: 'nodes',
- fieldLabel: gettext('Nodes'),
- emptyText: gettext('All') + ' (' +
- gettext('No restrictions') +')',
- multiSelect: true,
- autoSelect: false
- });
- }
-
me.callParent();
}
});
-
-Ext.define('PVE.storage.ZFSPoolEdit', {
- 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('PVE.storage.ZFSPoolInputPanel', {
- isCreate: me.isCreate,
- storageId: me.storageId
- });
-
- Ext.apply(me, {
- subject: PVE.Utils.format_storage_type('zfspool'),
- 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);
- }
- });
- }
- }
-});
--
2.14.2
More information about the pve-devel
mailing list