]> git.proxmox.com Git - pve-manager.git/blobdiff - www/manager6/Utils.js
add snippets content type to the gui
[pve-manager.git] / www / manager6 / Utils.js
index d0de3829ea050cd67fdf17d6116e96450ec7ea11..c96987e8b7450c91e7c9bc3a5eaeeee0f7de3366 100644 (file)
@@ -19,6 +19,7 @@ Ext.Ajax.defaultHeaders = {
     'Accept': 'application/json'
 };
 
+/*jslint confusion: true */
 Ext.define('PVE.Utils', { utilities: {
 
     // this singleton contains miscellaneous utilities
@@ -122,6 +123,32 @@ Ext.define('PVE.Utils', { utilities: {
        return state;
     },
 
+    render_zfs_health: function(value) {
+       if (typeof value == 'undefined'){
+           return "";
+       }
+       var iconCls = 'question-circle';
+       switch (value) {
+           case 'AVAIL':
+           case 'ONLINE':
+               iconCls = 'check-circle good';
+               break;
+           case 'REMOVED':
+           case 'DEGRADED':
+               iconCls = 'exclamation-circle warning';
+               break;
+           case 'UNAVAIL':
+           case 'FAULTED':
+           case 'OFFLINE':
+               iconCls = 'times-circle critical';
+               break;
+           default: //unknown
+       }
+
+       return '<i class="fa fa-' + iconCls + '"></i> ' + value;
+
+    },
+
     get_kvm_osinfo: function(value) {
        var info = { base: 'Other' }; // default
        if (value) {
@@ -175,6 +202,32 @@ Ext.define('PVE.Utils', { utilities: {
        return fa.join(', ');
     },
 
+    render_qga_features: function(value) {
+       if (!value) {
+           return Proxmox.Utils.defaultText + ' (' + Proxmox.Utils.disabledText  + ')';
+       }
+       var props = PVE.Parser.parsePropertyString(value, 'enabled');
+       if (!PVE.Parser.parseBoolean(props.enabled)) {
+           return Proxmox.Utils.disabledText;
+       }
+
+       delete props.enabled;
+       var agentstring = Proxmox.Utils.enabledText;
+
+       Ext.Object.each(props, function(key, value) {
+           var keystring = '' ;
+           agentstring += ', ' + key + ': ';
+
+           if (PVE.Parser.parseBoolean(value)) {
+               agentstring += Proxmox.Utils.enabledText;
+           } else {
+               agentstring += Proxmox.Utils.disabledText;
+           }
+       });
+
+       return agentstring;
+    },
+
     render_qemu_bios: function(value) {
        if (!value) {
            return Proxmox.Utils.defaultText + ' (SeaBIOS)';
@@ -255,7 +308,9 @@ Ext.define('PVE.Utils', { utilities: {
        serial0: gettext('Serial terminal') + ' 0',
        serial1: gettext('Serial terminal') + ' 1',
        serial2: gettext('Serial terminal') + ' 2',
-       serial3: gettext('Serial terminal') + ' 3'
+       serial3: gettext('Serial terminal') + ' 3',
+       virtio: 'VirtIO-GPU',
+       none: Proxmox.Utils.noneText
     },
 
     render_kvm_language: function (value) {
@@ -282,7 +337,7 @@ Ext.define('PVE.Utils', { utilities: {
        '__default__': Proxmox.Utils.defaultText + ' (HTML5)',
        'vv': 'SPICE (remote-viewer)',
        'html5': 'HTML5 (noVNC)',
-       'xtermjs': 'xterm.js',
+       'xtermjs': 'xterm.js'
     },
 
     render_console_viewer: function(value) {
@@ -303,7 +358,11 @@ Ext.define('PVE.Utils', { utilities: {
        if (!value) {
            return Proxmox.Utils.defaultText;
        }
-       var text = PVE.Utils.kvm_vga_drivers[value];
+       var vga = PVE.Parser.parsePropertyString(value, 'type');
+       var text = PVE.Utils.kvm_vga_drivers[vga.type];
+       if (!vga.type) {
+           text = Proxmox.Utils.defaultText;
+       }
        if (text) {
            return text + ' (' + value + ')';
        }
@@ -379,11 +438,14 @@ Ext.define('PVE.Utils', { utilities: {
        return days.toFixed(1) + 'd';
     },
 
-    imagesText: gettext('Disk image'),
-    backupFileText: gettext('VZDump backup file'),
-    vztmplText: gettext('Container template'),
-    isoImageText: gettext('ISO image'),
-    containersText: gettext('Container'),
+    contentTypes: {
+       'images': gettext('Disk image'),
+       'backup': gettext('VZDump backup file'),
+       'vztmpl': gettext('Container template'),
+       'iso': gettext('ISO image'),
+       'rootdir': gettext('Container'),
+       'snippets': gettext('Snippets')
+    },
 
     storageSchema: {
        dir: {
@@ -427,20 +489,26 @@ Ext.define('PVE.Utils', { utilities: {
            hideAdd: true,
            faIcon: 'building'
        },
-       rbd: {
-           name: 'RBD',
-           ipanel: 'RBDInputPanel',
+       cephfs: {
+           name: 'CephFS',
+           ipanel: 'CephFSInputPanel',
+           faIcon: 'building'
+       },
+       pvecephfs: {
+           name: 'CephFS (PVE)',
+           ipanel: 'CephFSInputPanel',
            hideAdd: true,
            faIcon: 'building'
        },
-       rbd_ext: {
-           name: 'RBD (external)',
+       rbd: {
+           name: 'RBD',
            ipanel: 'RBDInputPanel',
            faIcon: 'building'
        },
        pveceph: {
            name: 'RBD (PVE)',
-           ipanel: 'PVERBDInputPanel',
+           ipanel: 'RBDInputPanel',
+           hideAdd: true,
            faIcon: 'building'
        },
        zfs: {
@@ -460,8 +528,10 @@ Ext.define('PVE.Utils', { utilities: {
     },
 
     format_storage_type: function(value, md, record) {
-       if (value === 'rbd' && record) {
-           value = (record.get('monhost')?'rbd_ext':'pveceph');
+       if (value === 'rbd') {
+           value = (!record || record.get('monhost') ? 'rbd' : 'pveceph');
+       } else if (value === 'cephfs') {
+           value = (!record || record.get('monhost') ? 'cephfs' : 'pvecephfs');
        }
 
        var schema = PVE.Utils.storageSchema[value];
@@ -485,23 +555,9 @@ Ext.define('PVE.Utils', { utilities: {
     },
 
     format_content_types: function(value) {
-       var cta = [];
-
-       Ext.each(value.split(',').sort(), function(ct) {
-           if (ct === 'images') {
-               cta.push(PVE.Utils.imagesText);
-           } else if (ct === 'backup') {
-               cta.push(PVE.Utils.backupFileText);
-           } else if (ct === 'vztmpl') {
-               cta.push(PVE.Utils.vztmplText);
-           } else if (ct === 'iso') {
-               cta.push(PVE.Utils.isoImageText);
-           } else if (ct === 'rootdir') {
-               cta.push(PVE.Utils.containersText);
-           }
-       });
-
-       return cta.join(', ');
+       return value.split(',').sort().map(function(ct) {
+           return PVE.Utils.contentTypes[ct] || ct;
+       }).join(', ');
     },
 
     render_storage_content: function(value, metaData, record) {
@@ -721,6 +777,33 @@ Ext.define('PVE.Utils', { utilities: {
        return PVE.Utils.render_size_usage(record.used, record.total);
     },
 
+    render_optional_url: function(value) {
+       var match;
+       if (value && (match = value.match(/^https?:\/\//)) !== null) {
+           return '<a target="_blank" href="' + value + '">' + value + '</a>';
+       }
+       return value;
+    },
+
+    render_san: function(value) {
+       var names = [];
+       if (Ext.isArray(value)) {
+           value.forEach(function(val) {
+               if (!Ext.isNumber(val)) {
+                   names.push(val);
+               }
+           });
+           return names.join('<br>');
+       }
+       return value;
+    },
+
+    render_full_name: function(firstname, metaData, record) {
+       var first = firstname || '';
+       var last = record.data.lastname || '';
+       return Ext.htmlEncode(first + " " + last);
+    },
+
     windowHostname: function() {
        return window.location.hostname.replace(Proxmox.Utils.IP6_bracket_match,
             function(m, addr, offset, original) { return addr; });
@@ -777,7 +860,7 @@ Ext.define('PVE.Utils', { utilities: {
            allowXtermjs = true;
        } else if (typeof consoles === 'object') {
            allowSpice = consoles.spice;
-           allowXtermjs = consoles.xtermjs;
+           allowXtermjs = !!consoles.xtermjs;
        }
        var vncdefault = 'html5';
        var dv = PVE.VersionInfo.console || vncdefault;
@@ -794,7 +877,8 @@ Ext.define('PVE.Utils', { utilities: {
            novnc: 1,
            vmid: vmid,
            vmname: vmname,
-           node: nodename
+           node: nodename,
+           resize: 'off'
        });
        var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427");
        nw.focus();
@@ -858,7 +942,7 @@ Ext.define('PVE.Utils', { utilities: {
                    Ext.Msg.alert('Error', response.htmlStatus);
                },
                success: function(response, opts) {
-                   var allowSpice = response.result.data.spice;
+                   var allowSpice = !!response.result.data.spice;
                    PVE.Utils.openDefaultConsoleWindow(allowSpice, 'kvm', vmid, nodename, vmname);
                }
            });
@@ -911,6 +995,7 @@ Ext.define('PVE.Utils', { utilities: {
        }
 
        menu.showAt(event.getXY());
+       return menu;
     },
 
     // helper for deleting field which are set to there default values
@@ -978,7 +1063,7 @@ Ext.define('PVE.Utils', { utilities: {
        }
     },
 
-    mp_counts: { mps: 10, unused: 10 },
+    mp_counts: { mps: 256, unused: 256 },
 
     forEachMP: function(func, includeUnused) {
        var i, cont;