Updated Rico 2 and Rico 3 with all patches submitted on Sourceforge.
[infodrom/rico3] / minsrc / ricoLiveGrid.js
index 6a5ef63..d550aaf 100644 (file)
@@ -43,11 +43,12 @@ Rico.Buffer.Base.prototype = {
       fixedHdrRows     : 0,
       canFilter        : true,  // does buffer object support filtering?
       isEncoded        : true,  // is the data received via ajax html encoded?
       fixedHdrRows     : 0,
       canFilter        : true,  // does buffer object support filtering?
       isEncoded        : true,  // is the data received via ajax html encoded?
-      acceptAttr       : []     // attributes that can be copied from original/ajax data (e.g. className, style, id)
+      acceptStyle      : false  // copy style from original/ajax data?
     };
     Rico.extend(this.options, options || {});
     if (dataTable) {
       this.loadRowsFromTable(dataTable,this.options.fixedHdrRows);
     };
     Rico.extend(this.options, options || {});
     if (dataTable) {
       this.loadRowsFromTable(dataTable,this.options.fixedHdrRows);
+      dataTable.parentNode.removeChild(dataTable);  // delete the data once it has been loaded
     } else {
       this.clear();
     }
     } else {
       this.clear();
     }
@@ -77,10 +78,10 @@ Rico.Buffer.Base.prototype = {
   },
 
   loadRowsFromTable: function(tableElement,firstRow) {
   },
 
   loadRowsFromTable: function(tableElement,firstRow) {
-    var newRows = new Array();
+    var newRows = [];
     var trs = tableElement.getElementsByTagName("tr");
     for ( var i=firstRow || 0; i < trs.length; i++ ) {
     var trs = tableElement.getElementsByTagName("tr");
     for ( var i=firstRow || 0; i < trs.length; i++ ) {
-      var row = new Array();
+      var row = [];
       var cells = trs[i].getElementsByTagName("td");
       for ( var j=0; j < cells.length ; j++ )
         row[j]=cells[j].innerHTML;
       var cells = trs[i].getElementsByTagName("td");
       for ( var j=0; j < cells.length ; j++ )
         row[j]=cells[j].innerHTML;
@@ -106,10 +107,10 @@ Rico.Buffer.Base.prototype = {
 
   dom2jstable: function(rowsElement) {
     Rico.log('dom2jstable: encoded='+this.options.isEncoded);
 
   dom2jstable: function(rowsElement) {
     Rico.log('dom2jstable: encoded='+this.options.isEncoded);
-    var newRows = new Array();
+    var newRows = [];
     var trs = rowsElement.getElementsByTagName("tr");
     for ( var i=0; i < trs.length; i++ ) {
     var trs = rowsElement.getElementsByTagName("tr");
     for ( var i=0; i < trs.length; i++ ) {
-      var row = new Array();
+      var row = [];
       var cells = trs[i].getElementsByTagName("td");
       for ( var j=0; j < cells.length ; j++ )
         row[j]=Rico.getContentAsString(cells[j],this.options.isEncoded);
       var cells = trs[i].getElementsByTagName("td");
       for ( var j=0; j < cells.length ; j++ )
         row[j]=Rico.getContentAsString(cells[j],this.options.isEncoded);
@@ -118,26 +119,6 @@ Rico.Buffer.Base.prototype = {
     return newRows;
   },
 
     return newRows;
   },
 
-  dom2jstableAttr: function(rowsElement,firstRow) {
-    var acceptAttr=this.options.acceptAttr;
-    Rico.log("dom2jstableAttr start, # attr="+acceptAttr.length);
-    var newRows = new Array();
-    var trs = rowsElement.getElementsByTagName("tr");
-    for ( var i=firstRow || 0; i < trs.length; i++ ) {
-      var row = new Array();
-      var cells = trs[i].getElementsByTagName("td");
-      for ( var j=0; j < cells.length ; j++ ) {
-        row[j]={};
-        for (var k=0; k<acceptAttr.length; k++)
-          row[j]['_'+acceptAttr[k]]=cells[j].getAttribute(acceptAttr[k]);
-        if (Rico.isIE) row[j]._class=cells[j].getAttribute('className');
-      }
-      newRows.push( row );
-    }
-    Rico.log("dom2jstableAttr end");
-    return newRows;
-  },
-
   _blankRow: function() {
     var newRow=[];
     for (var i=0; i<this.liveGrid.columns.length; i++) {
   _blankRow: function() {
     var newRow=[];
     for (var i=0; i<this.liveGrid.columns.length; i++) {
@@ -291,9 +272,9 @@ Rico.Buffer.Base.prototype = {
     return this.isVisible(bufrow) && col < this.rows[bufrow].length ? this.rows[bufrow][col] : null;
   },
 
     return this.isVisible(bufrow) && col < this.rows[bufrow].length ? this.rows[bufrow][col] : null;
   },
 
-  getWindowAttr: function(windowRow,col) {
+  getWindowStyle: function(windowRow,col) {
     var bufrow=this.bufferRow(windowRow);
     var bufrow=this.bufferRow(windowRow);
-    return this.attr && this.isVisible(bufrow) && col < this.attr[bufrow].length ? this.attr[bufrow][col] : null;
+    return this.attr && this.isVisible(bufrow) && this.attr[bufrow] && col < this.attr[bufrow].length ? this.attr[bufrow][col] : '';
   },
 
   getWindowValue: function(windowRow,col) {
   },
 
   getWindowValue: function(windowRow,col) {
@@ -326,7 +307,7 @@ Rico.Buffer.Base.prototype = {
   getRows: function(start, count) {
     var begPos = start - this.startPos;
     var endPos = Math.min(begPos + count,this.size);
   getRows: function(start, count) {
     var begPos = start - this.startPos;
     var endPos = Math.min(begPos + count,this.size);
-    var results = new Array();
+    var results = [];
     for ( var i=begPos; i < endPos; i++ ) {
       results.push(this.rows[i]);
     }
     for ( var i=begPos; i < endPos; i++ ) {
       results.push(this.rows[i]);
     }
@@ -554,8 +535,8 @@ Rico.LiveGrid.prototype = {
 
     this.bookmark=document.getElementById(this.tableId+"_bookmark");
     this.sizeDivs();
 
     this.bookmark=document.getElementById(this.tableId+"_bookmark");
     this.sizeDivs();
-    var filterUIrow=this.buffer.options.canFilter ? this.options.FilterLocation : false;
-    if (typeof(filterUIrow)=='number' && filterUIrow<0)
+    var filterUIrow=-1;
+    if (this.buffer.options.canFilter && this.options.AutoFilter)
       filterUIrow=this.addHeadingRow('ricoLG_FilterRow');
     this.createDataCells(this.options.visibleRows);
     if (this.pageSize == 0) return;
       filterUIrow=this.addHeadingRow('ricoLG_FilterRow');
     this.createDataCells(this.options.visibleRows);
     if (this.pageSize == 0) return;
@@ -580,7 +561,7 @@ Rico.LiveGrid.prototype = {
       this.scrollToRow(this.options.offset);
       this.buffer.fetch(this.options.offset);
     }
       this.scrollToRow(this.options.offset);
       this.buffer.fetch(this.options.offset);
     }
-    if (typeof(filterUIrow)=='number')
+    if (filterUIrow >= 0)
       this.createFilters(filterUIrow);
     this.scrollEventFunc=Rico.eventHandle(this,'handleScroll');
     this.wheelEventFunc=Rico.eventHandle(this,'handleWheel');
       this.createFilters(filterUIrow);
     this.scrollEventFunc=Rico.eventHandle(this,'handleScroll');
     this.wheelEventFunc=Rico.eventHandle(this,'handleWheel');
@@ -593,6 +574,13 @@ Rico.LiveGrid.prototype = {
     if (this.options.windowResize)
       Rico.runLater(100,this,'pluginWindowResize');
     Rico.log("initialize complete for "+this.tableId);
     if (this.options.windowResize)
       Rico.runLater(100,this,'pluginWindowResize');
     Rico.log("initialize complete for "+this.tableId);
+    //alert('clientLeft='+this.scrollDiv.clientLeft);
+    if (this.direction=='rtl' && (!Rico.isWebKit || this.scrollDiv.clientLeft > 0)) {
+      this.scrollTab.style.right='0px';
+    } else {
+      this.scrollTab.style.left='0px';
+      Rico.setStyle(this.tabs[1], {'float': 'left'});
+    }
   }
 };
 
   }
 };
 
@@ -662,7 +650,7 @@ Rico.LiveGridMethods = {
       var theads=table.getElementsByTagName("thead");
       if (theads.length == 1) {
         Rico.log("createTables: using thead section, id="+this.tableId);
       var theads=table.getElementsByTagName("thead");
       if (theads.length == 1) {
         Rico.log("createTables: using thead section, id="+this.tableId);
-        if (this.options.PanelNamesOnTabHdr && this.options.panels) {
+        if (this.options.ColGroupsOnTabHdr && this.options.ColGroups) {
           var r=theads[0].insertRow(0);
           this.insertPanelNames(r, 0, this.options.frozenColumns, 'ricoFrozen');
           this.insertPanelNames(r, this.options.frozenColumns, this.options.columnSpecs.length);
           var r=theads[0].insertRow(0);
           this.insertPanelNames(r, 0, this.options.frozenColumns, 'ricoFrozen');
           this.insertPanelNames(r, this.options.frozenColumns, this.options.columnSpecs.length);
@@ -722,7 +710,7 @@ Rico.LiveGridMethods = {
     // create new tables
     for (i=0; i<3; i++) {
       this.tabs[i] = document.createElement("table");
     // create new tables
     for (i=0; i<3; i++) {
       this.tabs[i] = document.createElement("table");
-      this.tabs[i].className = 'ricoLG_table';
+      this.tabs[i].className = (i < 2) ? 'ricoLG_table' : 'ricoLG_scrollTab';
       this.tabs[i].border=0;
       this.tabs[i].cellPadding=0;
       this.tabs[i].cellSpacing=0;
       this.tabs[i].border=0;
       this.tabs[i].cellPadding=0;
       this.tabs[i].cellSpacing=0;
@@ -731,8 +719,8 @@ Rico.LiveGridMethods = {
     // set headings
     for (i=0; i<2; i++) {
       this.thead[i]=this.tabs[i].createTHead();
     // set headings
     for (i=0; i<2; i++) {
       this.thead[i]=this.tabs[i].createTHead();
-      Rico.addClass(this.tabs[i],'ricoLG_top');
-      //this.thead[i].className='ricoLG_top';
+      //Rico.addClass(this.tabs[i],'ricoLG_top');
+      this.thead[i].className='ricoLG_top';
       if (Rico.theme.gridheader) Rico.addClass(this.thead[i],Rico.theme.gridheader);
     }
     // set bodies
       if (Rico.theme.gridheader) Rico.addClass(this.thead[i],Rico.theme.gridheader);
     }
     // set bodies
@@ -752,7 +740,7 @@ Rico.LiveGridMethods = {
     } else {
       this.createHdr(0,0,this.options.frozenColumns);
       this.createHdr(1,this.options.frozenColumns,this.options.columnSpecs.length);
     } else {
       this.createHdr(0,0,this.options.frozenColumns);
       this.createHdr(1,this.options.frozenColumns,this.options.columnSpecs.length);
-      if (this.options.PanelNamesOnTabHdr && this.options.panels) {
+      if (this.options.ColGroupsOnTabHdr && this.options.ColGroups) {
         this.insertPanelNames(this.thead[0].insertRow(0), 0, this.options.frozenColumns);
         this.insertPanelNames(this.thead[1].insertRow(0), this.options.frozenColumns, this.options.columnSpecs.length);
       }
         this.insertPanelNames(this.thead[0].insertRow(0), 0, this.options.frozenColumns);
         this.insertPanelNames(this.thead[1].insertRow(0), this.options.frozenColumns, this.options.columnSpecs.length);
       }
@@ -808,11 +796,11 @@ Rico.LiveGridMethods = {
       switch (fmt.filterUI.charAt(0)) {
         case 't':
           // text field
       switch (fmt.filterUI.charAt(0)) {
         case 't':
           // text field
-          field=Rico.createFormField(divs[1],'input','text',name,name);
+          field=Rico.createFormField(divs[1],'input',Rico.inputtypes.search ? 'search' : 'text',name,name);
           var size=fmt.filterUI.match(/\d+/);
           field.maxLength=fmt.Length || 50;\r
           field.size=size ? parseInt(size,10) : 10;
           var size=fmt.filterUI.match(/\d+/);
           field.maxLength=fmt.Length || 50;\r
           field.size=size ? parseInt(size,10) : 10;
-          divs[1].appendChild(Rico.clearButton(Rico.eventHandle(col,'filterClear')));
+          if (field.type != 'search') divs[1].appendChild(Rico.clearButton(Rico.eventHandle(col,'filterClear')));
           if (col.filterType==Rico.ColumnConst.USERFILTER && col.filterOp=='LIKE') {
             var v=col.filterValues[0];
             if (v.charAt(0)=='*') v=v.substr(1);
           if (col.filterType==Rico.ColumnConst.USERFILTER && col.filterOp=='LIKE') {
             var v=col.filterValues[0];
             if (v.charAt(0)=='*') v=v.substr(1);
@@ -954,15 +942,15 @@ Rico.LiveGridMethods = {
     r.className='ricoLG_hdg';
     var lastIdx=-1, span, newCell=null, spanIdx=0;
     for( var c=start; c < limit; c++ ) {
     r.className='ricoLG_hdg';
     var lastIdx=-1, span, newCell=null, spanIdx=0;
     for( var c=start; c < limit; c++ ) {
-      if (lastIdx == this.options.columnSpecs[c].panelIdx) {
+      if (lastIdx == this.options.columnSpecs[c].ColGroupIdx) {
         span++;
       } else {
         if (newCell) newCell.colSpan=span;
         newCell = r.insertCell(-1);
         if (cellClass) newCell.className=cellClass;
         span=1;
         span++;
       } else {
         if (newCell) newCell.colSpan=span;
         newCell = r.insertCell(-1);
         if (cellClass) newCell.className=cellClass;
         span=1;
-        lastIdx=this.options.columnSpecs[c].panelIdx;
-        newCell.innerHTML=this.options.panels[lastIdx];
+        lastIdx=this.options.columnSpecs[c].ColGroupIdx;
+        newCell.innerHTML=this.options.ColGroups[lastIdx];
       }
     }
     if (newCell) newCell.colSpan=span;
       }
     }
     if (newCell) newCell.colSpan=span;
@@ -1002,7 +990,7 @@ Rico.LiveGridMethods = {
       for (r=0; r<hdrSrc.length; r++) {
         cells=hdrSrc[r].cells;
         for (c=0,h=0; cells.length > 0; c++) {
       for (r=0; r<hdrSrc.length; r++) {
         cells=hdrSrc[r].cells;
         for (c=0,h=0; cells.length > 0; c++) {
-          if (cells[0].className=='ricoFrozen') {
+          if (Rico.hasClass(cells[0],'ricoFrozen')) {
             if (r==this.headerRowIdx) this.options.frozenColumns=c+1;
           } else {
             h=1;
             if (r==this.headerRowIdx) this.options.frozenColumns=c+1;
           } else {
             h=1;
@@ -1228,11 +1216,13 @@ Rico.LiveGridMethods = {
       newdiv.className = 'ricoLG_cell '+cls;
       newdiv.id=this.tableId+'_'+this.pageSize+'_'+c;
       this.columns[c].dataColDiv.appendChild(newdiv);
       newdiv.className = 'ricoLG_cell '+cls;
       newdiv.id=this.tableId+'_'+this.pageSize+'_'+c;
       this.columns[c].dataColDiv.appendChild(newdiv);
-      if (this.columns[c].format.canDrag && Rico.registerDraggable)
-        Rico.registerDraggable( new Rico.LiveGridDraggable(this, this.pageSize, c), this.options.dndMgrIdx );
-      newdiv.innerHTML='&nbsp;';   // this seems to be required by IE
       if (this.columns[c]._create) {
         this.columns[c]._create(newdiv,this.pageSize);
       if (this.columns[c]._create) {
         this.columns[c]._create(newdiv,this.pageSize);
+      } else {
+        newdiv.innerHTML='&nbsp;';   // this seems to be required by IE
+      }
+      if (this.columns[c].format.canDrag && Rico.registerDraggable) {
+        Rico.registerDraggable( new Rico.LiveGridDraggable(this, this.pageSize, c), this.options.dndMgrIdx );
       }
     }
     this.pageSize++;
       }
     }
     this.pageSize++;
@@ -1679,13 +1669,6 @@ Rico.LiveGridMethods = {
     return -1;
   },
 
     return -1;
   },
 
-  findColumnName: function(name) {
-    for (var n=0; n<this.columns.length; n++) {
-      if (this.columns[n].fieldName == name) return n;
-    }
-    return -1;
-  },
-  
 /**
  * Searches options.columnSpecs colAttr for matching colValue
  * @return array of matching column indexes
 /**
  * Searches options.columnSpecs colAttr for matching colValue
  * @return array of matching column indexes
@@ -1701,8 +1684,8 @@ Rico.LiveGridMethods = {
 /**
  * Set initial sort
  */
 /**
  * Set initial sort
  */
-  setSortUI: function( columnNameOrNum, sortDirection ) {
-    Rico.log("setSortUI: "+columnNameOrNum+' '+sortDirection);
+  setSortUI: function( columnIdOrNum, sortDirection ) {
+    Rico.log("setSortUI: "+columnIdOrNum+' '+sortDirection);
     var colnum=this.findSortedColumn();
     if (colnum >= 0) {
       sortDirection=this.columns[colnum].getSortDirection();
     var colnum=this.findSortedColumn();
     if (colnum >= 0) {
       sortDirection=this.columns[colnum].getSortDirection();
@@ -1713,12 +1696,12 @@ Rico.LiveGridMethods = {
         sortDirection=sortDirection.toUpperCase();
         if (sortDirection != Rico.ColumnConst.SORT_DESC) sortDirection=Rico.ColumnConst.SORT_ASC;
       }
         sortDirection=sortDirection.toUpperCase();
         if (sortDirection != Rico.ColumnConst.SORT_DESC) sortDirection=Rico.ColumnConst.SORT_ASC;
       }
-      switch (typeof columnNameOrNum) {
+      switch (typeof columnIdOrNum) {
         case 'string':
         case 'string':
-          colnum=this.findColumnName(columnNameOrNum);
+          colnum=this.findColumnsBySpec('id',columnIdOrNum);
           break;
         case 'number':
           break;
         case 'number':
-          colnum=columnNameOrNum;
+          colnum=columnIdOrNum;
           break;
       }
     }
           break;
       }
     }
@@ -1994,9 +1977,9 @@ initialize: function(liveGrid,colIdx,hdrInfo,tabIdx) {
   Rico.extend(this, new Rico.TableColumnBase());
   this.baseInit(liveGrid,colIdx,hdrInfo,tabIdx);
   this.buffer=liveGrid.buffer;
   Rico.extend(this, new Rico.TableColumnBase());
   this.baseInit(liveGrid,colIdx,hdrInfo,tabIdx);
   this.buffer=liveGrid.buffer;
-  if (typeof(this.format.type)!='string' || this.format.EntryType=='tinyMCE') this.format.type='raw';
+  if (typeof(this.format.type)!='string' || this.format.EntryType=='tinyMCE') this.format.type='html';
   if (typeof this.isNullable!='boolean') this.isNullable = /number|date/.test(this.format.type);
   if (typeof this.isNullable!='boolean') this.isNullable = /number|date/.test(this.format.type);
-  this.isText = /raw|text|showTags/.test(this.format.type);
+  this.isText = /html|text/.test(this.format.type);
   Rico.log(" sortable="+this.sortable+" filterable="+this.filterable+" hideable="+this.hideable+" isNullable="+this.isNullable+' isText='+this.isText);
   this.fixHeaders(this.liveGrid.tableId, this.options.hdrIconsFirst);
   if (this['format_'+this.format.type]) {
   Rico.log(" sortable="+this.sortable+" filterable="+this.filterable+" hideable="+this.hideable+" isNullable="+this.isNullable+' isText='+this.isText);
   this.fixHeaders(this.liveGrid.tableId, this.options.hdrIconsFirst);
   if (this['format_'+this.format.type]) {
@@ -2288,13 +2271,6 @@ mFilterOtherClick: function(e) {
 },
 
 format_text: function(v) {
 },
 
 format_text: function(v) {
-  if (typeof v!='string')
-    return '&nbsp;';
-  else
-    return Rico.stripTags(v);
-},
-
-format_showTags: function(v) {
   if (typeof v!='string')
     return '&nbsp;';
   else
   if (typeof v!='string')
     return '&nbsp;';
   else
@@ -2319,7 +2295,7 @@ format_datetime: function(v) {
 },
 
 // converts GMT/UTC to local time
 },
 
 // converts GMT/UTC to local time
-format_UTCasLocalTime: function(v) {
+format_utcaslocaltime: function(v) {
   if (typeof v=='undefined' || v=='' || v==null)
     return '&nbsp;';
   else {
   if (typeof v=='undefined' || v=='' || v==null)
     return '&nbsp;';
   else {
@@ -2382,8 +2358,8 @@ getValue: function(windowRow) {
   return this.buffer.getWindowCell(windowRow,this.index);
 },
 
   return this.buffer.getWindowCell(windowRow,this.index);
 },
 
-getBufferAttr: function(windowRow) {
-  return this.buffer.getWindowAttr(windowRow,this.index);
+getBufferStyle: function(windowRow) {
+  return this.buffer.getWindowStyle(windowRow,this.index);
 },
 
 setValue: function(windowRow,newval) {
 },
 
 setValue: function(windowRow,newval) {
@@ -2414,17 +2390,8 @@ displayValue: function(windowRow) {
   }
   var gridCell=this.cell(windowRow);
   this._display(bufval,gridCell,windowRow);
   }
   var gridCell=this.cell(windowRow);
   this._display(bufval,gridCell,windowRow);
-  var acceptAttr=this.buffer.options.acceptAttr;
-  if (acceptAttr.length==0) return;
-  var bufAttr=this.getBufferAttr(windowRow);
-  if (bufAttr==null) return;
-  for (var k=0; k<acceptAttr.length; k++) {
-    bufAttr=bufAttr['_'+acceptAttr[k]] || '';
-    switch (acceptAttr[k]) {
-      case 'style': gridCell.style.cssText=bufAttr; break;
-      case 'class': gridCell.className=bufAttr; break;
-      default:      gridCell['_'+acceptAttr[k]]=bufAttr; break;
-    }
+  if (this.buffer.options.acceptStyle) {
+    gridCell.style.cssText=this.getBufferStyle(windowRow);
   }
 }
 
   }
 }