Fix caret in filter specs
[infodrom/rico3] / minsrc / ricoLiveGridAjax.js
index a1a3ccd..d239546 100644 (file)
@@ -1,6 +1,6 @@
 /*
- *  (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
@@ -17,11 +17,11 @@ if(typeof Rico=='undefined') throw("LiveGridAjax requires the Rico JavaScript fr
 
 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
@@ -49,7 +49,7 @@ Rico.Buffer.AjaxXML.prototype = {
 
 Rico.Buffer.AjaxXMLMethods = {
 
-/** @lends Rico.Buffer.AjaxXML# */
+/** @lends Rico.Buffer.AjaxLoadOnce# */
   fetch: function(offset) {
     if (this.fetchData) {
       this.foundRowCount=true;
@@ -92,7 +92,7 @@ Rico.Buffer.AjaxXMLMethods = {
       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];
@@ -115,7 +115,7 @@ Rico.Buffer.AjaxXMLMethods = {
     delete this.timeoutHandler;
   },
 
-  // used by both XML and SQL buffers
+  // used by both LoadOnce and SQL buffers
   jsUpdate: function(startPos, newRows, newStyle, totalRows, errMsg) {
     this.clearTimer();
     this.processingRequest=false;
@@ -146,7 +146,7 @@ Rico.Buffer.AjaxXMLMethods = {
     }
   },
 
-  // used by both XML and SQL buffers
+  // used by both LoadOnce and SQL buffers
   ajaxUpdate: function(startPos,xhr) {
     this.clearTimer();
     this.processingRequest=false;
@@ -155,6 +155,7 @@ Rico.Buffer.AjaxXMLMethods = {
       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)
@@ -170,7 +171,7 @@ Rico.Buffer.AjaxXMLMethods = {
     }
   },
   
-  // 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
@@ -236,7 +237,6 @@ Rico.Buffer.AjaxXMLMethods = {
   },
 
   dom2jstableStyle: function(rowsElement,firstRow) {
-    var acceptStyle=this.options.acceptStyle;
     Rico.log("dom2jstableStyle start");
     var newRows = [];
     var trs = rowsElement.getElementsByTagName("tr");
@@ -282,7 +282,7 @@ Rico.Buffer.AjaxXMLMethods = {
     return true;
   },
 
-  // specific to XML buffer
+  // specific to LoadOnce buffer
   updateBuffer: function(start, newRows, newStyle) {
     this.baseRows = newRows;
     this.attr = newStyle;
@@ -295,7 +295,7 @@ Rico.Buffer.AjaxXMLMethods = {
     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;
@@ -307,8 +307,6 @@ Rico.Buffer.AjaxXMLMethods = {
         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);
@@ -341,16 +339,17 @@ Rico.Buffer.AjaxSQL = function(url,options,ajaxOptions) {
 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 || {});
   }
@@ -426,7 +425,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;
@@ -470,7 +469,7 @@ Rico.Buffer.AjaxSQLMethods = {
 
   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
@@ -485,7 +484,11 @@ Rico.Buffer.AjaxSQLMethods = {
       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;
       }
     }
@@ -528,7 +531,7 @@ Rico.Buffer.AjaxSQLMethods = {
         this.startPos = start;
       } else {
         this.rows = this.rows.concat( newRows.slice(0, newRows.length));
-        if (this.attr) this.attr = this.attr.concat( newStyle.slice(0, newStyle.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);
@@ -538,11 +541,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;
     }