this patch adds a checkbox to the login window,
which uses the localstorage to save the username

if one is saved, set the textfield and move focus
to the password field

Signed-off-by: Dominik Csapak <d.csa...@proxmox.com>
---
 www/manager6/window/LoginWindow.js | 42 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/www/manager6/window/LoginWindow.js 
b/www/manager6/window/LoginWindow.js
index d980860..521f2db 100644
--- a/www/manager6/window/LoginWindow.js
+++ b/www/manager6/window/LoginWindow.js
@@ -9,11 +9,22 @@ Ext.define('PVE.window.LoginWindow', {
            var me = this;
 
            var form = this.lookupReference('loginForm');
+           var unField = this.lookupReference('usernameField');
+           var saveunField = this.lookupReference('saveunField');
            var view = this.getView();
 
            if(form.isValid()){
                view.el.mask(gettext('Please wait...'), 'x-mask-loading');
 
+               // set or clear username
+               var sp = Ext.state.Manager.getProvider();
+               if (saveunField.getValue() === true) {
+                   sp.set(unField.getStateId(), unField.getValue());
+               } else {
+                   sp.clear(unField.getStateId());
+               }
+               sp.set(saveunField.getStateId(), saveunField.getValue());
+
                form.submit({
                    failure: function(f, resp){
                        view.el.unmask();
@@ -79,7 +90,25 @@ Ext.define('PVE.window.LoginWindow', {
            },
             'button[reference=loginButton]': {
                click: 'onLogon'
-            }
+            },
+           '#': {
+               show: function() {
+                   var sp = Ext.state.Manager.getProvider();
+                   var checkboxField = this.lookupReference('saveunField');
+                   var unField = this.lookupReference('usernameField');
+
+                   var checked = sp.get(checkboxField.getStateId());
+                   checkboxField.setValue(checked);
+
+                   if(checked === true) {
+                       var username = sp.get(unField.getStateId());
+                       console.log(username);
+                       unField.setValue(username);
+                       var pwField = this.lookupReference('passwordField');
+                       pwField.focus();
+                   }
+               }
+           }
        }
     },
 
@@ -119,6 +148,7 @@ Ext.define('PVE.window.LoginWindow', {
                name: 'username',
                itemId: 'usernameField',
                reference: 'usernameField',
+               stateId: 'login-username',
                blankText: gettext("Enter your user name")
            },
            {
@@ -152,6 +182,16 @@ Ext.define('PVE.window.LoginWindow', {
        ],
        buttons: [
            {
+               xtype: 'checkbox',
+               fieldLabel: gettext('Save User name'),
+               name: 'saveusername',
+               reference: 'saveunField',
+               stateId: 'login-saveusername',
+               labelWidth: 'auto',
+               labelAlign: 'right',
+               submitValue: false
+           },
+           {
                text: gettext('Login'),
                reference: 'loginButton'
            }
-- 
2.1.4


_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to