/**
 * Rozszerzenie PagingToolbar, dodające możliwość wyboru liczby wierszy na "stronie"
 * 
 * @author Piotr Krokowski
 * @copyright LGPL
 * @version 1.0, Ext 2.0-alhpa!!!
 **/

// Sposób użycia:
// var config = {
//		amounts: [[10, 10], [25, 25], [50, 50], [100, 100], [200, 200], [-1, 'wszystkie']], // możliwe do wyboru opcje
//   	defaultAmount: 25	// ile domyśnie rekordów ma być wyświetlanych
// };
// this.pagingToolbar.addPaginationLimit(config);

Ext.override(Ext.PagingToolbar, {
    addPaginationLimit: function(config) {
    	
    	config = config || {};
    	Ext.applyIf(config, {
    		amounts: [[10, 10], [25, 25], [50, 50], [100, 100], [200, 200]/*, [999999, 'wszystkie']*/],
    		defaultAmount: 10
    	});
    	
	    var store = new Ext.data.SimpleStore({
	        fields: ['limit', 'limitName'],
	        data : config.amounts
	    });
	    var combo = new Ext.form.ComboBox({
	    	/* regex: /^\d*$/, */
	        store: store,
	        displayField:'limitName',
	        editable: false,
			forceSelection: true,
	        typeAhead: true,
	        mode: 'local',
	        emptyText: '',
	        triggerAction: 'all',
	        selectOnFocus:true,
	        width: 70
	    });
	    combo.setValue(config.defaultAmount);
	    
	    var ptThisScope = this;
	    this.on('render', function() {
	    	ptThisScope.addField(combo);
	    });
	    //
	    /*
	    combo.on("change", function(c, value) {
	    	this.pageSize = value.get('limit');
	    	this.onClick("refresh");
	    }, this);
	    */
	    combo.on("select", function(c, record) {
	    	this.pageSize = record.get('limit');
	    	this.onClick("first");
	    }, this);
	    
	    return combo;
	},
	
	doLoad : function(start){
        var o = {}, pn = this.paramNames;
        o[pn.start] = start;
        o[pn.limit] = this.pageSize;
        try {
        	if (this.store.baseParams!=null)
        		Ext.apply(o, this.store.baseParams);
        } catch (e) {
        	console.warn(e);
        }
        this.store.load({params:o});
    }
});
