/**
@class FilterAddIn
@namespace ProspectDirector.Types.View
**/
ProspectDirector.Types.View.FilterAddIn = Class.extend({

    init: function (args) {

    },

    filter: function (trigger) {
        if (!this.isFiltered(trigger)) {
            this._addIcon(trigger);
        }
    },

    unfilter: function (trigger) {
        if (this.isFiltered(trigger)) {
            this._getIcon(trigger).remove();
        }
    },

    clearAllFilters: function (trigger) {

        var grid = $(trigger).closest(".k-grid");

        grid.find(".k-grid-header .k-header :not([data-field=\"\"])").each(function (index, el) {
            this._getIcon(el).remove();
        });

    },

    toggle: function (trigger) {

        if (this.isFiltered(trigger)) {
            this.unfilter(trigger);
        }
        else {
            this.filter(trigger);
        }

    },

    isFiltered: function (trigger) {
        return this._getIcon(trigger).length !== 0;
    },

    _getIcon: function (trigger) {
        return $(trigger).find(".k-link .grid-filter");
    },

    _addIcon: function (trigger) {
        $(trigger).children(".k-link").prepend("<img src=\"" + ProspectDirector.RUNTIME.resolveUrl("~/application/icons/misc/filter.png") + "\" class=\"grid-filter\" style=\"vertical-align:middle;padding-right:5px;\">");
    }

});