]> git.proxmox.com Git - proxmox-backup.git/blobdiff - www/MainView.js
ui: user menu: allow changing language while logged in
[proxmox-backup.git] / www / MainView.js
index 062d78e0ff53223f1a5b2e4eb795620f4b4c01f6..10bc8eeb9c96d20b87270fd8c848b898e92c4eb7 100644 (file)
@@ -10,11 +10,11 @@ Ext.define('PBS.MainView', {
            ':path:subpath': {
                action: 'changePath',
                before: 'beforeChangePath',
-                conditions : {
-                   ':path'    : '(?:([%a-zA-Z0-9\\-\\_\\s,\.]+))',
-                   ':subpath' : '(?:(?::)([%a-zA-Z0-9\\-\\_\\s,]+))?'
-               }
-           }
+                conditions: {
+                   ':path': '(?:([%a-zA-Z0-9\\-\\_\\s,.]+))',
+                   ':subpath': '(?:(?::)([%a-zA-Z0-9\\-\\_\\s,]+))?',
+               },
+           },
        },
 
        beforeChangePath: function(path, subpath, action) {
@@ -67,53 +67,54 @@ Ext.define('PBS.MainView', {
            var contentpanel = me.lookupReference('contentpanel');
            var lastpanel = contentpanel.getLayout().getActiveItem();
 
-           var obj;
-           if (PBS.Utils.isDataStorePath(path)) {
-               let datastore = PBS.Utils.getDataStoreFromPath(path);
-               obj = contentpanel.add({
-                   xtype: 'pbsDataStorePanel',
-                   nodename: 'localhost',
-                   datastore,
-               });
-           } else {
-               obj = contentpanel.add({
-                   xtype: path,
-                   nodename: 'localhost',
-                   border: false
-               });
-           }
-
-           var treelist = me.lookupReference('navtree');
+           let tabChangeListener = function(tp, newc, oldc) {
+               let newpath = path;
 
-           treelist.suspendEvents();
-           if (subpath === undefined) {
-               treelist.select(path);
-           } else {
-               treelist.select(path + ':' + subpath);
-           }
-           treelist.resumeEvents();
+               // only add the subpath part for the
+               // non-default tabs
+               if (tp.items.findIndex('id', newc.id) !== 0) {
+                   newpath += `:${newc.getItemId()}`;
+               }
 
-           if (Ext.isFunction(obj.setActiveTab)) {
-               obj.setActiveTab(subpath || 0);
-               obj.addListener('tabchange', function(tabpanel, newc, oldc) {
-                   var newpath = path;
+               me.redirectTo(newpath);
+           };
 
-                   // only add the subpath part for the
-                   // non-default tabs
-                   if (tabpanel.items.findIndex('id', newc.id) !== 0) {
-                       newpath += ":" + newc.getItemId();
+           let xtype = path;
+           var obj;
+           let datastore;
+           if (PBS.Utils.isDataStorePath(path)) {
+               datastore = PBS.Utils.getDataStoreFromPath(path);
+               if (lastpanel && lastpanel.xtype === 'pbsDataStorePanel' && !subpath) {
+                   let activeTab = lastpanel.getActiveTab();
+                   let newpath = path;
+                   if (lastpanel.items.indexOf(activeTab) !== 0) {
+                       subpath = activeTab.getItemId();
+                       newpath += `:${subpath}`;
                    }
-
                    me.redirectTo(newpath);
-               });
+               }
+               xtype = 'pbsDataStorePanel';
            }
+           obj = contentpanel.add({
+               xtype,
+               datastore,
+               nodename: 'localhost',
+               border: false,
+               activeTab: subpath || 0,
+               listeners: {
+                   tabchange: tabChangeListener,
+               },
+           });
+
+           var treelist = me.lookupReference('navtree');
+
+           treelist.select(path, true);
 
            contentpanel.setActiveItem(obj);
 
            if (lastpanel) {
                contentpanel.remove(lastpanel, { destroy: true });
            }
-
        },
 
        logout: function() {
@@ -125,20 +126,21 @@ Ext.define('PBS.MainView', {
        },
 
        control: {
-           'button[reference=logoutButton]': {
-               click: 'logout'
-           }
+           '[reference=logoutButton]': {
+               click: 'logout',
+           },
        },
 
        init: function(view) {
            var me = this;
 
-           me.lookupReference('usernameinfo').update({username:Proxmox.UserName});
+           PBS.data.RunningTasksStore.startUpdate();
+           me.lookupReference('usernameinfo').setText(Proxmox.UserName);
 
            // show login on requestexception
            // fixme: what about other errors
            Ext.Ajax.on('requestexception', function(conn, response, options) {
-               if (response.status == 401) { // auth failure
+               if (response.status === 401 || response.status === '401') { // auth failure
                    me.logout();
                }
            });
@@ -154,7 +156,7 @@ Ext.define('PBS.MainView', {
                    Ext.Ajax.request({
                        params: {
                            username: Proxmox.UserName,
-                           password: ticket
+                           password: ticket,
                        },
                        url: '/api2/json/access/ticket',
                        method: 'POST',
@@ -164,17 +166,17 @@ Ext.define('PBS.MainView', {
                        success: function(response, opts) {
                            var obj = Ext.decode(response.responseText);
                            PBS.Utils.updateLoginData(obj.data);
-                       }
+                       },
                    });
                },
-               interval: 15*60*1000
+               interval: 15*60*1000,
            });
 
 
            // select treeitem and load page from url fragment, if set
            let token = Ext.util.History.getToken() || 'pbsDashboard';
            this.redirectTo(token, true);
-       }
+       },
     },
 
     plugins: 'viewport',
@@ -187,9 +189,9 @@ Ext.define('PBS.MainView', {
            xtype: 'container',
            layout: {
                type: 'hbox',
-               align: 'middle'
+               align: 'middle',
            },
-           margin: '2 5 2 5',
+           margin: '2 0 2 5',
            height: 38,
            items: [
                {
@@ -197,7 +199,8 @@ Ext.define('PBS.MainView', {
                    prefix: '',
                },
                {
-                   xtype: 'versioninfo'
+                   padding: '0 0 0 5',
+                   xtype: 'versioninfo',
                },
                {
                    padding: 5,
@@ -208,12 +211,6 @@ Ext.define('PBS.MainView', {
                    flex: 1,
                    baseCls: 'x-plain',
                },
-               {
-                   baseCls: 'x-plain',
-                   reference: 'usernameinfo',
-                   padding: '0 5',
-                   tpl: Ext.String.format(gettext("You are logged in as {0}"), "'{username}'")
-               },
                {
                    xtype: 'button',
                    baseCls: 'x-btn',
@@ -224,12 +221,38 @@ Ext.define('PBS.MainView', {
                    margin: '0 5 0 0',
                },
                {
-                   reference: 'logoutButton',
+                   xtype: 'pbsTaskButton',
+                   margin: '0 5 0 0',
+               },
+               {
                    xtype: 'button',
-                   iconCls: 'fa fa-sign-out',
-                   text: gettext('Logout')
-               }
-           ]
+                   reference: 'usernameinfo',
+                   style: {
+                       // proxmox dark grey p light grey as border
+                       backgroundColor: '#464d4d',
+                       borderColor: '#ABBABA',
+                   },
+                   margin: '0 5 0 0',
+                   iconCls: 'fa fa-user',
+                   menu: [
+                       {
+                           iconCls: 'fa fa-language',
+                           text: gettext('Language'),
+                           reference: 'languageButton',
+                           handler: () => Ext.create('Proxmox.window.LanguageEditWindow', {
+                               cookieName: 'PBSLangCookie',
+                               autoShow: true,
+                           }),
+                       },
+                       '-',
+                       {
+                           iconCls: 'fa fa-sign-out',
+                           text: gettext('Logout'),
+                           reference: 'logoutButton',
+                       },
+                   ],
+               },
+           ],
        },
        {
            xtype: 'panel',
@@ -238,7 +261,7 @@ Ext.define('PBS.MainView', {
            region: 'west',
            layout: {
                type: 'vbox',
-               align: 'stretch'
+               align: 'stretch',
            },
            items: [{
                xtype: 'navigationtree',
@@ -248,20 +271,20 @@ Ext.define('PBS.MainView', {
                // because of a bug where a viewcontroller does not detect
                // the selectionchange event of a treelist
                listeners: {
-                   selectionchange: 'navigate'
-               }
+                   selectionchange: 'navigate',
+               },
            }, {
                xtype: 'box',
                cls: 'x-treelist-nav',
-               flex: 1
-           }]
+               flex: 1,
+           }],
        },
        {
            xtype: 'panel',
            layout: { type: 'card' },
            region: 'center',
            border: false,
-           reference: 'contentpanel'
-       }
-    ]
+           reference: 'contentpanel',
+       },
+    ],
 });