]> git.proxmox.com Git - pve-manager.git/blobdiff - www/manager6/Utils.js
Add ceph in optional packages
[pve-manager.git] / www / manager6 / Utils.js
index cd61c24edd6227b5c0f3d14f734827257784be7b..bc52af1c2c10ddac4028edd5d43c98a55afc0836 100644 (file)
@@ -2,19 +2,19 @@ Ext.ns('PVE');
 
 // avoid errors related to Accessible Rich Internet Applications
 // (access for people with disabilities)
-// TODO reenable after all components are upgraded 
+// TODO reenable after all components are upgraded
 Ext.enableAria = false;
 Ext.enableAriaButtons = false;
 Ext.enableAriaPanels = false;
 
 // avoid errors when running without development tools
-if (!Ext.isDefined(Ext.global.console)) {   
-    var console = { 
-       dir: function() {}, 
-       log: function() {} 
+if (!Ext.isDefined(Ext.global.console)) {
+    var console = {
+       dir: function() {},
+       log: function() {}
     };
 }
-console.log("Starting PVE Manager"); 
+console.log("Starting PVE Manager");
 
 Ext.Ajax.defaultHeaders = {
     'Accept': 'application/json'
@@ -22,7 +22,7 @@ Ext.Ajax.defaultHeaders = {
 
 Ext.Ajax.on('beforerequest', function(conn, options) {
     if (PVE.CSRFPreventionToken) {
-       if (!options.headers) { 
+       if (!options.headers) {
            options.headers = {};
        }
        options.headers.CSRFPreventionToken = PVE.CSRFPreventionToken;
@@ -36,7 +36,7 @@ var IPV6_LS32 = "(?:(?:" + IPV6_H16 + ":" + IPV6_H16 + ")|" + IPV4_REGEXP + ")";
 
 
 var IP4_match = new RegExp("^(?:" + IPV4_REGEXP + ")$");
-var IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/[1-3][0-9]?$");
+var IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/([0-9]{1,2})$");
 
 var IPV6_REGEXP = "(?:" +
     "(?:(?:"                                                  + "(?:" + IPV6_H16 + ":){6})" + IPV6_LS32 + ")|" +
@@ -51,7 +51,7 @@ var IPV6_REGEXP = "(?:" +
     ")";
 
 var IP6_match = new RegExp("^(?:" + IPV6_REGEXP + ")$");
-var IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/[0-9]{1,3}?$");
+var IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/([0-9]{1,3})$");
 var IP6_bracket_match = new RegExp("^\\[(" + IPV6_REGEXP + ")\\]");
 
 var IP64_match = new RegExp("^(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + ")$");
@@ -60,7 +60,7 @@ Ext.define('PVE.Utils', { statics: {
 
     // this class only contains static functions
 
-    toolkit: undefined, // (extjs|touch), set inside Toolkit.js 
+    toolkit: undefined, // (extjs|touch), set inside Toolkit.js
 
     log_severity_hash: {
        0: "panic",
@@ -88,7 +88,7 @@ Ext.define('PVE.Utils', { statics: {
        w2k: 'Microsoft Windows 2000',
        w2k8: 'Microsoft Windows Vista/2008',
        win7: 'Microsoft Windows 7/2008r2',
-       win8: 'Microsoft Windows 8/2012',
+       win8: 'Microsoft Windows 8.x/10/2012/r2',
        l24: 'Linux 2.4 Kernel',
        l26: 'Linux 4.X/3.X/2.6 Kernel',
        solaris: 'Solaris Kernel'
@@ -100,7 +100,7 @@ Ext.define('PVE.Utils', { statics: {
        }
        var text = PVE.Utils.kvm_ostypes[value];
        if (text) {
-           return text + ' (' + value + ')';
+           return text;
        }
        return value;
     },
@@ -142,7 +142,7 @@ Ext.define('PVE.Utils', { statics: {
     },
 
     render_network_iface_type: function(value) {
-       return PVE.Utils.network_iface_types[value] || 
+       return PVE.Utils.network_iface_types[value] ||
            PVE.Utils.unknownText;
     },
 
@@ -181,29 +181,29 @@ Ext.define('PVE.Utils', { statics: {
     kvm_keymaps: {
        //ar: 'Arabic',
        da: 'Danish',
-       de: 'German', 
-       'de-ch': 'German (Swiss)', 
-       'en-gb': 'English (UK)', 
+       de: 'German',
+       'de-ch': 'German (Swiss)',
+       'en-gb': 'English (UK)',
        'en-us': 'English (USA)',
        es: 'Spanish',
        //et: 'Estonia',
        fi: 'Finnish',
-       //fo: 'Faroe Islands', 
-       fr: 'French', 
-       'fr-be': 'French (Belgium)', 
+       //fo: 'Faroe Islands',
+       fr: 'French',
+       'fr-be': 'French (Belgium)',
        'fr-ca': 'French (Canada)',
        'fr-ch': 'French (Swiss)',
        //hr: 'Croatia',
        hu: 'Hungarian',
        is: 'Icelandic',
-       it: 'Italian', 
+       it: 'Italian',
        ja: 'Japanese',
        lt: 'Lithuanian',
        //lv: 'Latvian',
-       mk: 'Macedonian', 
+       mk: 'Macedonian',
        nl: 'Dutch',
        //'nl-be': 'Dutch (Belgium)',
-       no: 'Norwegian', 
+       no: 'Norwegian',
        pl: 'Polish',
        pt: 'Portuguese',
        'pt-br': 'Portuguese (Brazil)',
@@ -307,7 +307,7 @@ Ext.define('PVE.Utils', { statics: {
            return PVE.Utils.defaultText;
        }
        var text = PVE.Utils.kvm_vga_drivers[value];
-       if (text) { 
+       if (text) {
            return text + ' (' + value + ')';
        }
        return value;
@@ -352,7 +352,7 @@ Ext.define('PVE.Utils', { statics: {
     // fixme: remove - not needed?
     gridLineHeigh: function() {
        return 21;
-       
+
        //if (Ext.isGecko)
        //return 23;
        //return 21;
@@ -372,10 +372,10 @@ Ext.define('PVE.Utils', { statics: {
            if (verbose && Ext.isObject(result.errors)) {
                msg += "<br>";
                Ext.Object.each(result.errors, function(prop, desc) {
-                   msg += "<br><b>" + Ext.htmlEncode(prop) + "</b>: " + 
+                   msg += "<br><b>" + Ext.htmlEncode(prop) + "</b>: " +
                        Ext.htmlEncode(desc);
                });
-           }   
+           }
        }
 
        return msg;
@@ -586,7 +586,7 @@ Ext.define('PVE.Utils', { statics: {
        migrateall: [ '', gettext('Migrate all VMs and Containers') ]
     },
 
-    format_task_description: function(type, id) {      
+    format_task_description: function(type, id) {
        var farray = PVE.Utils.task_desc_table[type];
        if (!farray) {
            return type;
@@ -594,7 +594,7 @@ Ext.define('PVE.Utils', { statics: {
        var prefix = farray[0];
        var text = farray[1];
        if (prefix) {
-           return prefix + ' ' + id + ' - ' + text; 
+           return prefix + ' ' + id + ' - ' + text;
        }
        return text;
     },
@@ -637,7 +637,7 @@ Ext.define('PVE.Utils', { statics: {
        return "<div class='pve-bar-wrap'>" + text + "<div class='pve-bar-border'>" +
            "<div class='pve-bar-inner' style='width:" + per + "%;'></div>" +
            "</div></div>";
-       
+
     },
 
     format_cpu_bar: function(per1, per2, text) {
@@ -645,7 +645,7 @@ Ext.define('PVE.Utils', { statics: {
        return "<div class='pve-bar-border'>" +
            "<div class='pve-bar-inner' style='width:" + per1 + "%;'></div>" +
            "<div class='pve-bar-inner2' style='width:" + per2 + "%;'></div>" +
-           "<div class='pve-bar-text'>" + text + "</div>" + 
+           "<div class='pve-bar-text'>" + text + "</div>" +
            "</div>";
     },
 
@@ -657,7 +657,7 @@ Ext.define('PVE.Utils', { statics: {
 
        return "<div class='pve-largebar-border'>" +
            "<div class='pve-largebar-inner' style='width:" + per + "%;'></div>" +
-           "<div class='pve-largebar-text'>" + text + "</div>" + 
+           "<div class='pve-largebar-text'>" + text + "</div>" +
            "</div>";
     },
 
@@ -679,7 +679,7 @@ Ext.define('PVE.Utils', { statics: {
 
        if (days) {
            var ds = days > 1 ? PVE.Utils.daysText : PVE.Utils.dayText;
-           return days.toString() + ' ' + ds + ' ' + 
+           return days.toString() + ' ' + ds + ' ' +
                hours_str + ':' + mins_str + ':' + ut_str;
        } else {
            return hours_str + ':' + mins_str + ':' + ut_str;
@@ -687,7 +687,7 @@ Ext.define('PVE.Utils', { statics: {
     },
 
     format_duration_short: function(ut) {
-       
+
        if (ut < 60) {
            return ut.toString() + 's';
        }
@@ -703,7 +703,7 @@ Ext.define('PVE.Utils', { statics: {
        }
 
        var days = ut / 86400;
-       return days.toFixed(0) + 'd';   
+       return days.toFixed(0) + 'd';
     },
 
     yesText: gettext('Yes'),
@@ -725,6 +725,8 @@ Ext.define('PVE.Utils', { statics: {
     vztmplText: gettext('Container template'),
     isoImageText: gettext('ISO image'),
     containersText: gettext('Container'),
+    stateText: gettext('State'),
+    groupText: gettext('Group'),
 
     format_expire: function(date) {
        if (!date) {
@@ -778,6 +780,20 @@ Ext.define('PVE.Utils', { statics: {
        return !value ? PVE.Utils.yesText : PVE.Utils.noText;
     },
 
+    format_ha: function(value) {
+       var text = PVE.Utils.format_boolean(value.managed);
+
+       if (value.managed) {
+           text += ', ' + PVE.Utils.stateText + ': ';
+           text += value.state || PVE.Utils.noneText;
+
+           text += ', ' +  PVE.Utils.groupText + ': ';
+           text += value.group || PVE.Utils.noneText;
+       }
+
+       return text;
+    },
+
     format_content_types: function(value) {
        var cta = [];
 
@@ -803,8 +819,8 @@ Ext.define('PVE.Utils', { statics: {
        if (Ext.isNumber(data.channel) &&
            Ext.isNumber(data.id) &&
            Ext.isNumber(data.lun)) {
-           return "CH " + 
-               Ext.String.leftPad(data.channel,2, '0') + 
+           return "CH " +
+               Ext.String.leftPad(data.channel,2, '0') +
                " ID " + data.id + " LUN " + data.lun;
        }
        return data.volid.replace(/^.*:(.*\/)?/,'');
@@ -825,7 +841,7 @@ Ext.define('PVE.Utils', { statics: {
        if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) {
            return '';
        }
-       
+
        var per = value * 100;
 
        return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU');
@@ -879,7 +895,7 @@ Ext.define('PVE.Utils', { statics: {
 
        var mem = value;
        var maxmem = record.data.maxmem;
-       
+
        if (!record.data.uptime) {
            return '';
        }
@@ -888,9 +904,7 @@ Ext.define('PVE.Utils', { statics: {
            return '';
        }
 
-       var per = (mem * 100) / maxmem;
-
-       return per.toFixed(1) + '%';
+       return PVE.Utils.render_size(value);
     },
 
     calculate_disk_usage: function(data) {
@@ -917,14 +931,16 @@ Ext.define('PVE.Utils', { statics: {
 
        var disk = value;
        var maxdisk = record.data.maxdisk;
+       var type = record.data.type;
 
-       if (!(Ext.isNumeric(disk) && maxdisk)) {
+       if (!Ext.isNumeric(disk) ||
+           type === 'qemu' ||
+           maxdisk === 0 ||
+           (type === 'lxc' && record.data.uptime === 0)) {
            return '';
        }
 
-       var per = (disk * 100) / maxdisk;
-
-       return per.toFixed(1) + '%';
+       return PVE.Utils.render_size(value);
     },
 
     render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) {
@@ -959,11 +975,11 @@ Ext.define('PVE.Utils', { statics: {
            }
        } else if (value === 'node') {
            if (record.data.running) {
-               gridcls = '-online'
+               gridcls = '-online';
            }
        }
 
-       var fa = '<i class="fa fa-fw x-fa-grid' + gridcls  +  ' fa-' + icon  + '"></i> '
+       var fa = '<i class="fa fa-fw x-fa-grid' + gridcls  +  ' fa-' + icon  + '"></i> ';
        return fa + value;
     },
 
@@ -974,7 +990,7 @@ Ext.define('PVE.Utils', { statics: {
        if (uptime === undefined) {
            return '';
        }
-       
+
        if (uptime <= 0) {
            return '-';
        }
@@ -986,7 +1002,7 @@ Ext.define('PVE.Utils', { statics: {
        return PVE.Utils.support_level_hash[value] || '-';
     },
 
-    render_upid: function(value, metaData, record) { 
+    render_upid: function(value, metaData, record) {
        var type = record.data.type;
        var id = record.data.id;
 
@@ -1009,7 +1025,7 @@ Ext.define('PVE.Utils', { statics: {
        return window.location.hostname.replace(IP6_bracket_match,
             function(m, addr, offset, original) { return addr; });
     },
+
     openDefaultConsoleWindow: function(allowSpice, vmtype, vmid, nodename, vmname) {
        var dv = PVE.Utils.defaultViewer(allowSpice);
        PVE.Utils.openConsoleWindow(dv, vmtype, vmid, nodename, vmname);
@@ -1112,13 +1128,13 @@ Ext.define('PVE.Utils', { statics: {
                });
                var url = 'data:application/x-virt-viewer;charset=UTF-8,' +
                    encodeURIComponent(raw);
-                   
+
                downloadWithName(url, "pve-spice.vv");
            }
        });
     },
 
-    // comp.setLoading() is buggy in ExtJS 4.0.7, so we 
+    // comp.setLoading() is buggy in ExtJS 4.0.7, so we
     // use el.mask() instead
     setErrorMask: function(comp, msg) {
        var el = comp.el;