]> git.proxmox.com Git - proxmox-widget-toolkit.git/blobdiff - src/Utils.js
ui: Utils: refactor userid parsing to Utils
[proxmox-widget-toolkit.git] / src / Utils.js
index 7f32f0556b8c32d1d3e9c11824ef5c1d9b2b5678..6526ec21fadf581b6f2e7890e5d23adde3321d9c 100644 (file)
@@ -238,6 +238,30 @@ utilities: {
        return min < width ? width : min;
     },
 
+    // returns username + realm
+    parse_userid: function(userid) {
+       if (!Ext.isString(userid)) {
+           return [undefined, undefined];
+       }
+
+       let match = userid.match(/^(.+)@([^@]+)$/);
+       if (match !== null) {
+           return [match[1], match[2]];
+       }
+
+       return [undefined, undefined];
+    },
+
+    render_username: function(userid) {
+       let username = PVE.Utils.parse_userid(userid)[0] || "";
+       return Ext.htmlEncode(username);
+    },
+
+    render_realm: function(userid) {
+       let username = PVE.Utils.parse_userid(userid)[1] || "";
+       return Ext.htmlEncode(username);
+    },
+
     getStoredAuth: function() {
        let storedAuth = JSON.parse(window.localStorage.getItem('ProxmoxUser'));
        return storedAuth || {};