]> git.proxmox.com Git - pve-manager.git/commitdiff
copy RealmComboBox.js from manager to manager5
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 27 Apr 2015 09:56:18 +0000 (11:56 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 27 Apr 2015 09:56:18 +0000 (11:56 +0200)
www/manager5/form/RealmComboBox.js [new file with mode: 0644]

diff --git a/www/manager5/form/RealmComboBox.js b/www/manager5/form/RealmComboBox.js
new file mode 100644 (file)
index 0000000..875ec37
--- /dev/null
@@ -0,0 +1,69 @@
+Ext.define('PVE.form.RealmComboBox', {
+    extend: 'Ext.form.field.ComboBox',
+    alias: ['widget.pveRealmComboBox'],
+
+    needOTP: function(realm) {
+       var me = this;
+
+       var rec = me.store.findRecord('realm', realm);
+
+       return rec && rec.data && rec.data.tfa ? rec.data.tfa : undefined;
+    },
+
+    initComponent: function() {
+       var me = this;
+
+       var stateid = 'pveloginrealm';
+
+       var realmstore = Ext.create('Ext.data.Store', {
+           model: 'pve-domains',
+           autoDestory: true
+       });
+
+       Ext.apply(me, {
+           fieldLabel: gettext('Realm'),
+           name: 'realm',
+           store: realmstore,
+           queryMode: 'local',
+           allowBlank: false,
+           forceSelection: true,
+           autoSelect: false,
+           triggerAction: 'all',
+           valueField: 'realm',
+           displayField: 'descr',
+           getState: function() {
+               return { value: this.getValue() };
+           },
+           applyState : function(state) {
+               if (state && state.value) {
+                   this.setValue(state.value);
+               }
+           },
+           stateEvents: [ 'select' ],
+           stateful: true,
+           id: stateid, // fixme: remove (Stateful does not work without)  
+           stateID: stateid
+       });
+
+        me.callParent();
+
+       realmstore.load({
+           callback: function(r, o, success) {
+               if (success) {
+                   var def = me.getValue();
+                   if (!def || !realmstore.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);
+                   }
+               }
+           }
+       });
+    }
+});