.net server control is almost feature complete and functional. All .net examples...
[infodrom/rico3] / minsrc / ricoLiveGridAjax.js
index 01b6921..a1a3ccd 100644 (file)
@@ -64,7 +64,7 @@ Rico.Buffer.AjaxXMLMethods = {
         this.ajaxOptions.onComplete = function(xhr) { self.ajaxUpdate(offset,xhr); };
         new Rico.ajaxRequest(this.dataSource, this.ajaxOptions);
       } else {
-        this.ajaxOptions.onComplete = function(newRows, newAttr, totalRows, errMsg) { self.jsUpdate(offset, newRows, newAttr, totalRows, errMsg); };
+        this.ajaxOptions.onComplete = function(newRows, newStyle, totalRows, errMsg) { self.jsUpdate(offset, newRows, newStyle, totalRows, errMsg); };
         this.dataSource(this.ajaxOptions);
       }
     } else {
@@ -116,7 +116,7 @@ Rico.Buffer.AjaxXMLMethods = {
   },
 
   // used by both XML and SQL buffers
-  jsUpdate: function(startPos, newRows, newAttr, totalRows, errMsg) {
+  jsUpdate: function(startPos, newRows, newStyle, totalRows, errMsg) {
     this.clearTimer();
     this.processingRequest=false;
     Rico.log("jsUpdate: "+arguments.length);
@@ -132,7 +132,7 @@ Rico.Buffer.AjaxXMLMethods = {
       this.foundRowCount = true;
       Rico.log("jsUpdate: found RowCount="+this.rowcntContent);
     }
-    this.updateBuffer(startPos, newRows, newAttr);
+    this.updateBuffer(startPos, newRows, newStyle);
     if (this.options.onAjaxUpdate)
       this.options.onAjaxUpdate();
     this.updateGrid(startPos);
@@ -192,7 +192,11 @@ Rico.Buffer.AjaxXMLMethods = {
 
     // process children of <ajax-response>
     var response = xmlDoc.getElementsByTagName("ajax-response");
-    if (response == null || response.length != 1) return false;
+    if (response == null || response.length != 1) {
+      alert("Received invalid response from server");
+      return false;
+    }
+    Rico.log("Processing ajax-response");
     this.rcvdRows = 0;
     this.rcvdRowCount = false;
     var ajaxResponse=response[0];
@@ -225,12 +229,29 @@ Rico.Buffer.AjaxXMLMethods = {
     this.rcvdOffset = rowsElement.getAttribute("offset");
     Rico.log("ajaxUpdate: rcvdOffset="+this.rcvdOffset);
     var newRows = this.dom2jstable(rowsElement);
-    var newAttr = (this.options.acceptAttr.length > 0) ? this.dom2jstableAttr(rowsElement) : false;
+    var newStyle = (this.options.acceptStyle) ? this.dom2jstableStyle(rowsElement) : false;
     this.rcvdRows = newRows.length;
-    this.updateBuffer(startPos, newRows, newAttr);
+    this.updateBuffer(startPos, newRows, newStyle);
     return true;
   },
 
+  dom2jstableStyle: function(rowsElement,firstRow) {
+    var acceptStyle=this.options.acceptStyle;
+    Rico.log("dom2jstableStyle start");
+    var newRows = [];
+    var trs = rowsElement.getElementsByTagName("tr");
+    for ( var i=firstRow || 0; i < trs.length; i++ ) {
+      var row = [];
+      var cells = trs[i].getElementsByTagName("td");
+      for ( var j=0; j < cells.length ; j++ ) {
+        row[j]=cells[j].getAttribute('style') || '';
+      }
+      newRows.push( row );
+    }
+    Rico.log("dom2jstableStyle end");
+    return newRows;
+  },
+
   processResponseJSON: function(startPos,request) {
     var json = Rico.getJSON(request);
     if (!json || json == null) {
@@ -257,14 +278,14 @@ Rico.Buffer.AjaxXMLMethods = {
     }
 
     this.rcvdRows = json.rows.length;
-    this.updateBuffer(startPos, json.rows);
+    this.updateBuffer(startPos, json.rows, json.styles);
     return true;
   },
 
   // specific to XML buffer
-  updateBuffer: function(start, newRows, newAttr) {
+  updateBuffer: function(start, newRows, newStyle) {
     this.baseRows = newRows;
-    this.attr = newAttr;
+    this.attr = newStyle;
     Rico.log("updateBuffer: # of rows="+this.rcvdRows);
     this.rcvdRowCount=true;
     this.rowcntContent=this.rcvdRows;
@@ -442,7 +463,7 @@ Rico.Buffer.AjaxSQLMethods = {
       this.ajaxOptions.onComplete = function(xhr) { self.ajaxUpdate(bufferStartPos, xhr); };
       new Rico.ajaxRequest(this.dataSource, this.ajaxOptions);
     } else {
-      this.ajaxOptions.onComplete = function(newRows, newAttr, totalRows, errMsg) { self.jsUpdate(bufferStartPos, newRows, newAttr, totalRows, errMsg); };
+      this.ajaxOptions.onComplete = function(newRows, newStyle, totalRows, errMsg) { self.jsUpdate(bufferStartPos, newRows, newStyle, totalRows, errMsg); };
       this.dataSource(this.ajaxOptions);
     }
   },
@@ -494,20 +515,20 @@ Rico.Buffer.AjaxSQLMethods = {
     return adjustedOffset;
   },
 
-  updateBuffer: function(start, newRows, newAttr) {
+  updateBuffer: function(start, newRows, newStyle) {
     Rico.log("updateBuffer: start="+start+", # of rows="+this.rcvdRows);
     if (this.rows.length == 0) { // initial load
       this.rows = newRows;
-      this.attr = newAttr;
+      this.attr = newStyle;
       this.startPos = start;
     } else if (start > this.startPos) { //appending
       if (this.startPos + this.rows.length < start) {
         this.rows =  newRows;
-        this.attr = newAttr;
+        this.attr = newStyle;
         this.startPos = start;
       } else {
         this.rows = this.rows.concat( newRows.slice(0, newRows.length));
-        if (this.attr) this.attr = this.attr.concat( newAttr.slice(0, newAttr.length));
+        if (this.attr) this.attr = this.attr.concat( newStyle.slice(0, newStyle.length));
         if (this.rows.length > this.maxBufferSize) {
           var fullSize = this.rows.length;
           this.rows = this.rows.slice(this.rows.length - this.maxBufferSize, this.rows.length);
@@ -563,7 +584,7 @@ Rico.Buffer.AjaxSQLMethods = {
     this.dataSource(this.ajaxOptions);
   },
 
-  _jsExport: function(newRows, newAttr, totalRows, errMsg) {
+  _jsExport: function(newRows, newStyle, totalRows, errMsg) {
     Rico.log("_jsExport: "+arguments.length);
     if (errMsg) {
       Rico.log("_jsExport: received error="+errMsg);