/*
- * (c) 2005-2009 Richard Cowin (http://openrico.org)
- * (c) 2005-2009 Matt Brown (http://dowdybrown.com)
+ * (c) 2005-2011 Richard Cowin (http://openrico.org)
+ * (c) 2005-2011 Matt Brown (http://dowdybrown.com)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at
if (!Rico.Buffer) Rico.Buffer = {};
-Rico.Buffer.AjaxXML = function(url,options,ajaxOptions) {
+Rico.Buffer.AjaxLoadOnce = function(url,options,ajaxOptions) {
this.initialize(url,options,ajaxOptions);
}
-Rico.Buffer.AjaxXML.prototype = {
+Rico.Buffer.AjaxLoadOnce.prototype = {
/**
* @class Implements buffer for LiveGrid. Loads data from server via a single AJAX call.
* @extends Rico.Buffer.Base
Rico.Buffer.AjaxXMLMethods = {
-/** @lends Rico.Buffer.AjaxXML# */
+/** @lends Rico.Buffer.AjaxLoadOnce# */
fetch: function(offset) {
if (this.fetchData) {
this.foundRowCount=true;
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 {
page_size: (typeof fetchSize=='number') ? fetchSize : this.totalRows,
offset: startPos.toString()
};
- if (!this.foundRowCount) queryHash['get_total']='true';
+ queryHash[this.liveGrid.actionId]="query";
if (this.options.requestParameters) {
for ( var i=0; i < this.options.requestParameters.length; i++ ) {
var anArg = this.options.requestParameters[i];
delete this.timeoutHandler;
},
- // used by both XML and SQL buffers
- jsUpdate: function(startPos, newRows, newAttr, totalRows, errMsg) {
+ // used by both LoadOnce and SQL buffers
+ jsUpdate: function(startPos, newRows, newStyle, totalRows, errMsg) {
this.clearTimer();
this.processingRequest=false;
Rico.log("jsUpdate: "+arguments.length);
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);
}
},
- // used by both XML and SQL buffers
+ // used by both LoadOnce and SQL buffers
ajaxUpdate: function(startPos,xhr) {
this.clearTimer();
this.processingRequest=false;
this.liveGrid.showMsg(Rico.getPhraseById("httpError",xhr.status));
return;
}
+ Rico.log("ajaxUpdate: startPos="+startPos);
this._responseHandler=this['processResponse'+this.options.fmt.toUpperCase()];
if (!this._responseHandler(startPos,xhr)) return;
if (this.options.onAjaxUpdate)
}
},
- // used by both XML and SQL buffers
+ // used by both LoadOnce and SQL buffers
processResponseXML: function(startPos,request) {
// The response text may contain META DATA for debugging if client side debugging is enabled in VS\r
var xmlDoc = request.responseXML;\r
// 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];
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) {
+ 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) {
}
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) {
+ // specific to LoadOnce buffer
+ 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;
this.startPos = 0;
},
- // used by both XML and SQL buffers
+ // used by both LoadOnce and SQL buffers
updateGrid: function(offset) {
Rico.log("updateGrid, size="+this.size+' rcv cnt type='+typeof(this.rowcntContent));
var newpos;
this.setTotalRows(eofrow);
newpos=Math.min(this.liveGrid.topOfLastPage(),offset);
Rico.log("updateGrid: new rowcnt="+eofrow+" newpos="+newpos);
- if (lastTotalRows==0 && this.liveGrid.sizeTo=='data')
- Rico.runLater(100,this.liveGrid,'adjustPageSize'); // FF takes a long time to calc initial size
this.liveGrid.scrollToRow(newpos);
if ( this.isInRange(newpos) ) {
this.liveGrid.refreshContents(newpos);
Rico.Buffer.AjaxSQL.prototype = {
/**
* @class Implements buffer for LiveGrid. Loads data from server in chunks as user scrolls through the grid.
- * @extends Rico.Buffer.AjaxXML
+ * @extends Rico.Buffer.AjaxLoadOnce
* @constructs
*/
initialize: function(url,options,ajaxOptions) {
- Rico.extend(this, new Rico.Buffer.AjaxXML());
+ Rico.extend(this, new Rico.Buffer.AjaxLoadOnce());
Rico.extend(this, Rico.Buffer.AjaxSQLMethods);
this.dataSource=url;
this.options.canFilter=true;
this.options.largeBufferSize = 7.0; // 7 pages
this.options.nearLimitFactor = 1.0; // 1 page
+ this.options.canRefresh=true;
Rico.extend(this.options, options || {});
Rico.extend(this.ajaxOptions, ajaxOptions || {});
}
this.pendingRequest=offset;
return;
}
- if (offset < 0) {
+ if ((typeof offset == 'undefined') || (offset < 0)) {
this.clear();
this.setTotalRows(0);
this.foundRowCount = false;
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);
}
},
formQueryHashSQL: function(startPos,fetchSize,fmt) {
var queryHash=this.formQueryHashXML(startPos,fetchSize);
- queryHash[this.liveGrid.actionId]="query";
+ if (!this.foundRowCount) queryHash['get_total']='true';
if (fmt) queryHash._fmt=fmt;
// sort
queryHash['f['+colnum+'][len]']=c.filterValues.length;
for (var i=0; i<c.filterValues.length; i++) {
var fval=c.filterValues[i];
- if (c.filterOp=='LIKE' && fval.indexOf('*')==-1) fval='*'+fval+'*';
+ if (c.filterOp=='LIKE' && fval.indexOf('*')==-1) {
+ if (c.format.filterUI.charAt(1) == '^') fval=fval+'*';
+ else if (c.format.filterUI.charAt(1) == '$') fval='*'+fval;
+ else fval='*'+fval+'*';
+ }
queryHash['f['+colnum+']['+i+']']=fval;
}
}
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 && newStyle) 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);
}
} 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;
}
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);