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

PD.Web.UI.Controls.ViewGridColumnInlineFilterModule =
PD.Web.UI.Controls.GridModule.extend({

    //===================================
    // FIELDS
    //===================================

    _activeFilters: null,

    //===================================
    // PROPERTIES
    //===================================

    get_gridHeader: function () {
        return this.get_kendo().element.find(".k-grid-header");
    },

    //===================================
    // EVENT HANDLERS
    //===================================

    _onRequestEnd: function (e) {

        if (e.response != null) {
            this._activeFilters = new PD.BCL.List(e.response.filters);
            this._removeInlineFilterIcons();
            this._insertInlineFilterIcons();
        }

    },

    //===================================
    // PUBLIC METHODS
    //===================================

    start: function () {

        this._activeFilters = new PD.BCL.List();

        this.addGridMethod("getActiveFilters", this.getActiveFilters);

        this.get_dataSource().get_instance().bind(
            "requestEnd",
            $.proxy(this._onRequestEnd, this));

    },

    getActiveFilters: function () {
        return this._activeFilters;
    },

    //===================================
    // PRIVATE METHODS
    //===================================

    _insertInlineFilterIcons: function () {

        var url = PD.Path.resolve("~/application/icons/misc/filter.png"),
            gridHeader = this.get_gridHeader();

        this._activeFilters.each(function (index, filter) {

            var link = gridHeader.find(".k-header[data-field=" + filter + "] .k-link");
            link.prepend("<img src='" + url + "' class='grid-filter' style='vertical-align:middle;padding-right:5px;'>");

        });

    },

    _removeInlineFilterIcons: function () {
        this.get_gridHeader().find(".grid-filter").remove();
    }

});