
var season_tour_stats_ds;

LSPN.MainPage.prototype.setupSeasonStrokeStats = function()
{
	var ds = new Ext.data.Store({
    	    proxy: new Ext.data.HttpProxy(new JayRock.RpcConnection({url:RPC_URL, rpcMethod:'getSeasonStrokeStats'})),
    	    method: "POST",
    	    sortInfo : {field: "average_score", direction: "ASC"},
            remoteSort: true,
            baseParams: {league_id: league_detail_id},
            reader: new Ext.data.JsonReader({
            root: 'rows',
            totalProperty: 'num_records',
			fields: ["username", "user_id", "average_score", "holes", "rounds", "holesinone", "doubleeagles", "eagles", "birdies", "pars", "bogies", "other", "hits_par_3", "hits_par_4", "hits_par_5", "chips_per_round", "mulligans_per_round"]
           })
    });
    
    // the column model has information about grid columns
    // dataIndex maps the column to the specific data field in
    // the data store
		
    
    var cm = new Ext.grid.ColumnModel([{
           header: "Player",
           dataIndex: 'username',
           width: 90
        },{
           header: "Avg Score",
           dataIndex: 'average_score',
           width: 70
        },{
           header: "Holes",
           dataIndex: 'holes',
           width: 50,
           align: 'left'
        },{
           header: "Rds",
           dataIndex: 'rounds',
           width: 50,
           align: 'left'
        },{
           header: "Aces",
           dataIndex: 'holesinone',
           width: 50,
           align: 'left'
        },{
           header: "Dbl Egls",
           dataIndex: 'doubleeagles',
           width: 50,
           align: 'left'
        },{
           header: "Egls",
           dataIndex: 'eagles',
           width: 50,
           align: 'left'
        },{
           header: "Brds",
           dataIndex: 'birdies',
           width: 50,
           align: 'left'
        },{
           header: "Pars",
           dataIndex: 'pars',
           width: 50,
           align: 'left'
        },{
           header: "Bgs",
           dataIndex: 'bogies',
           width: 50,
           align: 'left'
        },{
           header: "Other",
           dataIndex: 'other',
           width: 50,
           align: 'left'
        },{
           header: "Par3s",
           dataIndex: 'hits_par_3',
           width: 50,
           align: 'left',
           renderer: renderAvgPoints
        },{
           header: "Par4s",
           dataIndex: 'hits_par_4',
           width: 50,
           align: 'left',
           renderer: renderAvgPoints
        },{
           header: "Par5s",
           dataIndex: 'hits_par_5',
           width: 50,
           align: 'left',
           renderer: renderAvgPoints
        }]);

    // by default columns are sortable
    cm.defaultSortable = true;

    var grid = new Ext.grid.GridPanel({
        applyTo:'stats-stroke-grid',
        width:630,
        height:300,
        store: ds,
        cm: cm,
        stripeRows: true,
        loadMask: true,
        viewConfig: {
            forceFit:true,
            enableRowBody:true,
            showPreview:true
        },
		tbar: [
            'Search for player: ', ' ',
            new Ext.app.SearchField({
				pgid: 'page-stats-stroke',
                store: ds,
                width:320
            })
        ],
        bbar: new Ext.PagingToolbar({
        	id: 'page-stats-stroke',
            pageSize: 25,
            store: ds,
            displayInfo: true,
            displayMsg: 'Displaying players {0} - {1} of {2}',
            emptyMsg: "No players to display"
        })
    });

    grid.on('rowdblclick', this.showProfile, this);
    
    // render it
    grid.render();

    // trigger the data store load
    ds.load({params:{start:0, limit:25}});
	
	
	var myds = new Ext.data.Store({
    	    proxy: new Ext.data.HttpProxy(new JayRock.RpcConnection({url:RPC_URL, rpcMethod:'getSeasonStrokeStats'})),
    	    method: "POST",
    	    sortInfo : {field: "average_score", direction: "ASC"},
            remoteSort: true,
            baseParams: {stats_user_id: my_user_id, league_id: league_detail_id},
            reader: new Ext.data.JsonReader({
            root: 'rows',
            totalProperty: 'num_records',
			fields: ["username", "user_id", "average_score", "holes", "rounds", "holesinone", "doubleeagles", "eagles", "birdies", "pars", "bogies", "other", "hits_par_3", "hits_par_4", "hits_par_5", "chips_per_round", "mulligans_per_round"]
           })
    });
    
    // the column model has information about grid columns
    // dataIndex maps the column to the specific data field in
    // the data store
		
    
    var mycm = new Ext.grid.ColumnModel([{
           header: "Player",
           dataIndex: 'username',
           width: 90
        },{
           header: "Avg Score",
           dataIndex: 'average_score',
           width: 70
        },{
           header: "Holes",
           dataIndex: 'holes',
           width: 50,
           align: 'left'
        },{
           header: "Rds",
           dataIndex: 'rounds',
           width: 50,
           align: 'left'
        },{
           header: "Aces",
           dataIndex: 'holesinone',
           width: 50,
           align: 'left'
        },{
           header: "Dbl Egls",
           dataIndex: 'doubleeagles',
           width: 50,
           align: 'left'
        },{
           header: "Egls",
           dataIndex: 'eagles',
           width: 50,
           align: 'left'
        },{
           header: "Brds",
           dataIndex: 'birdies',
           width: 50,
           align: 'left'
        },{
           header: "Pars",
           dataIndex: 'pars',
           width: 50,
           align: 'left'
        },{
           header: "Bgs",
           dataIndex: 'bogies',
           width: 50,
           align: 'left'
        },{
           header: "Other",
           dataIndex: 'other',
           width: 50,
           align: 'left'
        },{
           header: "Par3s",
           dataIndex: 'hits_par_3',
           width: 50,
           align: 'left',
           renderer: renderAvgPoints
        },{
           header: "Par4s",
           dataIndex: 'hits_par_4',
           width: 50,
           align: 'left',
           renderer: renderAvgPoints
        },{
           header: "Par5s",
           dataIndex: 'hits_par_5',
           width: 50,
           align: 'left',
           renderer: renderAvgPoints
        }]);

    // by default columns are sortable
    mycm.defaultSortable = true;

	if (Ext.getCmp('my-stats-stroke-grid'))
	{
		var mygrid = new Ext.grid.GridPanel({
		    applyTo:'my-stats-stroke-grid',
		    width:630,
		    height:47,
		    store: myds,
		    cm: mycm,
		    stripeRows: true,
		    loadMask: true,
		    viewConfig: {
			forceFit:true,
			enableRowBody:true,
			showPreview:true
		    }
		});
	    
		mygrid.on('rowdblclick', this.showProfile, this);
		
		// render it
		mygrid.render();
	}
    // trigger the data store load
    myds.load({params:{start:0, limit:25}});
}

LSPN.MainPage.prototype.setupSeasonTourStats = function()
{
	var all_tours_ds = new Ext.data.Store({
        	    proxy: new Ext.data.HttpProxy(new JayRock.RpcConnection({url:RPC_URL, rpcMethod:'getToursForSeason'})),
        	    method: "POST",
                remoteSort: true,
                baseParams: {},
	            reader: new Ext.data.JsonReader({
	            root: 'rows',
	            totalProperty: 'num_records'
               }, ['tour_id', 'name'] )
            });	
	
	/*var myds = new Ext.data.Store({
    	    proxy: new Ext.data.HttpProxy(new JayRock.RpcConnection({url:RPC_URL, rpcMethod:'getMyTourStats'})),
    	    method: "POST",
    	    sortInfo : {field: "average_score", direction: "ASC"},
            remoteSort: true,
            baseParams: {tour: 'PLSA'},
            reader: new Ext.data.JsonReader({
            root: 'rows',
            totalProperty: 'num_records',
			fields: ["username", "user_id", "average_score", "holes", "rounds", "holesinone", "doubleeagles", "eagles", "birdies", "pars", "bogies", "other", "hits_par_3", "hits_par_4", "hits_par_5", "chips_per_round", "mulligans_per_round"]
           })
    });*/
	
	season_tour_stats_ds = new Ext.data.Store({
    	    proxy: new Ext.data.HttpProxy(new JayRock.RpcConnection({url:RPC_URL, rpcMethod:'getSeasonTourStats'})),
    	    method: "POST",
    	    sortInfo : {field: "average_score", direction: "ASC"},
            remoteSort: true,
            baseParams: {tour: 'PLSA'},
            reader: new Ext.data.JsonReader({
            root: 'rows',
            totalProperty: 'num_records',
			fields: ["username", "user_id", "average_score", "holes", "rounds", "holesinone", "doubleeagles", "eagles", "birdies", "pars", "bogies", "other", "hits_par_3", "hits_par_4", "hits_par_5", "chips_per_round", "mulligans_per_round"]
           })
    });
    
	my_season_tour_stats_ds = new Ext.data.Store({
    	    proxy: new Ext.data.HttpProxy(new JayRock.RpcConnection({url:RPC_URL, rpcMethod:'getSeasonTourStats'})),
    	    method: "POST",
    	    sortInfo : {field: "average_score", direction: "ASC"},
            remoteSort: true,
            baseParams: {stats_user_id: my_user_id, tour: 'PLSA'},
            reader: new Ext.data.JsonReader({
            root: 'rows',
            totalProperty: 'num_records',
			fields: ["username", "user_id", "average_score", "holes", "rounds", "holesinone", "doubleeagles", "eagles", "birdies", "pars", "bogies", "other", "hits_par_3", "hits_par_4", "hits_par_5", "chips_per_round", "mulligans_per_round"]
           })
    });	
	
    // the column model has information about grid columns
    // dataIndex maps the column to the specific data field in
    // the data store
		
    
    var cm = new Ext.grid.ColumnModel([{
           header: "Player",
           dataIndex: 'username',
           width: 90
        },{
           header: "Avg Score",
           dataIndex: 'average_score',
           width: 70,
		   renderer: renderAvgPoints
        },{
           header: "Holes",
           dataIndex: 'holes',
           width: 50,
           align: 'left'
        },{
           header: "Rds",
           dataIndex: 'rounds',
           width: 50,
           align: 'left'
        },{
           header: "Aces",
           dataIndex: 'holesinone',
           width: 50,
           align: 'left'
        },{
           header: "Dbl Egls",
           dataIndex: 'doubleeagles',
           width: 50,
           align: 'left'
        },{
           header: "Egls",
           dataIndex: 'eagles',
           width: 50,
           align: 'left'
        },{
           header: "Brds",
           dataIndex: 'birdies',
           width: 50,
           align: 'left'
        },{
           header: "Pars",
           dataIndex: 'pars',
           width: 50,
           align: 'left'
        },{
           header: "Bgs",
           dataIndex: 'bogies',
           width: 50,
           align: 'left'
        },{
           header: "Other",
           dataIndex: 'other',
           width: 50,
           align: 'left'
        },{
           header: "Par3s",
           dataIndex: 'hits_par_3',
           width: 50,
           align: 'left',
           renderer: renderAvgPoints
        },{
           header: "Par4s",
           dataIndex: 'hits_par_4',
           width: 50,
           align: 'left',
           renderer: renderAvgPoints
        },{
           header: "Par5s",
           dataIndex: 'hits_par_5',
           width: 50,
           align: 'left',
           renderer: renderAvgPoints
        }]);

    // by default columns are sortable
    cm.defaultSortable = true;

    var grid = new Ext.grid.GridPanel({
        applyTo:'stats-tour-grid',
        width:630,
        height:300,
        store: season_tour_stats_ds,
        cm: cm,
        stripeRows: true,
        loadMask: true,
        viewConfig: {
            forceFit:true,
            enableRowBody:true,
            showPreview:true
        },
		tbar: [
            {
				xtype: 'combo',
				style: 'text-align: left;',
				fieldLabel: "Tour",
				labelSeparator: ":",
				id: 'tour-stats-combo',
				store: all_tours_ds,
				width: 100,
				displayField: 'name',
				valueField: 'tour_id',
				typeAhead: true,
				mode: 'remote', 
				selectOnFocus: true,
				triggerAction: 'all',
				emptyText: 'Tour...',
				listeners:{
					select:{fn:function(combo, value) {
						season_tour_stats_ds.baseParams.tour = Ext.getCmp('tour-stats-combo').getValue();
						season_tour_stats_ds.removeAll();
						season_tour_stats_ds.load({params:{start:0, limit:25}});
					}}	
				}	
			},
			{
				xtype: 'combo',
				style: 'text-align: left;',
				fieldLabel: "Game",
				labelSeparator: ":",
				id: 'tour-stats-game',
				store: LSPN.stores.games ,
				width: 100,
				displayField: 'name',
				valueField: 'num',
				typeAhead: true,
				mode: 'local', 
				selectOnFocus: true,
				triggerAction: 'all',
				emptyText: 'Game...',
				listeners:{
					select:{fn:function(combo, value) {
						season_tour_stats_ds.baseParams.game = Ext.getCmp('tour-stats-game').getValue();
						season_tour_stats_ds.removeAll();
						season_tour_stats_ds.load({params:{start:0, limit:25}});
					}}	
				}	
			},{
				xtype: 'combo',
				style: 'text-align: left;',
				fieldLabel: "Swing",
				labelSeparator: ":",
				id: 'tour-stats-swing',
				store: LSPN.stores.stats_swing,
				width: 100,
				displayField: 'name',
				valueField: 'num',
				typeAhead: true,
				mode: 'local', 
				selectOnFocus: true,
				triggerAction: 'all',
				emptyText: 'Swing...',
				listeners:{
					select:{fn:function(combo, value) {
						season_tour_stats_ds.baseParams.swing = Ext.getCmp('tour-stats-swing').getValue();
						season_tour_stats_ds.removeAll();
						season_tour_stats_ds.load({params:{start:0, limit:25}});
					}}	
				}	
				
			},{
				xtype: 'combo',
				style: 'text-align: left;',
				fieldLabel: "Difficulty",
				labelSeparator: ":",
				id: 'tour-stats-skill',
				store: LSPN.stores.stats_difficulty,
				width: 100,
				displayField: 'name',
				valueField: 'num',
				typeAhead: true,
				mode: 'local', 
				selectOnFocus: true,
				triggerAction: 'all',
				emptyText: 'Skill...',
				listeners:{
					select:{fn:function(combo, value) {
						season_tour_stats_ds.baseParams.skill = Ext.getCmp('tour-stats-skill').getValue();
						season_tour_stats_ds.removeAll();
						season_tour_stats_ds.load({params:{start:0, limit:25}});
					}}	
				}	
				
			},
	        'Search for player: ', ' ',
            new Ext.app.SearchField({
				pgid: 'page-stats-tour',
                store: season_tour_stats_ds,
                width:120
            })
        ],
        bbar: new Ext.PagingToolbar({
        	id: 'page-stats-tour',
            pageSize: 25,
            store: season_tour_stats_ds,
            displayInfo: true,
            displayMsg: 'Displaying players {0} - {1} of {2}',
            emptyMsg: "No players to display"
        })
    });

    grid.on('rowdblclick', this.showProfile, this);
    
    // render it
    grid.render();

   var mycm = new Ext.grid.ColumnModel([{
           header: "Player",
           dataIndex: 'username',
           width: 90
        },{
           header: "Avg Score",
           dataIndex: 'average_score',
           width: 70,
		   renderer: renderAvgPoints
        },{
           header: "Holes",
           dataIndex: 'holes',
           width: 50,
           align: 'left'
        },{
           header: "Rds",
           dataIndex: 'rounds',
           width: 50,
           align: 'left'
        },{
           header: "Aces",
           dataIndex: 'holesinone',
           width: 50,
           align: 'left'
        },{
           header: "Dbl Egls",
           dataIndex: 'doubleeagles',
           width: 50,
           align: 'left'
        },{
           header: "Egls",
           dataIndex: 'eagles',
           width: 50,
           align: 'left'
        },{
           header: "Brds",
           dataIndex: 'birdies',
           width: 50,
           align: 'left'
        },{
           header: "Pars",
           dataIndex: 'pars',
           width: 50,
           align: 'left'
        },{
           header: "Bgs",
           dataIndex: 'bogies',
           width: 50,
           align: 'left'
        },{
           header: "Other",
           dataIndex: 'other',
           width: 50,
           align: 'left'
        },{
           header: "Par3s",
           dataIndex: 'hits_par_3',
           width: 50,
           align: 'left',
           renderer: renderAvgPoints
        },{
           header: "Par4s",
           dataIndex: 'hits_par_4',
           width: 50,
           align: 'left',
           renderer: renderAvgPoints
        },{
           header: "Par5s",
           dataIndex: 'hits_par_5',
           width: 50,
           align: 'left',
           renderer: renderAvgPoints
        }]);

    // by default columns are sortable
   mycm.defaultSortable = true;

    var mygrid = new Ext.grid.GridPanel({
        applyTo:'my-stats-tour-grid',
        width:630,
        height:72,
        store: my_season_tour_stats_ds,
        cm: mycm,
        stripeRows: true,
        loadMask: true,
        viewConfig: {
            forceFit:true,
            enableRowBody:true,
            showPreview:true
        },
		tbar: [
            {
				xtype: 'combo',
				style: 'text-align: left;',
				fieldLabel: "Tour",
				labelSeparator: ":",
				id: 'my-tour-stats-combo',
				store: all_tours_ds,
				width: 100,
				displayField: 'name',
				valueField: 'tour_id',
				typeAhead: true,
				mode: 'remote', 
				selectOnFocus: true,
				triggerAction: 'all',
				emptyText: 'Tour...',
				listeners:{
					select:{fn:function(combo, value) {
						my_season_tour_stats_ds.baseParams.tour = Ext.getCmp('my-tour-stats-combo').getValue();
						my_season_tour_stats_ds.removeAll();
						my_season_tour_stats_ds.load({params:{start:0, limit:25}});
					}}	
				}	
			},
			{
				xtype: 'combo',
				style: 'text-align: left;',
				fieldLabel: "Game",
				labelSeparator: ":",
				id: 'my-tour-stats-game',
				store: LSPN.stores.games ,
				width: 100,
				displayField: 'name',
				valueField: 'num',
				typeAhead: true,
				mode: 'local', 
				selectOnFocus: true,
				triggerAction: 'all',
				emptyText: 'Game...',
				listeners:{
					select:{fn:function(combo, value) {
						my_season_tour_stats_ds.baseParams.game = Ext.getCmp('my-tour-stats-game').getValue();
						my_season_tour_stats_ds.removeAll();
						my_season_tour_stats_ds.load({params:{start:0, limit:25}});
					}}	
				}	
			},{
				xtype: 'combo',
				style: 'text-align: left;',
				fieldLabel: "Swing",
				labelSeparator: ":",
				id: 'my-tour-stats-swing',
				store: LSPN.stores.stats_swing,
				width: 100,
				displayField: 'name',
				valueField: 'num',
				typeAhead: true,
				mode: 'local', 
				selectOnFocus: true,
				triggerAction: 'all',
				emptyText: 'Swing...',
				listeners:{
					select:{fn:function(combo, value) {
						my_season_tour_stats_ds.baseParams.swing = Ext.getCmp('my-tour-stats-swing').getValue();
						my_season_tour_stats_ds.removeAll();
						my_season_tour_stats_ds.load({params:{start:0, limit:25}});
					}}	
				}	
				
			},{
				xtype: 'combo',
				style: 'text-align: left;',
				fieldLabel: "Difficulty",
				labelSeparator: ":",
				id: 'my-tour-stats-skill',
				store: LSPN.stores.stats_difficulty,
				width: 100,
				displayField: 'name',
				valueField: 'num',
				typeAhead: true,
				mode: 'local', 
				selectOnFocus: true,
				triggerAction: 'all',
				emptyText: 'Skill...',
				listeners:{
					select:{fn:function(combo, value) {
						my_season_tour_stats_ds.baseParams.skill = Ext.getCmp('my-tour-stats-skill').getValue();
						my_season_tour_stats_ds.removeAll();
						my_season_tour_stats_ds.load({params:{start:0, limit:25}});
					}}	
				}	
				
			}
        ]
    });

    mygrid.on('rowdblclick', this.showProfile, this);
    
    // render it
    mygrid.render();


}

