[pve-devel] r6276 - pve-manager/pve2/www/manager/tree

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Jul 8 14:05:02 CEST 2011


Author: dietmar
Date: 2011-07-08 14:05:02 +0200 (Fri, 08 Jul 2011)
New Revision: 6276

Modified:
   pve-manager/pve2/www/manager/tree/ResourceTree.js
Log:
make lint happy


Modified: pve-manager/pve2/www/manager/tree/ResourceTree.js
===================================================================
--- pve-manager/pve2/www/manager/tree/ResourceTree.js	2011-07-08 11:39:17 UTC (rev 6275)
+++ pve-manager/pve2/www/manager/tree/ResourceTree.js	2011-07-08 12:05:02 UTC (rev 6276)
@@ -40,15 +40,17 @@
 	    var v1 = n1.type;
 	    var v2 = n2.type;
 
-	    if ((tcmp = v1 > v2 ? 1 : (v1 < v2 ? -1 : 0)) != 0)
+	    if ((tcmp = v1 > v2 ? 1 : (v1 < v2 ? -1 : 0)) != 0) {
 		return tcmp;
+	    }
 
 	    // numeric compare for VM IDs
 	    if (v1 === 'qemu' || v1 === 'openvz') {
 		v1 = n1.vmid;
 		v2 = n2.vmid;
-		if ((tcmp = v1 > v2 ? 1 : (v1 < v2 ? -1 : 0)) != 0)
+		if ((tcmp = v1 > v2 ? 1 : (v1 < v2 ? -1 : 0)) != 0) {
 		    return tcmp;
+		}
 	    }
 
 	    return n1.text > n2.text ? 1 : (n1.text < n2.text ? -1 : 0);
@@ -67,31 +69,33 @@
 
 	var mid = start + (diff>>1);
 
-	if (diff <= 0)
+	if (diff <= 0) {
 	    return start;
+	}
 
 	var res = me.nodeSortFn(child, node.childNodes[mid]);
-	if (res <= 0)
+	if (res <= 0) {
 	    return me.findInsertIndex(node, child, start, mid);
-	else
+	} else {
 	    return me.findInsertIndex(node, child, mid + 1, end);
+	}
     },
 
     // private
     addChildSorted: function(node, info) {
 	var me = this;
 
-	var statics = me.statics();
-	var defaults = statics.typeDefaults[info.type];
-	if (defaults && defaults.iconCls)
+	var defaults = PVE.tree.ResourceTree.typeDefaults[info.type];
+	if (defaults && defaults.iconCls) {
 	    info.iconCls = defaults.iconCls;
-
+	}
 	if (info.groupbyid) {
 	    info.text = info.groupbyid;	    
 	    if (info.type === 'type') {
-		defaults = statics.typeDefaults[info.groupbyid];
-		if (defaults && defaults.text)
+		defaults = PVE.tree.ResourceTree.typeDefaults[info.groupbyid];
+		if (defaults && defaults.text) {
 		    info.text = defaults.text;
+		}
 	    }
 	}
 	var child = Ext.ModelMgr.create(info, 'PVETree', info.id);
@@ -99,9 +103,7 @@
         var cs = node.childNodes;
 	var pos;
 	if (cs) {
-            var len = cs.length;
-            index = me.findInsertIndex(node, child, 0, len);
-	    pos = cs[index];
+	    pos = cs[me.findInsertIndex(node, child, 0, cs.length)];
 	}
 
 	//var expanded = node.isExpanded();
@@ -132,8 +134,9 @@
 			type: groupby,
 			id : groupby + "/" + v
 		    };
-		    if (groupby !== 'type')
+		    if (groupby !== 'type') {
 			groupinfo[groupby] = v;
+		    }
 		}
 		groupinfo.leaf = false;
 		groupinfo.groupbyid = v; 
@@ -141,10 +144,12 @@
 		// fixme: remove when EXTJS has fixed those bugs?!
 		group.expand(); group.collapse();
 	    }
-	    if (info.type === groupby)
+	    if (info.type === groupby) {
 		return group;
-	    if (group)
+	    }
+	    if (group) {
 		return me.groupChild(group, info, groups, level + 1);
+	    }
 	}
 
 	return me.addChildSorted(node, info);
@@ -156,8 +161,9 @@
 	var rstore = PVE.data.ResourceStore;
 	var sp = Ext.state.Manager.getProvider();
 
-	if (!me.viewFilter)
+	if (!me.viewFilter) {
 	    me.viewFilter = {};
+	}
 
 	var pdata = {
 	    dataIndex: {},
@@ -188,8 +194,9 @@
 	    var lastsel = sm.getSelection()[0];
 	    var parents = [];
 	    var p = lastsel;
-	    while(p && (p = p.parentNode))
+	    while (p && !!(p = p.parentNode)) {
 		parents.push(p);
+	    }
 
 	    var index = pdata.dataIndex;
 
@@ -197,71 +204,75 @@
 	    var filterfn = me.viewFilter.filterfn;
 
 	    // remove vanished or changed items
-	    for (var key in index) {
-		if (!index.hasOwnProperty(key))
-		    continue;
+	    var key;
+	    for (key in index) {
+		if (index.hasOwnProperty(key)) {
+		    var olditem = index[key];
 
-		var olditem = index[key];
+		    // getById() use find(), which is slow (ExtJS4 DP5) 
+		    //var item = rstore.getById(olditem.data.id);
+		    var item = rstore.data.get(olditem.data.id);
 
-		// getById() use find(), which is slow (ExtJS4 DP5) 
-		//var item = rstore.getById(olditem.data.id);
-		var item = rstore.data.get(olditem.data.id);
-
-		var changed = false;
-		if (item) {
-		    // test if any grouping attributes changed
-		    for (var i = 0, len = groups.length; i < len; i++) {
-			var attr = groups[i];
-			if (item.data[attr] != olditem.data[attr]) {
-			    //console.log("changed " + attr);
+		    var changed = false;
+		    if (item) {
+			// test if any grouping attributes changed
+			var i, len;
+			for (i = 0, len = groups.length; i < len; i++) {
+			    var attr = groups[i];
+			    if (item.data[attr] != olditem.data[attr]) {
+				//console.log("changed " + attr);
+				changed = true;
+				break;
+			    }
+			}
+			if (item.data.text != olditem.data.text) {
+			    //console.log("changed text");
 			    changed = true;
-			    break;
 			}
+
+			// fixme: also test filterfn()?
 		    }
-		    if (item.data.text != olditem.data.text) {
-			//console.log("changed text");
-			changed = true;
+
+		    if (!item || changed) {
+			//console.log("REM UID: " + key + " ITEM " + olditem.data.id);
+			delete index[key];
+			var parentNode = olditem.parentNode;
+			//var expanded = parentNode.isExpanded();
+			//if (expanded)
+			//parentNode.collapse();		    
+			parentNode.removeChild(olditem, true);
+			//if (expanded) 
+			//parentNode.expand();
 		    }
-
-		    // fixme: also test filterfn()?
 		}
-
-		if (!item || changed) {
-		    //console.log("REM UID: " + key + " ITEM " + olditem.data.id);
-		    delete index[key];
-		    var parentNode = olditem.parentNode;
-		    //var expanded = parentNode.isExpanded();
-		    //if (expanded)
-		    //parentNode.collapse();		    
-		    parentNode.removeChild(olditem, true);
-		    //if (expanded) 
-		    //parentNode.expand();
-		}
 	    }
 
- 	    // add new items
+	    // add new items
             rstore.each(function(item) {
 		var olditem = index[item.data.id];
-		if (olditem)
+		if (olditem) {
 		    return;
+		}
 
-		if (filterfn && !filterfn(item))
+		if (filterfn && !filterfn(item)) {
 		    return;
+		}
 
 		//console.log("ADD UID: " + item.data.id);
 
 		var info = Ext.apply({ leaf: true }, item.data);
 
 		var child = me.groupChild(rootnode, info, groups, 0);
-		if (child)
+		if (child) {
 		    index[item.data.id] = child;
+		}
 	    });
 
 	    // select parent node is selection vanished
 	    if (lastsel && !rootnode.findChild('id', lastsel.data.id, true)) {
 		lastsel = rootnode;
-		while (p = parents.shift()) {
-		    if (tmp = rootnode.findChild('id', p.data.id, true)) {
+		while (!!(p = parents.shift())) {
+		    if (!!(tmp = rootnode.findChild('id', p.data.id, true))) {
 			lastsel = tmp;
 			break;
 		    }
@@ -293,7 +304,7 @@
             title: 'Resource Tree',
 	    listeners: {
 		destroy: function() {
-		    rstore.un("load", updateTree)
+		    rstore.un("load", updateTree);
 		}
 	    },
 	    setViewFilter: function(view) {
@@ -313,17 +324,19 @@
 		var rootnode = me.store.getRootNode();
 		var sm = me.getSelectionModel();
 		var node;
-		if (nodeid === 'root')
+		if (nodeid === 'root') {
 		    node = rootnode;
-		else
+		} else {
 		    node = rootnode.findChild('id', nodeid, true);
+		}
 		if (node) {
 		    if (!sm.isSelected(node)) {
 			sm.select(node);
 			var cn = node;
-			while ((cn = cn.parentNode)) {
-			    if (!cn.isExpanded())
+			while (!!(cn = cn.parentNode)) {
+			    if (!cn.isExpanded()) {
 				cn.expand();
+			    }
 			}
 		    }
 		}
@@ -332,7 +345,7 @@
 		var sm = me.getSelectionModel();
 		if (state && state.value) {
 		    me.selectById(state.value);
- 		} else {
+		} else {
 		    sm.deselectAll();
 		}
 	    }



More information about the pve-devel mailing list