]> git.proxmox.com Git - proxmox-widget-toolkit.git/blobdiff - Utils.js
refactor info/link extraction from onlinehelp to utils
[proxmox-widget-toolkit.git] / Utils.js
index 9f98a1156453d6aa890ebcb255b5213fa94ea74c..ee0a0ce460220785ffef48274f27454311707186 100644 (file)
--- a/Utils.js
+++ b/Utils.js
@@ -57,7 +57,8 @@ Ext.define('Proxmox.Utils', { utilities: {
     groupText: gettext('Group'),
 
     language_map: {
-       zh_CN: 'Chinese',
+       zh_CN: 'Chinese (Simplified)',
+       zh_TW: 'Chinese (Traditional)',
        ca: 'Catalan',
        da: 'Danish',
        en: 'English',
@@ -178,11 +179,26 @@ Ext.define('Proxmox.Utils', { utilities: {
        return min < width ? width : min;
     },
 
+    setAuthData: function(data) {
+       Proxmox.CSRFPreventionToken = data.CSRFPreventionToken;
+       Proxmox.UserName = data.username;
+       Proxmox.LoggedOut = data.LoggedOut;
+       // creates a session cookie (expire = null)
+       // that way the cookie gets deleted after the browser window is closed
+       Ext.util.Cookies.set(Proxmox.Setup.auth_cookie_name, data.ticket, null, '/', null, true);
+    },
+
     authOK: function() {
+       if (Proxmox.LoggedOut) {
+           return undefined;
+       }
        return (Proxmox.UserName !== '') && Ext.util.Cookies.get(Proxmox.Setup.auth_cookie_name);
     },
 
     authClear: function() {
+       if (Proxmox.LoggedOut) {
+           return undefined;
+       }
        Ext.util.Cookies.clear(Proxmox.Setup.auth_cookie_name);
     },
 
@@ -404,6 +420,7 @@ Ext.define('Proxmox.Utils', { utilities: {
        eth: gettext("Network Device"),
        bridge: 'Linux Bridge',
        bond: 'Linux Bond',
+       vlan: 'Linux VLAN',
        OVSBridge: 'OVS Bridge',
        OVSBond: 'OVS Bond',
        OVSPort: 'OVS Port',
@@ -445,7 +462,8 @@ Ext.define('Proxmox.Utils', { utilities: {
        qmstop: [ 'VM', gettext('Stop') ],
        qmreset: [ 'VM', gettext('Reset') ],
        qmshutdown: [ 'VM', gettext('Shutdown') ],
-       qmsuspend: [ 'VM', gettext('Suspend') ],
+       qmsuspend: [ 'VM', gettext('Hibernate') ],
+       qmpause: [ 'VM', gettext('Pause') ],
        qmresume: [ 'VM', gettext('Resume') ],
        qmconfig: [ 'VM', gettext('Configure') ],
        vzsnapshot: [ 'CT', gettext('Snapshot') ],
@@ -479,27 +497,36 @@ Ext.define('Proxmox.Utils', { utilities: {
        cephdestroyosd: ['Ceph OSD', gettext('Destroy') ],
        cephcreatepool: ['Ceph Pool', gettext('Create') ],
        cephdestroypool: ['Ceph Pool', gettext('Destroy') ],
+       cephfscreate: ['CephFS', gettext('Create') ],
+       cephcreatemds: ['Ceph Metadata Server', gettext('Create') ],
+       cephdestroymds: ['Ceph Metadata Server', gettext('Destroy') ],
        imgcopy: ['', gettext('Copy data') ],
        imgdel: ['', gettext('Erase data') ],
+       unknownimgdel: ['', gettext('Destroy image from unknown guest') ],
        download: ['', gettext('Download') ],
-       vzdump: ['', gettext('Backup') ],
+       vzdump: ['VM/CT', gettext('Backup') ],
        aptupdate: ['', gettext('Update package database') ],
        startall: [ '', gettext('Start all VMs and Containers') ],
        stopall: [ '', gettext('Stop all VMs and Containers') ],
-       migrateall: [ '', gettext('Migrate all VMs and Containers') ]
+       migrateall: [ '', gettext('Migrate all VMs and Containers') ],
+       dircreate: [ gettext('Directory Storage'), gettext('Create') ],
+       lvmcreate: [ gettext('LVM Storage'), gettext('Create') ],
+       lvmthincreate: [ gettext('LVM-Thin Storage'), gettext('Create') ],
+       zfscreate: [ gettext('ZFS Storage'), gettext('Create') ]
     },
 
     format_task_description: function(type, id) {
        var farray = Proxmox.Utils.task_desc_table[type];
+       var text;
        if (!farray) {
-           var text = type;
+           text = type;
            if (id) {
                type += ' ' + id;
            }
            return text;
        }
        var prefix = farray[0];
-       var text = farray[1];
+       text = farray[1];
        if (prefix) {
            return prefix + ' ' + id + ' - ' + text;
        }
@@ -566,16 +593,43 @@ Ext.define('Proxmox.Utils', { utilities: {
        return Ext.Date.format(servertime, 'Y-m-d H:i:s');
     },
 
-    openXtermJsViewer: function(vmtype, vmid, nodename, vmname) {
-       var url = Ext.urlEncode({
+    get_help_info: function(section) {
+       var helpMap;
+       if (typeof proxmoxOnlineHelpInfo !== 'undefined') {
+           helpMap = proxmoxOnlineHelpInfo;
+       } else if (typeof pveOnlineHelpInfo !== 'undefined') {
+           // be backward compatible with older pve-doc-generators
+           helpMap = pveOnlineHelpInfo;
+       } else {
+           throw "no global OnlineHelpInfo map declared";
+       }
+
+       return helpMap[section];
+    },
+
+    get_help_link: function(section) {
+       var info = Proxmox.Utils.get_help_info(section);
+       if (!info) {
+           return;
+       }
+
+       return window.location.origin + info.link;
+    },
+
+    openXtermJsViewer: function(vmtype, vmid, nodename, vmname, cmd) {
+       var url = Ext.Object.toQueryString({
            console: vmtype, // kvm, lxc, upgrade or shell
            xtermjs: 1,
            vmid: vmid,
            vmname: vmname,
-           node: nodename
+           node: nodename,
+           cmd: cmd,
+
        });
        var nw = window.open("?" + url, '_blank', 'toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=800,height=420');
-       nw.focus();
+       if (nw) {
+           nw.focus();
+       }
     }
 
 },
@@ -589,10 +643,12 @@ Ext.define('Proxmox.Utils', { utilities: {
        var IPV4_REGEXP = "(?:(?:" + IPV4_OCTET + "\\.){3}" + IPV4_OCTET + ")";
        var IPV6_H16 = "(?:[0-9a-fA-F]{1,4})";
        var IPV6_LS32 = "(?:(?:" + IPV6_H16 + ":" + IPV6_H16 + ")|" + IPV4_REGEXP + ")";
+       var IPV4_CIDR_MASK = "([0-9]{1,2})";
+       var IPV6_CIDR_MASK = "([0-9]{1,3})";
 
 
        me.IP4_match = new RegExp("^(?:" + IPV4_REGEXP + ")$");
-       me.IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/([0-9]{1,2})$");
+       me.IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/" + IPV4_CIDR_MASK + "$");
 
        var IPV6_REGEXP = "(?:" +
            "(?:(?:"                                                  + "(?:" + IPV6_H16 + ":){6})" + IPV6_LS32 + ")|" +
@@ -607,10 +663,11 @@ Ext.define('Proxmox.Utils', { utilities: {
            ")";
 
        me.IP6_match = new RegExp("^(?:" + IPV6_REGEXP + ")$");
-       me.IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/([0-9]{1,3})$");
+       me.IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/" + IPV6_CIDR_MASK + "$");
        me.IP6_bracket_match = new RegExp("^\\[(" + IPV6_REGEXP + ")\\]");
 
        me.IP64_match = new RegExp("^(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + ")$");
+       me.IP64_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + "\/" + IPV6_CIDR_MASK + ")|(?:" + IPV4_REGEXP + "\/" + IPV4_CIDR_MASK + ")$");
 
        var DnsName_REGEXP = "(?:(([a-zA-Z0-9]([a-zA-Z0-9\\-]*[a-zA-Z0-9])?)\\.)*([A-Za-z0-9]([A-Za-z0-9\\-]*[A-Za-z0-9])?))";
        me.DnsName_match = new RegExp("^" + DnsName_REGEXP + "$");