RealmComboBox: use schematic declaration and ViewController

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2017-12-11 15:47:14 +01:00 committed by Dominik Csapak
parent ef4ef788d5
commit 1cfd092907

View File

@ -1,7 +1,33 @@
/*global Proxmox*/
Ext.define('PVE.form.RealmComboBox', { Ext.define('PVE.form.RealmComboBox', {
extend: 'Ext.form.field.ComboBox', extend: 'Ext.form.field.ComboBox',
alias: ['widget.pveRealmComboBox'], alias: ['widget.pveRealmComboBox'],
controller: {
xclass: 'Ext.app.ViewController',
init: function(view) {
view.store.on('load', this.onLoad, view);
},
onLoad: function(store, records, success) {
if (!success) {
return;
}
var me = this;
var val = me.getValue();
if (!val || !me.store.findRecord('realm', val)) {
var def = 'pam';
Ext.each(records, function(rec) {
if (rec.data && rec.data['default']) {
def = rec.data.realm;
}
});
me.setValue(def);
}
}
},
fieldLabel: gettext('Realm'), fieldLabel: gettext('Realm'),
name: 'realm', name: 'realm',
queryMode: 'local', queryMode: 'local',
@ -32,32 +58,8 @@ Ext.define('PVE.form.RealmComboBox', {
return rec && rec.data && rec.data.tfa ? rec.data.tfa : undefined; return rec && rec.data && rec.data.tfa ? rec.data.tfa : undefined;
}, },
initComponent: function() { store: {
var me = this; model: 'pve-domains',
autoLoad: true
me.store = Ext.create('Ext.data.Store', {
model: 'pve-domains'
});
me.callParent();
me.store.load({
callback: function(r, o, success) {
if (success) {
var def = me.getValue();
if (!def || !me.store.findRecord('realm', def)) {
def = 'pam';
Ext.each(r, function(record) {
if (record.data && record.data["default"]) {
def = record.data.realm;
}
});
}
if (def) {
me.setValue(def);
}
}
}
});
} }
}); });