]> git.proxmox.com Git - pve-manager.git/blob - www/manager/form/RealmComboBox.js
imported from svn 'pve-manager/pve2'
[pve-manager.git] / www / manager / form / RealmComboBox.js
1 Ext.define('PVE.form.RealmComboBox', {
2 extend: 'Ext.form.field.ComboBox',
3 requires: ['Ext.data.Store', 'PVE.RestProxy'],
4 alias: ['widget.pveRealmComboBox'],
5
6 initComponent: function() {
7 var me = this;
8
9 var stateid = 'pveloginrealm';
10
11 var realmstore = Ext.create('Ext.data.Store', {
12 model: 'pve-domains',
13 autoDestory: true
14 });
15
16 Ext.apply(me, {
17 fieldLabel: 'Realm',
18 name: 'realm',
19 store: realmstore,
20 queryMode: 'local',
21 allowBlank: false,
22 forceSelection: true,
23 autoSelect: false,
24 triggerAction: 'all',
25 valueField: 'realm',
26 displayField: 'comment',
27 getState: function() {
28 return { value: this.getValue() };
29 },
30 applyState : function(state) {
31 if (state && state.value) {
32 this.setValue(state.value);
33 }
34 },
35 stateEvents: [ 'select' ],
36 stateful: true,
37 id: stateid, // fixme: remove (Stateful does not work without)
38 stateID: stateid
39 });
40
41 me.callParent();
42
43 realmstore.load({
44 callback: function(r, o, success) {
45 if (success) {
46 var def = me.getValue();
47 if (!def || !realmstore.findRecord('realm', def)) {
48 def = 'pam';
49 Ext.each(r, function(record) {
50 if (record.data && record.data["default"]) {
51 def = record.data.realm;
52 }
53 });
54 }
55 if (def) {
56 me.setValue(def);
57 }
58 }
59 }
60 });
61 }
62 });