/* * DEXT - Domino JS Framework 0.1 * Copyright(c) 2007, Jake Howlett. *  * http://www.codestore.net/dext */YAHOO.namespace('DEXT.Database.View');DEXT.Database.View = function(el) {	el = Ext.get(el);	this.grid = el;	this.view = null;}DEXT.Database.View.prototype = {	open: function(view){		if (this.view==view) return true; //already open - don't do anything				this.view=view;				var callback = {			success:this.load,			failure:this.failed,			scope:this		}				YAHOO.util.Connect.asyncRequest('GET', view+"?ReadDesign&OutputFormat=JSON", callback, null); 					this.failed = function(o){			//dialog prompt			Ext.MessageBox.show({				title: 'Error',				msg: "Failed to open view "+this.view,				width:300,     		     buttons: Ext.MessageBox.OK			})		}	},		load: function(o){			design=eval("("+o.responseText+")");        	        	cols=[]; maps=[];		for (var i=0; i<design.column.length; i++){			cols.push(				{					dataIndex:design.column[i]["@name"],					header:design.column[i]["@title"],					width:design.column[i]["@width"]				}			);			maps.push(				{					name: design.column[i]["@name"],					mapping: design.column[i]["@columnnumber"]				}			);		}     		ds = new Ext.data.Store(		{			proxy: new Ext.data.HttpProxy({	        		url: this.view+'?ReadViewEntries',	     		method:'GET'			}),			reader: new Ext.data.DominoJsonReader( {}, Ext.data.Record.create(maps) ),			remoteSort: true,			baseParams:{'OutputFormat':'JSON'}		}); //end store				this.cm = new Ext.grid.ColumnModel( cols );		sm = new Ext.grid.RowSelectionModel({singleSelect:true});				if (grid) grid.destroy();		        	var grid = new Ext.grid.Grid(			this.grid,			{				ds:ds,				cm:this.cm,				selModel: sm,				enableColLock:false				}		);        	grid.render();        	        	this.gridFoot = grid.getView().getFooterPanel(true);        			paging = new DEXT.PagingToolbar(this.gridFoot, ds, {cursor:1, pageSize: 30});				// create a floating label with display info    		var displayInfo = this.gridFoot.createChild({cls:'paging-info'});        		ds.on('load', function(){    			var count = ds.getCount();    			var msg = count == 0 ? "No documents found" : String.format(     	           'Displaying documents {0} - {1} of {2}',                paging.cursor, paging.cursor+count-1, ds.getTotalCount()              	);	          displayInfo.update(msg);	    });			    ds.load({params:{start:1, count:30}});  		grid.getView().fitColumns(); 		grid.addListener('rowclick', this.preview);	     //innerLayout.findPanel('view').setTitle(this.view + ' - View');        		},		preview:function(grid, rowIndex, e){			ticket_id = sm.getSelected().id; // grid.getRowId(rowIndex);			Ext.DomHelper.overwrite('preview-body-view',     		            {tag: 'iframe', frameBorder: 0, src: "0/"+ticket_id + "?OpenDocument"}); 	}}