ui: storage: RBD: factor out view- model/controler

will be reused for CephFS, look at this with git's ignore whitespace
change flag '-w' to see that the changes consist mostly of indent and
hunk movement changes

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2018-11-15 13:20:09 +01:00 committed by Dominik Csapak
parent 35ce219cdc
commit b42d008b3a

View File

@ -1,75 +1,84 @@
/*jslint confusion: true*/ /*jslint confusion: true*/
Ext.define('PVE.storage.RBDInputPanel', { Ext.define('PVE.storage.Ceph.Model', {
extend: 'PVE.panel.StorageBase', extend: 'Ext.app.ViewModel',
alias: 'viewmodel.cephstorage',
viewModel: { data: {
parent: null, pveceph: true,
data: { pvecephPossible: true
pveceph: true, }
pvecephPossible: true });
Ext.define('PVE.storage.Ceph.Controller', {
extend: 'Ext.app.ViewController',
alias: 'controller.cephstorage',
control: {
'#': {
afterrender: 'queryMonitors'
},
'textfield[name=username]': {
disable: 'resetField'
},
'displayfield[name=monhost]': {
enable: 'queryMonitors'
},
'textfield[name=monhost]': {
disable: 'resetField',
enable: 'resetField'
} }
}, },
resetField: function(field) {
field.reset();
},
queryMonitors: function(field, newVal, oldVal) {
// we get called with two signatures, the above one for a field
// change event and the afterrender from the view, this check only
// can be true for the field change one and omit the API request if
// pveceph got unchecked - as it's not needed there.
if (field && !newVal && oldVal) {
return;
}
var view = this.getView();
var vm = this.getViewModel();
if (!(view.isCreate || vm.get('pveceph'))) {
return; // only query on create or if editing a pveceph store
}
controller: { var monhostField = this.lookupReference('monhost');
xclass: 'Ext.app.ViewController',
control: {
'#': {
afterrender: 'queryMonitors'
},
'textfield[name=username]': {
disable: 'resetField'
},
'displayfield[name=monhost]': {
enable: 'queryMonitors'
},
'textfield[name=monhost]': {
disable: 'resetField',
enable: 'resetField'
}
},
resetField: function(field) {
field.reset();
},
queryMonitors: function(field, newVal, oldVal) {
// we get called with two signatures, the above one for a field
// change event and the afterrender from the view, this check only
// can be true for the field change one and omit the API request if
// pveceph got unchecked - as it's not needed there.
if (field && !newVal && oldVal) {
return;
}
var view = this.getView();
var vm = this.getViewModel();
if (!(view.isCreate || vm.get('pveceph'))) {
return; // only query on create or if editing a pveceph store
}
var monhostField = this.lookupReference('monhost'); Proxmox.Utils.API2Request({
url: '/api2/json/nodes/localhost/ceph/mon',
Proxmox.Utils.API2Request({ method: 'GET',
url: '/api2/json/nodes/localhost/ceph/mon', scope: this,
method: 'GET', callback: function(options, success, response) {
scope: this, var data = response.result.data;
callback: function(options, success, response) { if (response.status === 200) {
var data = response.result.data; if (data.length > 0) {
if (response.status === 200) { var monhost = Ext.Array.pluck(data, 'name').sort().join(',');
if (data.length > 0) { monhostField.setValue(monhost);
var monhost = Ext.Array.pluck(data, 'name').sort().join(','); monhostField.resetOriginalValue();
monhostField.setValue(monhost); if (view.isCreate) {
monhostField.resetOriginalValue(); vm.set('pvecephPossible', true);
if (view.isCreate) {
vm.set('pvecephPossible', true);
}
} else {
vm.set('pveceph', false);
} }
} else { } else {
vm.set('pveceph', false); vm.set('pveceph', false);
vm.set('pvecephPossible', false);
} }
} else {
vm.set('pveceph', false);
vm.set('pvecephPossible', false);
} }
}); }
} });
}
});
Ext.define('PVE.storage.RBDInputPanel', {
extend: 'PVE.panel.StorageBase',
controller: 'cephstorage',
viewModel: {
type: 'cephstorage'
}, },
setValues: function(values) { setValues: function(values) {