[richfaces-svn-commits] JBoss Rich Faces SVN: r1091 - trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/common/utils.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Jun 8 03:44:11 EDT 2007


Author: maksimkaszynski
Date: 2007-06-08 03:44:11 -0400 (Fri, 08 Jun 2007)
New Revision: 1091

Modified:
   trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/common/utils/Utils.js
Log:
now update rows is possible

Modified: trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/common/utils/Utils.js
===================================================================
--- trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/common/utils/Utils.js	2007-06-07 22:46:35 UTC (rev 1090)
+++ trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/common/utils/Utils.js	2007-06-08 07:44:11 UTC (rev 1091)
@@ -1,71 +1,101 @@
-var AjaxUpdater = {
+var Utils = {
 	
-	updateTr:function(trObj, innerHTML){
-		if(trObj) {
-			if(ClientUILib.isIE) {
-				var theDoc = document;
-				var createEl = theDoc.createElement;
-				var tds = [];
-				var i = 0;
-				var pattern = '(?:<td.*?>)((\n|\r|.)*?)(?:<\/td>)';
-				var rez = innerHTML.gsub(pattern, function(item) {
-							             tds[i++] = item[1];
-						                 return "";  });
+	DOM: {
+		
+		importNode: function(node, bKids) {
+			
+			var nodeName = node.nodeName.toUpperCase();
+	
+			switch(nodeName) {
+				case "TBODY":
+				case "TR":
+				case "TD":  
+					{
+						var imported = document.createElement(nodeName);
+						
+						this.copyAttributes(imported, node);
+						
+						if (bKids) {
 							
-				var row = trObj.cloneNode(false);
-				var count = i, td;
-				for(i=0; i< count; i++) {
-					td = createEl("TD");
-					td.innerHTML = tds[i];
-					td.className = "ClientUI_Grid_BC";
-					row.insertBefore(td, null);
-			 	}
-				trObj.parentNode.replaceChild(row, trObj);
-			}else {
-				trObj.innerHTML = innerHTML;
+							for(var kid = node.firstChild; kid; 
+								kid = kid.nextSibling) {
+								
+								var importedKid = this.importNode(kid, true);
+								
+								imported.appendChild(importedKid);
+							}
+						}
+						return imported;
+					}
+				default: 
+					return (document.importNode(node, bKids));
 			}
-		}
-	},
-	
-	updateRows: function(options,request,grid,clientid){
-		var theDoc = document;
-		var getEl = theDoc.getElementById; 
-		var localOptions = options;
-		var rowCount = grid.getBody().templFrozen.getElement().rows.length;
-		var startRow = localOptions.startRow;
-		var count = localOptions.count;
-		var row, id, rowindex, i, el;
-		var dataModel = grid.dataModel;
-		var baseid = clientid;
+		},
 		
-		for(i=0; i<count; i++) {
-			rowindex = startRow + i;
-			if(rowindex >= rowCount){
-				 rowindex -= rowCount;
-			}	 
+		copyAttributes : function(target, source) {
 			
-			id = baseid + ":f:" + rowindex;
-			row = request.getElementById(id);
-						
-			if(ClientUILib.isIE) {
-				el = getEl(id);
-				this.updateTr(el,row.xml);
-			}else {
-				el = theDoc.getElementById(id);
-				this.updateTr(el,row.innerHTML);
+			var attrs = source.attributes;
+			
+			for(var i = 0 ; i < attrs.length; i++) {
+			
+				var attributeNode = attrs[i];
+				
+				if(attributeNode.specified) {
+					
+					var newAttributeNode = 
+						document.createAttribute(attributeNode.nodeName);
+					
+					newAttributeNode.nodeValue = attributeNode.nodeValue;
+					target.setAttributeNode(newAttributeNode);
+				}
+				
 			}
 			
-			id = baseid + ":n:" + rowindex;
-			row = request.getElementById(id);
-			if(ClientUILib.isIE) {
-				el = getEl(id);
-				this.updateTr(el,row.xml);
-			}else {
-				el = theDoc.getElementById(id);
-				this.updateTr(el,row.innerHTML);
-			}
+		},
+		
+		replaceNode : function(id, request) {
+			var target = document.getElementById(id);
+			var src = request.getElementById(id);
+			
+			var importProvider = ClientUILib.isIE ? this : document;
+			
+			src = importProvider.importNode(src, true);
+			
+			target.parentNode.replaceChild(src, target);
+			
 		}
+	},
 
-		dataModel.eventDataReady.fire(localOptions);
+	AJAX : {
+		updateRows: function(options,request,grid,clientid){
+			var theDoc = document;
+			var getEl = theDoc.getElementById; 
+			var localOptions = options;
+			var rowCount = grid.getBody().templFrozen.getElement().rows.length;
+			var startRow = localOptions.startRow;
+			var count = localOptions.count;
+			var row, id, rowindex, i, el;
+			var dataModel = grid.dataModel;
+			var baseid = clientid;
+			
+			for(i=0; i<count; i++) {
+				rowindex = startRow + i;
+				if(rowindex >= rowCount){
+					 rowindex -= rowCount;
+				}	 
+				
+				id = baseid + ":f:" + rowindex;
+				
+				Utils.DOM.replaceNode(id, request);
+				
+				id = baseid + ":n:" + rowindex;
+	
+				Utils.DOM.replaceNode(id, request);
+			}
+	
+			dataModel.eventDataReady.fire(localOptions);
+		}	
 	}
+		
+
 }
\ No newline at end of file




More information about the richfaces-svn-commits mailing list