[Zope3-checkins] CVS: Zope3/src/zope/app/browser/skins/rotterdam - xmltree.js:1.4

Godefroid Chapelle gotcha@swing.be
Sat, 28 Dec 2002 17:28:33 -0500


Update of /cvs-repository/Zope3/src/zope/app/browser/skins/rotterdam
In directory cvs.zope.org:/tmp/cvs-serv2230

Modified Files:
	xmltree.js 
Log Message:
second step of refactoring to use OO Javascript


=== Zope3/src/zope/app/browser/skins/rotterdam/xmltree.js 1.3 => 1.4 ===
--- Zope3/src/zope/app/browser/skins/rotterdam/xmltree.js:1.3	Sat Dec 28 13:44:01 2002
+++ Zope3/src/zope/app/browser/skins/rotterdam/xmltree.js	Sat Dec 28 17:28:32 2002
@@ -52,14 +52,19 @@
 
 navigationTreeNode.prototype.collapse = function() {
  	this.isCollapsed = 1;
-        changeExpandIcon(this.domNode, "pl.gif"); 
+        this.changeExpandIcon("pl.gif"); 
 }
 
 navigationTreeNode.prototype.expand = function() {
  	this.isCollapsed = 0;
-        changeExpandIcon(this.domNode, "mi.gif"); 
+        this.changeExpandIcon("mi.gif"); 
 }
 
+navigationTreeNode.prototype.changeExpandIcon = function(icon) {
+        var expand = this.domNode.getElementsByTagName('expand')[0];
+        expand.style.backgroundImage = 'url("' + baseurl + '@@/' + icon + '")';
+        }
+
 navigationTreeNode.prototype.getNodeByName = function(name) {
         var numchildren = this.childNodes.length;
         if (name == this.name) {
@@ -76,6 +81,49 @@
         return null;
 }
 
+navigationTreeNode.prototype.toggleExpansion = function() {
+with (this) {
+        prettydump('toggleExpansion', LG_TRACE);
+        // If this collection is empty, load it from server
+        // todo xxx optimize for the case where collection has null length
+        var elem = domNode;
+        if (isEmpty) {
+                var url = baseurl + name + XML_CHILDREN_VIEW;
+                var data = loadtreexml(url);
+                addNavigationTreeNodes(data, this, 0);
+                isEmpty = 0;
+                }
+        if (isCollapsed) {
+	 	expand();
+                showChildren();
+   		}
+        else {
+                collapse();
+                hideChildren();
+   		}
+        }
+} 
+
+navigationTreeNode.prototype.hideChildren = function() {
+with (this) {
+        prettydump('hideChildren', LG_TRACE);
+        var num = childNodes.length;
+	for (var i = num - 1; i >=0; i--) {
+	        childNodes[i].domNode.style.display = 'none';
+        	}
+        }
+}
+
+navigationTreeNode.prototype.showChildren = function() {
+with (this) {
+        prettydump('showChildren', LG_TRACE);
+        var num = childNodes.length;
+	for (var i = num - 1; i >=0; i--) {
+	        childNodes[i].domNode.style.display = 'block';
+        	}
+        }
+}
+
 // utilities
 function prettydump(s, locallog) {
         // Put the string "s" in a box on the screen as an log message
@@ -139,61 +187,26 @@
 	return (elem.tagName.toUpperCase() == tagName);
 	}
 
-function toggleExpansion (navTreeNode) {
-	prettydump('toggleExpansion', LG_TRACE);
-        // If this collection is empty, load it from server
-        // todo xxx optimize for the case where collection has null length
-        var elem = navTreeNode.domNode;
-        if (navTreeNode.isEmpty) {
-                var url = baseurl + navTreeNode.name + XML_CHILDREN_VIEW;
-                var data = loadtreexml(url);
-                addNavigationTreeNodes(data, navTreeNode, 0);
-                navTreeNode.isEmpty = 0;
-                }
-        if (navTreeNode.isCollapsed) {
-	 	navTreeNode.expand();
-                showChildren(elem);
-   		}
-        else {
-                navTreeNode.collapse();
-                hideChildren(elem);
-   		}
-        } 
-
-function hideChildren(elem) {
-        prettydump('hideChildren', LG_TRACE);
-        var collections = elem.getElementsByTagName('collection');
-        var num = collections.length;
-	for (var i = num - 1; i >=0; i--) {
-	        collections[i].style.display = 'none';
-        	}
-        }
+function getCollectionChildNodes(xmlDomElem) {
+        // get collection element nodes among childNodes of elem
+        var result = new Array();
+        
+        var items = xmlDomElem.childNodes;
+        var numitems = items.length;
+        var currentItem;
+        for (var i = 0; i < numitems; i++) {
+                currentItem = items[i];
 
-function showChildren(elem) {
-        prettydump('showChildren', LG_TRACE);
-        var collections = elem.getElementsByTagName('collection');
-        var num = collections.length;
-        for (var i = num - 1; i >=0; i--) {
-                var parentColl = getParentCollection(collections[i]);
-                var parentNavTreeNode = navigationTree.getNodeByName(parentColl.getAttribute('name'));
-                if (! (parentNavTreeNode.isCollapsed)) {
-                        collections[i].style.display = 'block';
+                if (currentItem.nodeType != ELEMENT_NODE) {
+                        continue;
                         }
-                }
-        }
 
-function getParentCollection(elem) {
-        if (elem.getAttribute('isroot') != null) {
-                throw "Root collection has no parent collection"; 
-                }
-        else {
-                return elem.parentNode; 
+                if (!isCollection(currentItem)) {
+                        continue;
+                        }
+                result.push(currentItem);
                 }
-        }
-
-function changeExpandIcon(elem, icon) {
-        var expand = elem.getElementsByTagName('expand')[0];
-        expand.style.backgroundImage = 'url("' + baseurl + '@@/' + icon + '")';
+        return result;
         }
 
 //events
@@ -232,7 +245,7 @@
                 //get collection node
                 elem = elem.parentNode;
                 var navTreeNode = navigationTree.getNodeByName(elem.getAttribute('name'));
-                toggleExpansion(navTreeNode);
+                navTreeNode.toggleExpansion();
                 }
         }
 
@@ -343,29 +356,7 @@
                 }
         }       
 
-function getCollectionChildNodes(elem) {
-        // get collection element nodes among childNodes of elem
-        var items = elem.childNodes;
-        var numitems = items.length;
-        var currentItem;
-        var result = new Array();
-        for (var i = 0; i < numitems; i++) {
-                currentItem = items[i];
-
-                if (currentItem.nodeType != ELEMENT_NODE) {
-                        continue;
-                        }
-
-                if (!isCollection(currentItem)) {
-                        continue;
-                        }
-                result.push(currentItem);
-                }
-        return result;
-        }
-
-
-function createPresentationNodes(title, icon_url) {
+function createPresentationNodes(title, icon_url, length) {
         // create nodes hierarchy for one collection (without children)
         
         // create elem for plus/minus icon
@@ -379,6 +370,7 @@
         var newtextnode = document.createTextNode(title);
         
         titleElem.appendChild(newtextnode);
+        titleElem.setAttribute('title', 'Contains ' + length + ' item(s)');
         
         iconElem.appendChild(titleElem);
 
@@ -405,13 +397,13 @@
         navTreeNode.setName(elemName);
         
         //could show number of child items
-        //var length = source.getAttribute('length');
+        var length = source.getAttribute('length');
         //elemTitle = elemTitle + '(' + length + ')';
         
         var icon_url = source.getAttribute('icon_url');  
 
         
-        var expandElem = createPresentationNodes(elemTitle, icon_url);
+        var expandElem = createPresentationNodes(elemTitle, icon_url, length);
         newelem.appendChild(expandElem);