/// class PD.Web.UI.Controls.ViewGridContextualFilterModule
/// using PD.Web.UI.Controls.GridModule

PD.Web.UI.Controls.ViewGridContextualFilterModule =
PD.Web.UI.Controls.GridModule.extend({
    
    //===================================
    // EVENT HANDLERS
    //===================================

    _onDataSourceRead: function (e) {
        e.contextualFilters = JSON.stringify(this.getContextualFilters());
    
    },
    //===================================
    // PUBLIC METHODS
    //===================================

    start: function () {
        this.get_grid().get_dataSource().bind("dataSourceRead", $.proxy(this._onDataSourceRead, this));
        this.addGridMethod("getContextualFilters", this.getContextualFilters);
    },

    getContextualFilters: function () {
            
        var needContextCallback = this.getOption("needContext", function () { }),
            result = {
                filters: [],
                addFilter: function (filter) {
                    this.filters[this.filters.length] = filter;
                }
            };

        needContextCallback(result);
        
        return result.filters;

    }

});