]> git.proxmox.com Git - pve-manager.git/blobdiff - www/manager6/Utils.js
improve xtermjs settings button behaviour
[pve-manager.git] / www / manager6 / Utils.js
index 87699e567993e02077a19b96c009d74d1c2dca6f..ad5a0a61b7152f0d21bf7807fa1fd0436ef2c7b5 100644 (file)
@@ -10,7 +10,6 @@ Ext.enableAriaPanels = false;
 // avoid errors when running without development tools
 if (!Ext.isDefined(Ext.global.console)) {
     var console = {
-       dir: function() {},
        log: function() {}
     };
 }
@@ -279,20 +278,23 @@ Ext.define('PVE.Utils', { utilities: {
        return data;
     },
 
+    console_map: {
+       '__default__': Proxmox.Utils.defaultText + ' (HTML5)',
+       'vv': 'SPICE (remote-viewer)',
+       'html5': 'HTML5 (noVNC)',
+       'xtermjs': 'xterm.js'
+    },
+
     render_console_viewer: function(value) {
-       if (!value || value === '__default__') {
-           return Proxmox.Utils.defaultText + ' (HTML5)';
-       } else if (value === 'vv') {
-           return  'SPICE (remote-viewer)';
-       } else if (value === 'html5') {
-           return  'HTML5 (noVNC)';
-       } else {
-           return value;
+       value = value || '__default__';
+       if (PVE.Utils.console_map[value]) {
+           return PVE.Utils.console_map[value];
        }
+       return value;
     },
 
     console_viewer_array: function() {
-       return Ext.Array.map(['__default__','vv', 'html5'], function(v) {
+       return Ext.Array.map(Object.keys(PVE.Utils.console_map), function(v) {
            return [v, PVE.Utils.render_console_viewer(v)];
        });
     },
@@ -383,41 +385,90 @@ Ext.define('PVE.Utils', { utilities: {
     isoImageText: gettext('ISO image'),
     containersText: gettext('Container'),
 
+    storageSchema: {
+       dir: {
+           name: Proxmox.Utils.directoryText,
+           ipanel: 'DirInputPanel',
+           faIcon: 'folder'
+       },
+       lvm: {
+           name: 'LVM',
+           ipanel: 'LVMInputPanel',
+           faIcon: 'folder'
+       },
+       lvmthin: {
+           name: 'LVM-Thin',
+           ipanel: 'LvmThinInputPanel',
+           faIcon: 'folder'
+       },
+       nfs: {
+           name: 'NFS',
+           ipanel: 'NFSInputPanel',
+           faIcon: 'building'
+       },
+       cifs: {
+           name: 'CIFS',
+           ipanel: 'CIFSInputPanel',
+           faIcon: 'building'
+       },
+       glusterfs: {
+           name: 'GlusterFS',
+           ipanel: 'GlusterFsInputPanel',
+           faIcon: 'building'
+       },
+       iscsi: {
+           name: 'iSCSI',
+           ipanel: 'IScsiInputPanel',
+           faIcon: 'building'
+       },
+       sheepdog: {
+           name: 'Sheepdog',
+           ipanel: 'SheepdogInputPanel',
+           hideAdd: true,
+           faIcon: 'building'
+       },
+       rbd: {
+           name: 'RBD',
+           ipanel: 'RBDInputPanel',
+           hideAdd: true,
+           faIcon: 'building'
+       },
+       rbd_ext: {
+           name: 'RBD (external)',
+           ipanel: 'RBDInputPanel',
+           faIcon: 'building'
+       },
+       pveceph: {
+           name: 'RBD (PVE)',
+           ipanel: 'PVERBDInputPanel',
+           faIcon: 'building'
+       },
+       zfs: {
+           name: 'ZFS over iSCSI',
+           ipanel: 'ZFSInputPanel',
+           faIcon: 'building'
+       },
+       zfspool: {
+           name: 'ZFS',
+           ipanel: 'ZFSPoolInputPanel',
+           faIcon: 'folder'
+       },
+       drbd: {
+           name: 'DRBD',
+           hideAdd: true
+       }
+    },
+
     format_storage_type: function(value, md, record) {
        if (value === 'rbd' && record) {
            value = (record.get('monhost')?'rbd_ext':'pveceph');
        }
-       if (value === 'dir') {
-           return Proxmox.Utils.directoryText;
-       } else if (value === 'nfs') {
-           return 'NFS';
-       } else if (value === 'glusterfs') {
-           return 'GlusterFS';
-       } else if (value === 'lvm') {
-           return 'LVM';
-       } else if (value === 'lvmthin') {
-           return 'LVM-Thin';
-       } else if (value === 'iscsi') {
-           return 'iSCSI';
-       } else if (value === 'rbd') {
-           return 'RBD';
-       } else if (value === 'rbd_ext') {
-           return 'RBD (external)';
-       } else if (value === 'pveceph') {
-           return 'RBD (PVE)';
-       } else if (value === 'sheepdog') {
-           return 'Sheepdog';
-       } else if (value === 'zfs') {
-           return 'ZFS over iSCSI';
-       } else if (value === 'zfspool') {
-           return 'ZFS';
-       } else if (value === 'iscsidirect') {
-           return 'iSCSIDirect';
-       } else if (value === 'drbd') {
-           return 'DRBD';
-       } else {
-           return Proxmox.Utils.unknownText;
+
+       var schema = PVE.Utils.storageSchema[value];
+       if (schema) {
+           return schema.name;
        }
+       return Proxmox.Utils.unknownText;
     },
 
     format_ha: function(value) {
@@ -670,13 +721,34 @@ 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;
+    },
+
     windowHostname: function() {
        return window.location.hostname.replace(Proxmox.Utils.IP6_bracket_match,
             function(m, addr, offset, original) { return addr; });
     },
 
-    openDefaultConsoleWindow: function(allowSpice, vmtype, vmid, nodename, vmname) {
-       var dv = PVE.Utils.defaultViewer(allowSpice);
+    openDefaultConsoleWindow: function(consoles, vmtype, vmid, nodename, vmname) {
+       var dv = PVE.Utils.defaultViewer(consoles);
        PVE.Utils.openConsoleWindow(dv, vmtype, vmid, nodename, vmname);
     },
 
@@ -717,10 +789,20 @@ Ext.define('PVE.Utils', { utilities: {
        }
     },
 
-    defaultViewer: function(allowSpice) {
+    defaultViewer: function(consoles) {
+
+       var allowSpice, allowXtermjs;
+
+       if (consoles === true) {
+           allowSpice = true;
+           allowXtermjs = true;
+       } else if (typeof consoles === 'object') {
+           allowSpice = consoles.spice;
+           allowXtermjs = !!consoles.xtermjs;
+       }
        var vncdefault = 'html5';
        var dv = PVE.VersionInfo.console || vncdefault;
-       if (dv === 'vv' && !allowSpice) {
+       if ((dv === 'vv' && !allowSpice) || (dv === 'xtermjs' && !allowXtermjs)) {
            dv = vncdefault;
        }
 
@@ -829,32 +911,22 @@ Ext.define('PVE.Utils', { utilities: {
            v.select(record);
        }
        var menu;
+       var template = !!record.data.template;
+       var type = record.data.type;
 
-       if (record.data.type === 'qemu' && !record.data.template) {
-           menu = Ext.create('PVE.qemu.CmdMenu', {
-               pveSelNode: record
-           });
-       } else if (record.data.type === 'qemu' && record.data.template) {
-           menu = Ext.create('PVE.qemu.TemplateMenu', {
-               pveSelNode: record
-           });
-       } else if (record.data.type === 'lxc' && !record.data.template) {
-           menu = Ext.create('PVE.lxc.CmdMenu', {
-               pveSelNode: record
-           });
-       } else if (record.data.type === 'lxc' && record.data.template) {
-           /* since clone does not work reliably, disable for now
-           menu = Ext.create('PVE.lxc.TemplateMenu', {
-               pveSelNode: record
-           });
-           */
-           return;
-
-       } else if (record.data.type === 'node' ){
-           menu = Ext.create('PVE.node.CmdMenu', {
+       if (template) {
+           if (type === 'qemu' || type == 'lxc') {
+               menu = Ext.create('PVE.menu.TemplateMenu', {
+                   pveSelNode: record
+               });
+           }
+       } else if (type === 'qemu' ||
+                  type === 'lxc' ||
+                  type === 'node') {
+           menu = Ext.create('PVE.' + type + '.CmdMenu', {
+               pveSelNode: record,
                nodename: record.data.node
            });
-
        } else {
            return;
        }
@@ -894,6 +966,60 @@ Ext.define('PVE.Utils', { utilities: {
            callback(evt.target.result);
        };
        reader.readAsText(file);
+    },
+
+    bus_counts: { ide: 4, sata: 6, scsi: 16, virtio: 16 },
+
+    // types is either undefined (all busses), an array of busses, or a single bus
+    forEachBus: function(types, func) {
+       var busses = Object.keys(PVE.Utils.bus_counts);
+       var i, j, count, cont;
+
+       if (Ext.isArray(types)) {
+           busses = types;
+       } else if (Ext.isDefined(types)) {
+           busses = [ types ];
+       }
+
+       // check if we only have valid busses
+       for (i = 0; i < busses.length; i++) {
+           if (!PVE.Utils.bus_counts[busses[i]]) {
+               throw "invalid bus: '" + busses[i] + "'";
+           }
+       }
+
+       for (i = 0; i < busses.length; i++) {
+           count = PVE.Utils.bus_counts[busses[i]];
+           for (j = 0; j < count; j++) {
+               cont = func(busses[i], j);
+               if (!cont && cont !== undefined) {
+                   return;
+               }
+           }
+       }
+    },
+
+    mp_counts: { mps: 10, unused: 10 },
+
+    forEachMP: function(func, includeUnused) {
+       var i, cont;
+       for (i = 0; i < PVE.Utils.mp_counts.mps; i++) {
+           cont = func('mp', i);
+           if (!cont && cont !== undefined) {
+               return;
+           }
+       }
+
+       if (!includeUnused) {
+           return;
+       }
+
+       for (i = 0; i < PVE.Utils.mp_counts.unused; i++) {
+           cont = func('unused', i);
+           if (!cont && cont !== undefined) {
+               return;
+           }
+       }
     }
 },