/* * (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 * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions * and limitations under the License. */ if(typeof Rico=='undefined') throw("SimpleGrid requires the Rico JavaScript framework"); Rico.SimpleGrid = function(tableId, options) { this.initialize(tableId, options); } Rico.SimpleGrid.prototype = { /** * @class Create & manage an unbuffered grid. * Supports: frozen columns & headings, resizable columns. * @extends Rico.GridCommon * @constructs */ initialize: function( tableId, options ) { Rico.extend(this, Rico.GridCommon); this.baseInit(); Rico.setDebugArea(tableId+"_debugmsgs"); // if used, this should be a textarea Rico.extend(this.options, options || {}); this.tableId = tableId; Rico.log("SimpleGrid initialize start: "+tableId); this.createDivs(); this.hdrTabs=new Array(2); this.simpleGridInit(); Rico.log("SimpleGrid initialize end: "+tableId); }, simpleGridInit: function() { var i; for (i=0; i<2; i++) { Rico.log("simpleGridInit "+i); this.tabs[i]=Rico.$(this.tableId+'_tab'+i); if (!this.tabs[i]) return; this.hdrTabs[i]=Rico.$(this.tableId+'_tab'+i+'h'); if (!this.hdrTabs[i]) return; this.thead[i]=this.hdrTabs[i]; this.tbody[i]=this.tabs[i]; this.headerColCnt = this.getColumnInfo(this.hdrTabs[i].rows); if (i==0) this.options.frozenColumns=this.headerColCnt; if (Rico.theme.gridheader) Rico.addClass(this.thead[i],Rico.theme.gridheader); if (Rico.theme.gridcontent) Rico.addClass(this.tbody[i],Rico.theme.gridcontent); } if (this.headerColCnt==0) { alert('ERROR: no columns found in "'+this.tableId+'"'); return; } this.createColumnArray('SimpleGridColumn'); this.pageSize=this.columns[0].dataColDiv.childNodes.length; this.sizeDivs(); if (typeof(this.options.FilterLocation)=='number') this.createFilters(this.options.FilterLocation); this.attachMenuEvents(); this.scrollEventFunc=Rico.eventHandle(this,'handleScroll'); this.scrollFrozenEventFunc=Rico.eventHandle(this,'handleScrollFrozen'); this.scrollHeadingEventFunc=Rico.eventHandle(this,'handleScrollHeading'); this.pluginScroll(); if (this.options.windowResize) Rico.eventBind(window,"resize", Rico.eventHandle(this,'sizeDivs'), false); }, // return id string for a filter element filterId: function(colnum) { return 'RicoFilter_'+this.tableId+'_'+colnum; }, // create filter elements on heading row r createFilters: function(r) { if (r < 0) { r=this.addHeadingRow(); this.sizeDivs(); } for( var c=0; c < this.headerColCnt; c++ ) { var col=this.columns[c]; var fmt=col.format; if (typeof fmt.filterUI!='string') continue; var cell=this.hdrCells[r][c].cell; var field,name=this.filterId(c); var divs=cell.getElementsByTagName('div'); switch (fmt.filterUI.charAt(0)) { case 't': field=Rico.createFormField(divs[1],'input','text',name,name); var size=fmt.filterUI.match(/\d+/); field.maxLength=fmt.Length || 50; field.size=size ? parseInt(size,10) : 10; Rico.eventBind(field,'keyup',Rico.eventHandle(col,'filterKeypress'),false); break; case 's': field=Rico.createFormField(divs[1],'select',null,name); Rico.addSelectOption(field,this.options.FilterAllToken,Rico.getPhraseById("filterAll")); this.getFilterValues(col); var keys=Rico.keys(col.filterHash); keys.sort(); for (var i=0; i"+v+""; } } this.exportRows.push(exportText); } this.exportFinish(); }, /** * Hide a row in the grid. * sizeDivs() should be called after this function has completed. */ hideRow: function(rownum) { if (this.columns[0].cell(rownum).style.display=='none') return; for (var i=0; i this.width) newLeft-=this.width; } else { if (newLeft+this.width+this.options.margin > this.scrollDiv.clientWidth) newLeft-=this.width; } popupobj.divPopup.style.visibility="hidden"; popupobj.divPopup.style.display="block"; var contentHt=popupobj.divPopup.offsetHeight; var newTop=Math.floor(elem.offsetTop-this.scrollDiv.scrollTop+elem.offsetHeight/2); if (newTop+contentHt+popupobj.options.margin > this.scrollDiv.clientHeight) newTop=Math.max(newTop-contentHt,0); popupobj.openPopup(this.frzWi+newLeft,this.hdrHt+newTop); popupobj.divPopup.style.visibility ="visible"; return elem; } } if (Rico.Menu) { Rico.extend(Rico.Menu.prototype, { showSimpleMenu: function(e,hideFunc) { Rico.eventStop(e); this.hideFunc=hideFunc; if (this.div.childNodes.length==0) { this.cancelmenu(); return false; } var elem=Rico.eventElement(e); this.grid.openPopup(elem,this); return elem; }, showSimpleSubMenu: function(a,submenu) { if (this.openSubMenu) this.hideSubMenu(); this.openSubMenu=submenu; this.openMenuAnchor=a; if (a.className=='ricoSubMenu') a.className='ricoSubMenuOpen'; var top=parseInt(this.div.style.top,10); var left=parseInt(this.div.style.left,10); submenu.openPopup(left+a.offsetWidth,top+a.offsetTop); submenu.div.style.visibility ="visible"; } }); } Rico.SimpleGridColumn = function(grid,colIdx,hdrInfo,tabIdx) { this.initialize(grid,colIdx,hdrInfo,tabIdx); } Rico.SimpleGridColumn.prototype = { /** * @class Implements a SimpleGrid column * @extends Rico.TableColumnBase * @constructs */ initialize: function(grid,colIdx,hdrInfo,tabIdx) { Rico.extend(this, new Rico.TableColumnBase()); this.baseInit(grid,colIdx,hdrInfo,tabIdx); }, setUnfiltered: function() { this.filterRows=null; }, filterChange: function(e) { var selbox=Rico.eventElement(e); if (selbox.value==this.liveGrid.options.FilterAllToken) this.setUnfiltered(); else this.filterRows=this.filterHash[selbox.value]; this.liveGrid.applyFilters(); }, filterKeypress: function(e) { var txtbox=Rico.eventElement(e); if (typeof this.lastKeyFilter != 'string') this.lastKeyFilter=''; if (this.lastKeyFilter==txtbox.value) return; var v=txtbox.value; Rico.log("filterKeypress: "+this.index+' '+v); this.lastKeyFilter=v; if (v) { v=v.replace('\\','\\\\'); v=v.replace('(','\\(').replace(')','\\)'); v=v.replace('.','\\.'); if (this.format.filterUI.indexOf('^') > 0) v='^'+v; var re=new RegExp(v,'i'); this.filterRows=[]; var n=this.numRows(); for (var i=0; i