[pve-devel] r6263 - pve-manager/pve2/www/manager

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Jul 8 10:24:38 CEST 2011


Author: dietmar
Date: 2011-07-08 10:24:38 +0200 (Fri, 08 Jul 2011)
New Revision: 6263

Modified:
   pve-manager/pve2/www/manager/Makefile.am
   pve-manager/pve2/www/manager/PVEUtils.js
   pve-manager/pve2/www/manager/Parser.js
Log:
add lint target, start to make lint happy


Modified: pve-manager/pve2/www/manager/Makefile.am
===================================================================
--- pve-manager/pve2/www/manager/Makefile.am	2011-07-08 08:00:43 UTC (rev 6262)
+++ pve-manager/pve2/www/manager/Makefile.am	2011-07-08 08:24:38 UTC (rev 6263)
@@ -79,8 +79,12 @@
 	dc/Config.js					\
 	Workspace.js
 
+lint: ${JSSRC}
+	jslint ${JSSRC} 
+
 pvemanagerlib.js: ${JSSRC}
-	cat ${JSSRC} >$@
+	cat ${JSSRC} >$@.tmp
+	mv $@.tmp $@
 
 pvelib_DATA = pvemanagerlib.js
 pvelibdir = ${WWW_EXTDIR}

Modified: pve-manager/pve2/www/manager/PVEUtils.js
===================================================================
--- pve-manager/pve2/www/manager/PVEUtils.js	2011-07-08 08:00:43 UTC (rev 6262)
+++ pve-manager/pve2/www/manager/PVEUtils.js	2011-07-08 08:24:38 UTC (rev 6263)
@@ -18,36 +18,36 @@
 
 Ext.Ajax.on('beforerequest', function(conn, options) {
     if (PVE.CSRFPreventionToken) {
-	if (!options.headers) 
+	if (!options.headers) { 
 	    options.headers = {};
-	options.headers['CSRFPreventionToken'] = PVE.CSRFPreventionToken;
+	}
+	options.headers.CSRFPreventionToken = PVE.CSRFPreventionToken;
     }
 });
 
 // custom Vtype for vtype:'IPAddress'
 Ext.apply(Ext.form.field.VTypes, {
     IPAddress:  function(v) {
-        return /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v);
+        return (/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/).test(v);
     },
     IPAddressText: 'Must be a numeric IP address',
     IPAddressMask: /[\d\.]/i,
 
     MacAddress: function(v) {
-	return /^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/.test(v);
+	return (/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/).test(v);
     },
     MacAddressMask: /[a-fA-F0-9:]/,
     MacAddressText: 'Must be a valid MAC address (example: "01:23:45:67:89:ab")',
 
     BridgeName: function(v) {
-        return /^vmbr\d{1,4}$/.test(v);
+        return (/^vmbr\d{1,4}$/).test(v);
     },
     BridgeNameText: 'Allowable bridge names: vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999',
 
     BondName: function(v) {
-        return /^bond\d{1,4}$/.test(v);
+        return (/^bond\d{1,4}$/).test(v);
     },
     BondNameText: 'Allowable bond names: bond<b>N</b>, where 0 <= <b>N</b> <= 9999'
-   
 });
 
 // we dont want that a display field set the form dirty flag! 
@@ -113,11 +113,13 @@
     },
 
     render_kvm_language: function (value) {
-	if (!value)
+	if (!value) {
 	    return 'Default';
+	}
 	var text = PVE.Utils.kvm_keymaps[value];
-	if (text) 
+	if (text) {
 	    return text + ' (' + value + ')';
+	}
 	return value;
     },
 
@@ -131,11 +133,13 @@
     },
 
     render_kvm_vga_driver: function (value) {
-	if (!value)
+	if (!value) {
 	    return 'Default (cirrus)';
+	}
 	var text = PVE.Utils.kvm_vga_drivers[value];
-	if (text) 
+	if (text) { 
 	    return text + ' (' + value + ')';
+	}
 	return value;
     },
 
@@ -169,11 +173,12 @@
 	var msg = 'Successful';
 
 	if (!result.success) {
-	    var msg = "Unknown error";
+	    msg = "Unknown error";
 	    if (result.message) {
 		msg = result.message;
-		if (result.status)
+		if (result.status) {
 		    msg += ' (' + result.status + ')';
+		}
 	    }
 	    if (verbose && Ext.isObject(result.errors)) {
 		msg += "<br>";
@@ -196,8 +201,9 @@
 	case Ext.form.action.Action.CONNECT_FAILURE:
 	    msg = 'Connect failure';
 	    var resp = action.response;
-	    if (resp.status && resp.statusText)
+	    if (resp.status && resp.statusText) {
 		msg += " " + resp.status + ": " + resp.statusText;
+	    }
 	    break;
 	case Ext.form.action.Action.LOAD_FAILURE:
 	case Ext.form.action.Action.SERVER_INVALID:
@@ -213,30 +219,31 @@
 	var successFn = options.success;
 	var failureFn = options.failure;
 
-	if (!options.url.match(/^\/api2/))
+	if (!options.url.match(/^\/api2/)) {
 	    options.url = '/api2/extjs' + options.url;
-
+	}
 	delete options.callback;
 
 	options.success = function(response, options) {
 	    var result = Ext.decode(response.responseText);
 	    if (!result.success) {
 		response.htmlStatus = PVE.Utils.extractRequestError(result, true);
-		Ext.callback(callbackFn, options.scope, [options, false, response])
-		Ext.callback(failureFn, options.scope, [response, options])
+		Ext.callback(callbackFn, options.scope, [options, false, response]);
+		Ext.callback(failureFn, options.scope, [response, options]);
 		return;
 	    }
-	    Ext.callback(callbackFn, options.scope, [options, true, response])
-	    Ext.callback(successFn, options.scope, [response, options])
+	    Ext.callback(callbackFn, options.scope, [options, true, response]);
+	    Ext.callback(successFn, options.scope, [response, options]);
 	};
 
 	options.failure = function(response, options) {
 	    var msg = "Connection error - server offline?";
-	    if (response.status && response.statusText)
+	    if (response.status && response.statusText) {
 		msg = "Connection error " + response.status + ": " + response.statusText;
+	    }
 	    response.htmlStatus = msg;
-	    Ext.callback(callbackFn, options.scope, [options, false, response])
-	    Ext.callback(failureFn, options.scope, [response, options])
+	    Ext.callback(callbackFn, options.scope, [options, false, response]);
+	    Ext.callback(failureFn, options.scope, [response, options]);
 	};
 
 	Ext.Ajax.request(options);
@@ -245,7 +252,7 @@
     assemble_field_data: function(values, data) {
         if (Ext.isObject(data)) {
             Ext.iterate(data, function(name, val) {
-                if (name in values) {
+                if (values.hasOwnProperty[name]) {
                     var bucket = values[name],
                     isArray = Ext.isArray;
                     if (!isArray(bucket)) {
@@ -265,11 +272,13 @@
 
     format_task_description: function(type, id) {
 
-	if (type == 'vncproxy')
+	if (type == 'vncproxy') {
 	    return "VNC connection to VM " + id;
+	}
 
-	if (type == 'vncshell')
+	if (type == 'vncshell') {
 	    return "VNC shell";
+	}
 
 	return type;
     },
@@ -279,9 +288,9 @@
 	var task = {};
 
 	var res = upid.match(/^UPID:(\w+):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8}):([^:\s]+):([^:\s]*):([^:\s]+):$/);
-	if (!res)
+	if (!res) {
 	    throw "unable to parse upid '" + upid + "'";
-
+	}
 	task.node = res[1];
 	task.pid = parseInt(res[2], 16);
 	task.pstart = parseInt(res[3], 16);
@@ -299,18 +308,21 @@
 
 	var kb = size / 1024;
 
-	if (kb < 1024)
+	if (kb < 1024) {
 	    return kb.toFixed(0) + "KB";
+	}
 
 	var mb = size / (1024*1024);
 
-	if (mb < 1024)
+	if (mb < 1024) {
 	    return mb.toFixed(0) + "MB";
+	}
 
 	var gb = mb / 1024;
 
-	if (gb < 1024)
+	if (gb < 1024) {
 	    return gb.toFixed(2) + "GB";
+	}
 
 	var tb =  gb / 1024;
 
@@ -337,8 +349,9 @@
 
     format_large_bar: function(per, text) {
 
-	if (!text)
+	if (!text) {
 	    text = per.toFixed(1) + "%";
+	}
 
 	return "<div class='pve-largebar-border'>" +
 	    "<div class='pve-largebar-inner' style='width:" + per + "%;'></div>" +
@@ -355,26 +368,27 @@
 	var mins = Math.floor(ut / 60);
 	ut -= mins*60;
 
-	hours = "00" + hours;
-	hours = hours.substr(hours.length - 2);
-	mins = "00" + mins;
-	mins = mins.substr(mins.length - 2);
-	ut = "00" + ut;
-	ut = ut.substr(ut.length - 2);
+	var hours_str = '00' + hours.toString();
+	hours_str = hours_str.substr(hours_str.length - 2);
+	var mins_str = "00" + mins.toString();
+	mins_str = mins_str.substr(mins_str.length - 2);
+	var ut_str = "00" + ut.toString();
+	ut_str = ut_str.substr(ut_str.length - 2);
 
 	if (days) {
 	    var ds = days > 1 ? 'days' : 'day';
-	    return days + ' ' + ds + ' ' + 
-		hours + ':' + mins + ':' + ut;
+	    return days.toString() + ' ' + ds + ' ' + 
+		hours_str + ':' + mins_str + ':' + ut_str;
 	} else {
-	    return hours + ':' + mins + ':' + ut;
+	    return hours_str + ':' + mins_str + ':' + ut_str;
 	}
     },
 
     format_duration_short: function(ut) {
 	
-	if (ut < 60)
-	    return ut + 's';
+	if (ut < 60) {
+	    return ut.toString() + 's';
+	}
 
 	if (ut < 3600) {
 	    var mins = ut / 60;
@@ -391,13 +405,17 @@
     },
 
     format_storage_type: function(value) {
-	var desc = {
-	    dir: 'Directory',
-	    nfs: 'NFS',
-	    lvm: 'LVM',
-	    iscsi: 'iSCSI'
-	};
-	return desc[value] || 'unknown';
+	if (value === 'dir') {
+	    return 'Directory';
+	} else if (value === 'nfs') {
+	    return 'NFS';
+	} else if (value === 'lvm') {
+	    return 'LVM';
+	} else if (value === 'iscsi') {
+	    return 'iSCSI';
+	} else {
+	    return 'unknown';
+	}
     },
 
     format_boolean: function(value) {
@@ -412,14 +430,15 @@
 	var cta = [];
 
 	Ext.each(value.split(','), function(ct) {
-	    if (ct === 'images')
+	    if (ct === 'images') {
 		cta.push('Images');
-	    if (ct === 'backup')
+	    } else if (ct === 'backup') {
 		cta.push('Backups');
-	    if (ct === 'vztmpl')
+	    } else if (ct === 'vztmpl') {
 		cta.push('Templates');
-	    if (ct === 'iso')
+	    } else if (ct === 'iso') {
 		cta.push('ISO');
+	    }
 	});
 
 	return cta.join(', ');
@@ -433,21 +452,24 @@
 
 	var maxcpu = record.data.maxcpu;
 
-	if (!record.data.uptime)
+	if (!record.data.uptime) {
 	    return '';
+	}
 
-	if (!(Ext.isNumeric(value) && Ext.isNumeric(maxcpu) && (maxcpu >= 1)))
-	    return ''
+	if (!(Ext.isNumeric(value) && Ext.isNumeric(maxcpu) && (maxcpu >= 1))) {
+	    return '';
+	}
 
 	var per = (value * 100) / maxcpu;
 
-	return per.toFixed(1) + '% of ' + maxcpu + (maxcpu > 1 ? 'CPUs' : 'CPU');
+	return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU');
     },
 
     render_size: function(value, metaData, record, rowIndex, colIndex, store) {
 
-	if (!Ext.isNumeric(value))
+	if (!Ext.isNumeric(value)) {
 	    return '';
+	}
 
 	return PVE.Utils.format_size(value);
     },
@@ -462,11 +484,13 @@
 	var mem = value;
 	var maxmem = record.data.maxmem;
 	
-	if (!record.data.uptime)
+	if (!record.data.uptime) {
 	    return '';
+	}
 
-	if (!(Ext.isNumeric(mem) && maxmem))
-	    return ''
+	if (!(Ext.isNumeric(mem) && maxmem)) {
+	    return '';
+	}
 
 	var per = (mem * 100) / maxmem;
 
@@ -478,8 +502,9 @@
 	var disk = value;
 	var maxdisk = record.data.maxdisk;
 
-	if (!(Ext.isNumeric(disk) && maxdisk))
-	    return ''
+	if (!(Ext.isNumeric(disk) && maxdisk)) {
+	    return '';
+	}
 
 	var per = (disk * 100) / maxdisk;
 
@@ -497,11 +522,13 @@
 
 	var uptime = value;
 
-	if (uptime === undefined)
+	if (uptime === undefined) {
 	    return '';
+	}
 	
-	if (uptime <= 0)
+	if (uptime <= 0) {
 	    return '-';
+	}
 
 	return PVE.Utils.format_duration_long(uptime);
     },

Modified: pve-manager/pve2/www/manager/Parser.js
===================================================================
--- pve-manager/pve2/www/manager/Parser.js	2011-07-08 08:00:43 UTC (rev 6262)
+++ pve-manager/pve2/www/manager/Parser.js	2011-07-08 08:24:38 UTC (rev 6263)
@@ -6,24 +6,28 @@
     // this class only contains static functions
 
     parseQemuNetwork: function(key, value) {
-	if (!(key && value))
+	if (!(key && value)) {
 	    return;
+	}
 
 	var res = {};
 
 	var errors = false;
 	Ext.Array.each(value.split(','), function(p) {
-	    if (!p || p.match(/^\s*$/))
+	    if (!p || p.match(/^\s*$/)) {
 		return; // continue
+	    }
+
 	    var match_res;
 
-	    if (match_res = p.match(/^(ne2k_pci|e1000|rtl8139|pcnet|virtio|ne2k_isa|i82551|i82557b|i82559er)(=([0-9a-f]{2}(:[0-9a-f]{2}){5}))?$/i)) {
+	    if ((match_res = p.match(/^(ne2k_pci|e1000|rtl8139|pcnet|virtio|ne2k_isa|i82551|i82557b|i82559er)(=([0-9a-f]{2}(:[0-9a-f]{2}){5}))?$/i)) !== null) {
 		res.model = match_res[1].toLowerCase();
-		if (match_res[3])
+		if (match_res[3]) {
 		    res.macaddr = match_res[3];
-	    } else if (match_res = p.match(/^bridge=(\S+)$/)) {
+		}
+	    } else if ((match_res = p.match(/^bridge=(\S+)$/)) !== null) {
 		res.bridge = match_res[1];
-	    } else if (match_res = p.match(/^rate=(\d+(\.\d+)?)$/)) {
+	    } else if ((match_res = p.match(/^rate=(\d+(\.\d+)?)$/)) !== null) {
 		res.rate = match_res[1];
 	    } else {
 		errors = true;
@@ -31,8 +35,9 @@
 	    }
 	});
 
-	if (errors || !res.model)
+	if (errors || !res.model) {
 	    return;
+	}
 
 	return res;
     },
@@ -40,36 +45,40 @@
     printQemuNetwork: function(net) {
 
 	var netstr = net.model;
-	if (net.macaddr)
+	if (net.macaddr) {
 	    netstr += "=" + net.macaddr;
-	if (net.bridge)
+	}
+	if (net.bridge) {
 	    netstr += ",bridge=" + net.bridge;
-	if (net.rate)
+	}
+	if (net.rate) {
 	    netstr += ",rate=" + net.rate;
-
+	}
 	return netstr;
     },
 
     parseQemuDrive: function(key, value) {
-	if (!(key && value))
+	if (!(key && value)) {
 	    return;
+	}
 
 	var res = {};
 
-	var match_res = key.match(/^([^\d]+)(\d+)$/);
-	if (!match_res)
+	var match_res = key.match(/^([a-z]+)(\d+)$/);
+	if (!match_res) {
 	    return;
-
+	}
 	res['interface'] = match_res[1];
-	res['index'] = match_res[2];
+	res.index = match_res[2];
 
 	var errors = false;
 	Ext.Array.each(value.split(','), function(p) {
-	    if (!p || p.match(/^\s*$/))
+	    if (!p || p.match(/^\s*$/)) {
 		return; // continue
-	    var match_res = p.match(/^([a-z]+)=(.+)$/);
+	    }
+	    var match_res = p.match(/^([a-z]+)=(\S+)$/);
 	    if (!match_res) {
-		if (!p.match(/=/)) {
+		if (!p.match(/\=/)) {
 		    res.file = p;
 		    return; // continue
 		}
@@ -77,9 +86,10 @@
 		return false; // break
 	    }
 	    var k = match_res[1];
-	    if (k === 'volume')
+	    if (k === 'volume') {
 		k = 'file';
-	    
+	    }
+
 	    if (Ext.isDefined(res[k])) {
 		errors = true;
 		return false; // break
@@ -87,15 +97,17 @@
 
 	    var v = match_res[2];
 	    
-	    if (k === 'cache' && v === 'off')
+	    if (k === 'cache' && v === 'off') {
 		v = 'none';
-	    
+	    }
+
 	    res[k] = v;
 	});
 
-	if (errors || !res.file)
+	if (errors || !res.file) {
 	    return;
-	
+	}
+
 	return res;
     },
 
@@ -105,9 +117,9 @@
 
 	Ext.Object.each(drive, function(key, value) {
 	    if (!Ext.isDefined(value) || key === 'file' || 
-		key === 'index' || key === 'interface')
+		key === 'index' || key === 'interface') {
 		return; // continue
-
+	    }
 	    drivestr += ',' + key + '=' + value;
 	});
 




More information about the pve-devel mailing list