1 function TreeTable(tableid, querystr){
  2 	this.rowsLoaded = {};
  3 	if ( !querystr ){
  4 		querystr = window.location.search;
  5 	}
  6 	this.table = document.getElementById(tableid);
  7 	this.collapseAllRows();
  8 }
  9 
 10 /**
 11  * This Tree table code was taken from Super Simple JavaScript Tree 
 12  * at http://sstree.tigris.org/ unsed under the Apache license available
 13  * at http://www.apache.org/licenses/LICENSE-2.0.txt
 14  */
 15 TreeTable.prototype.toggleRows = function(elm) {
 16  var rows = this.table.getElementsByTagName("TR");
 17  elm.style.backgroundImage = "url("+DATAFACE_URL+"/images/folder-closed.gif)";
 18  var newDisplay = "none";
 19  var thisID = elm.parentNode.parentNode.parentNode.id + "-";
 20  // Are we expanding or contracting? If the first child is hidden, we expand
 21   for (var i = 0; i < rows.length; i++) {
 22    var r = rows[i];
 23    if (this.matchStart(r.id, thisID, true)) {
 24     if (r.style.display == "none") {
 25      if (document.all) newDisplay = "block"; //IE4+ specific code
 26      else newDisplay = "table-row"; //Netscape and Mozilla
 27      elm.style.backgroundImage = "url("+DATAFACE_URL+"/images/folder-open.gif)";
 28     }
 29     break;
 30    }
 31  }
 32  
 33  // When expanding, only expand one level.  Collapse all desendants.
 34  var matchDirectChildrenOnly = (newDisplay != "none");
 35 
 36  for (var j = 0; j < rows.length; j++) {
 37    var s = rows[j];
 38    if (this.matchStart(s.id, thisID, matchDirectChildrenOnly)) {
 39      s.style.display = newDisplay;
 40      var cell = s.getElementsByTagName("TD")[0];
 41      var tier = cell.getElementsByTagName("DIV")[0];
 42      var folder = tier.getElementsByTagName("A")[0];
 43      if (folder.getAttribute("onclick") != null) {
 44       folder.style.backgroundImage = "url("+DATAFACE_URL+"/images/folder-closed.gif)";
 45      }
 46    }
 47  }
 48 }
 49 
 50 TreeTable.prototype.matchStart = function(target, pattern, matchDirectChildrenOnly) {
 51  var pos = target.indexOf(pattern);
 52  if (pos != 0) return false;
 53  if (!matchDirectChildrenOnly) return true;
 54  if (target.slice(pos + pattern.length, target.length).indexOf("-") >= 0) return false;
 55  return true;
 56 }
 57 
 58 
 59 TreeTable.prototype.collapseAllRows = function() {
 60  var rows = document.getElementsByTagName("TR");
 61  for (var j = 0; j < rows.length; j++) {
 62    var r = rows[j];
 63    if (r.id.indexOf("-") >= 0) {
 64      r.style.display = "none";    
 65    }
 66  }
 67 }
 68 
 69 
 70 
 71 function TreeTable_loadSubrows(rowid, visible){
 72 	if ( !this.rowsLoaded[rowid] ){
 73 		// the row is not loaded yet.. let's make the http request to load the
 74 		// rows
 75 		var url = DATAFACE_SITE_HREF+
 76 					'?-action=ajax_load_tree_table_rows&-table='+this.queryStr+
 77 					'&-rowid='+escape(rowid);
 78 		var http = getHTTPObject();
 79 		http.handleLoadSubrows = this.handleLoadSubrows;	// this will be the handler
 80 		http.treeTable = this; // maintain a link to this treetable object for the handler
 81 		http.rowid = rowid; 	// the id of the row after which the subrows will be added
 82 		http.visible = visible;
 83 		
 84 		http.open("GET", url);
 85 		http.onreadystatechange = this.handleLoadSubrows;
 86 		http.send(null);
 87 		
 88 	}
 89 }
 90 
 91 TreeTable.prototype.loadSubrows = TreeTable_loadSubrows;
 92 
 93 function TreeTable_handleLoadSubrows(){
 94 	if ( this.readystate == 4 ){
 95 		// the request has been processed
 96 		var rows = document.getElementsByTagName('TR');
 97 		var found = false;
 98 		var prevEl = null;
 99 		var nextEl = null;
100 		for ( var i=0; i<rows.length; i++ ){
101 			var r = rows[i];
102 			if ( r.id == this.rowid ){
103 				// we have found our insertion point.
104 				prevEl = r;
105 			}
106 			if ( prevEl ){
107 				nextEl = r;
108 				break;
109 			}
110 		}
111 		var frag = document.createDocumentFragment();
112 		frag.innerHTML = http.responseText;
113 		
114 		if ( nextEl ){
115 			nextEl.parentNode.insertBefore(nextEl,frag);
116 		} else {
117 			prevEl.parentNode.appendChild(frag);
118 		}
119 	}
120 }
121 TreeTable.prototype.handleLoadSubrows = TreeTable_handleLoadSubrows;
122 TreeTable.prototype.trees = {};
123 
124 
125 function validateTTForm(form){
126 	for (var i=0; i<form.elements.length; i++ ){
127 		var e = form.elements[i];
128 		if ( (e.name == '--remkeys[]') && (e.type == 'checkbox') && e.checked ){
129 			return true;
130 		}
131 	}
132 	alert("No records are selected.  Please click the checkbox next to the record on which you wish to perform this action.");
133 	return false;
134 
135 }
136 
137 
138