proxmox-backup/www/RealmComboBox.js

68 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-04-09 11:37:14 +00:00
Ext.define('pbs-domains', {
extend: "Ext.data.Model",
fields: [ 'realm', 'comment', 'default' ],
idProperty: 'realm',
proxy: {
type: 'proxmox',
url: "/api2/json/access/domains"
}
});
Ext.define('PBS.form.RealmComboBox', {
extend: 'Ext.form.field.ComboBox',
alias: ['widget.pbsRealmComboBox'],
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'),
name: 'realm',
queryMode: 'local',
allowBlank: false,
editable: false,
forceSelection: true,
autoSelect: false,
triggerAction: 'all',
valueField: 'realm',
displayField: 'comment',
getState: function() {
return { value: this.getValue() };
},
applyState : function(state) {
if (state && state.value) {
this.setValue(state.value);
}
},
stateEvents: [ 'select' ],
stateful: true, // last chosen auth realm is saved between page reloads
id: 'pbsloginrealm', // We need stable ids when using stateful, not autogenerated
stateID: 'pbsloginrealm',
store: {
model: 'pbs-domains',
autoLoad: true
}
});