<commit_before>/*jslint nomen:true*/
/*global define*/
define([
    'underscore',
    './filters-manager'
], function (_, FiltersManager) {
    'use strict';

    var CollectionFiltersManager;

    /**
     * View that represents all grid filters
     *
     * @export  orofilter/js/collection-filters-manager
     * @class   orofilter.CollectionFiltersManager
     * @extends orofilter.FiltersManager
     */
    CollectionFiltersManager = FiltersManager.extend({
        /**
         * Initialize filter list options
         *
         * @param {Object} options
         * @param {oro.PageableCollection} [options.collection]
         * @param {Object} [options.filters]
         * @param {String} [options.addButtonHint]
         */
        initialize: function (options) {
            this.collection = options.collection;

            this.listenTo(this.collection, {
                'beforeFetch': this._beforeCollectionFetch,
                'updateState': this._onUpdateCollectionState,
                'reset': this._onCollectionReset
            });

            CollectionFiltersManager.__super__.initialize.apply(this, arguments);
        },

        render: function () {
            CollectionFiltersManager.__super__.render.apply(this, arguments);
            this._onUpdateCollectionState(this.collection);
            return this;
        },

        /**
         * Triggers when filter is updated
         *
         * @param {oro.filter.AbstractFilter} filter
         * @protected
         */
        _onFilterUpdated: function (filter) {
            if (this.ignoreFiltersUpdateEvents) {
                return;
            }
            this.collection.state.currentPage = 1;
            this.collection.fetch({reset: true});

            CollectionFiltersManager.__super__._onFilterUpdated.apply(this, arguments);
        },

        /**
         * Triggers before collection fetch it's data
         *
         * @protected
         */
        _beforeCollectionFetch: function (collection) {
            collection.state.filters = this._createState();
        },

        /**
         * Triggers when collection state is updated
         *
         * @param {oro.PageableCollection} collection
         */
        _onUpdateCollectionState: function (collection) {
            this.ignoreFiltersUpdateEvents = true;
            this._applyState(collection.state.filters || {});
            this.ignoreFiltersUpdateEvents = false;
        },

        /**
         * Triggers after collection resets it's data
         *
         * @protected
         */
        _onCollectionReset: function (collection) {
            if (collection.state.totalRecords > 0 && this.$el.children().length > 0) {
                this.$el.show();
            }
        },

        /**
         * Create state according to filters parameters
         *<commit_msg>BAP-4679: Tasks grid on Contact view has filters when no records exist on it<commit_after>/*jslint nomen:true*/
/*global define*/
define([
    'underscore',
    './filters-manager'
], function (_, FiltersManager) {
    'use strict';

    var CollectionFiltersManager;

    /**
     * View that represents all grid filters
     *
     * @export  orofilter/js/collection-filters-manager
     * @class   orofilter.CollectionFiltersManager
     * @extends orofilter.FiltersManager
     */
    CollectionFiltersManager = FiltersManager.extend({
        /**
         * Initialize filter list options
         *
         * @param {Object} options
         * @param {oro.PageableCollection} [options.collection]
         * @param {Object} [options.filters]
         * @param {String} [options.addButtonHint]
         */
        initialize: function (options) {
            this.collection = options.collection;

            this.listenTo(this.collection, {
                'beforeFetch': this._beforeCollectionFetch,
                'updateState': this._onUpdateCollectionState,
                'reset': this._onCollectionReset
            });

            CollectionFiltersManager.__super__.initialize.apply(this, arguments);
        },

        render: function () {
            CollectionFiltersManager.__super__.render.apply(this, arguments);
            this._onUpdateCollectionState(this.collection);
            return this;
        },

        /**
         * Triggers when filter is updated
         *
         * @param {oro.filter.AbstractFilter} filter
         * @protected
         */
        _onFilterUpdated: function (filter) {
            if (this.ignoreFiltersUpdateEvents) {
                return;
            }
            this.collection.state.currentPage = 1;
            this.collection.fetch({reset: true});

            CollectionFiltersManager.__super__._onFilterUpdated.apply(this, arguments);
        },

        /**
         * Triggers before collection fetch it's data
         *
         * @protected
         */
        _beforeCollectionFetch: function (collection) {
            collection.state.filters = this._createState();
        },

        /**
         * Triggers when collection state is updated
         *
         * @param {oro.PageableCollection} collection
         */
        _onUpdateCollectionState: function (collection) {
            this.ignoreFiltersUpdateEvents = true;
            this._applyState(collection.state.filters || {});
            this.ignoreFiltersUpdateEvents = false;
        },

        /**
         * Triggers after collection resets it's data
         *
         * @protected
         */
        _onCollectionReset: function (collection) {
            var hasRecords, hasFiltersState;
            hasRecords = collection.state.totalRecords > 0;
            hasFiltersState = !_.isEmpty(collection.state.filters);
            if (hasRecords || hasFiltersState) {
                this.$el.show();
            } else {
                this.$el.hide();
            }
        },

        /**
         * Create state according to filters parameters
         *
{'fraction_non_alphanumeric': 0.10046807087930458, 'fraction_numerical': 0.0015045135406218655, 'mean_word_length': 1.8010299625468165, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3636288', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1455, 'n_words': 293}