X-Git-Url: https://git.infodrom.org/?p=infodrom%2Frico3;a=blobdiff_plain;f=minsrc%2FricoLiveGridAjax.js;h=14d345ceaa87b50a2c03a3e31605f864cf1518d0;hp=01b69213dc151c40ea2835c246059bff3ebd7b4d;hb=ab25f937447080ebaca56778f6e62ad22b9d8cc8;hpb=b07d1369594a42d62f8054a07ae1162ee1d928ee diff --git a/minsrc/ricoLiveGridAjax.js b/minsrc/ricoLiveGridAjax.js index 01b6921..14d345c 100644 --- a/minsrc/ricoLiveGridAjax.js +++ b/minsrc/ricoLiveGridAjax.js @@ -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 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; @@ -405,7 +426,7 @@ Rico.Buffer.AjaxSQLMethods = { this.pendingRequest=offset; return; } - if (offset < 0) { + if ((typeof offset == 'undefined') || (offset < 0)) { this.clear(); this.setTotalRows(0); this.foundRowCount = false; @@ -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); @@ -517,11 +538,15 @@ Rico.Buffer.AjaxSQLMethods = { } } else { //prepending if (start + newRows.length < this.startPos) { - this.rows = newRows; + this.rows = newRows; + this.attr = newStyle; } else { this.rows = newRows.slice(0, this.startPos).concat(this.rows); - if (this.maxBufferSize && this.rows.length > this.maxBufferSize) + if (newStyle) this.attr = newStyle.slice(0, this.startPos).concat(this.attr); + if (this.maxBufferSize && this.rows.length > this.maxBufferSize) { this.rows = this.rows.slice(0, this.maxBufferSize); + if (this.attr) this.attr = this.attr.slice(0, this.maxBufferSize); + } } this.startPos = start; } @@ -563,7 +588,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);