]> git.proxmox.com Git - proxmox-widget-toolkit.git/blob - src/form/RealmComboBox.js
auth-realm selector: add custom store filters for callers
[proxmox-widget-toolkit.git] / src / form / RealmComboBox.js
1 Ext.define('Proxmox.form.RealmComboBox', {
2 extend: 'Ext.form.field.ComboBox',
3 alias: 'widget.pmxRealmComboBox',
4
5 controller: {
6 xclass: 'Ext.app.ViewController',
7
8 init: function(view) {
9 let store = view.getStore();
10 if (view.storeFilter) {
11 store.setFilters(view.storeFilter);
12 }
13 store.on('load', this.onLoad, view);
14 store.load();
15 },
16
17 onLoad: function(store, records, success) {
18 if (!success) {
19 return;
20 }
21 let me = this;
22 let val = me.getValue();
23 if (!val || !me.store.findRecord('realm', val, 0, false, true, true)) {
24 let def = 'pam';
25 Ext.each(records, function(rec) {
26 if (rec.data && rec.data.default) {
27 def = rec.data.realm;
28 }
29 });
30 me.setValue(def);
31 }
32 },
33 },
34
35 // define custom filters for the underlying store
36 storeFilter: undefined,
37
38 fieldLabel: gettext('Realm'),
39 name: 'realm',
40 queryMode: 'local',
41 allowBlank: false,
42 editable: false,
43 forceSelection: true,
44 autoSelect: false,
45 triggerAction: 'all',
46 valueField: 'realm',
47 displayField: 'descr',
48 getState: function() {
49 return { value: this.getValue() };
50 },
51 applyState: function(state) {
52 if (state && state.value) {
53 this.setValue(state.value);
54 }
55 },
56 stateEvents: ['select'],
57 stateful: true, // last chosen auth realm is saved between page reloads
58 id: 'pveloginrealm', // We need stable ids when using stateful, not autogenerated
59 stateID: 'pveloginrealm',
60
61 store: {
62 model: 'pmx-domains',
63 autoLoad: false,
64 },
65 });