<commit_before>/**
 * Subclass of Backgrid.Extension.Filter which allows us to search
 * for courses.  Fixes accessibility issues with the Backgrid
 * filter component.
 *
 * This class is a hack in that it directly copies source code from
 * backgrid.filter 0.3.5, making it heavily reliant on that
 * particular implementation.
 */
define(function(require) {
    'use strict';

    var $ = require('jquery'),
        _ = require('underscore'),
        Backgrid = require('backgrid'),

        listSearchTemplate = require('text!components/generic-list/list/templates/search.underscore'),

        CourseListSearch;

    require('backgrid-filter');

    CourseListSearch = Backgrid.Extension.ClientSideFilter.extend({
        className: function() {
            return [Backgrid.Extension.ClientSideFilter.prototype.className, 'course-list-search'].join(' ');
        },

        events: function() {
            var superEvents = Backgrid.Extension.ClientSideFilter.prototype.events;
            delete superEvents['keydown input[type=search]']; // Don't search on key down
            return _.extend(superEvents,
                {
                    'click .search': 'search',
                    'click .clear.btn': 'clear'
                }
            );
        },

        fields: ['catalog_course_title', 'course_id'],

        template: _.template(listSearchTemplate, null, {variable: null}),

        initialize: function(options) {
            this.options = options || {};
            this.listenTo(options.collection, 'backgrid:refresh', this.render);
            Backgrid.Extension.ClientSideFilter.prototype.initialize.call(this, options);
        },

        clearButton: function() {
            return this.$el.find('[data-backgrid-action=clear]');
        },

        render: function() {
            this.value = this.options.collection.getSearchString();
            this.$el.empty().append(this.template({
                id: 'search-course-list',
                name: this.name,
                placeholder: this.placeholder,
                value: this.value,
                labelText: gettext('Search courses'),
                executeSearchText: gettext('search'),
                clearSearchText: gettext('clear search')
            }));
            this.showClearButtonMaybe();
            this.delegateEvents();
            return this;
        },

        search: function(event) {
            var searchString = this.searchBox().val().trim();
            if (event) event.preventDefault();
            if (searchString === '') {
                this.options.collection.unsetSearchString();
            } else {
                this.options.collection.setSearchString(searchString);
                this.options.trackingModel.trigger('segment:track', 'edx.bi.course-list.searched', {
                    category: 'search'<commit_msg>Fixed course list search event naming.<commit_after>/**
 * Subclass of Backgrid.Extension.Filter which allows us to search
 * for courses.  Fixes accessibility issues with the Backgrid
 * filter component.
 *
 * This class is a hack in that it directly copies source code from
 * backgrid.filter 0.3.5, making it heavily reliant on that
 * particular implementation.
 */
define(function(require) {
    'use strict';

    var $ = require('jquery'),
        _ = require('underscore'),
        Backgrid = require('backgrid'),

        listSearchTemplate = require('text!components/generic-list/list/templates/search.underscore'),

        CourseListSearch;

    require('backgrid-filter');

    CourseListSearch = Backgrid.Extension.ClientSideFilter.extend({
        className: function() {
            return [Backgrid.Extension.ClientSideFilter.prototype.className, 'course-list-search'].join(' ');
        },

        events: function() {
            var superEvents = Backgrid.Extension.ClientSideFilter.prototype.events;
            delete superEvents['keydown input[type=search]']; // Don't search on key down
            return _.extend(superEvents,
                {
                    'click .search': 'search',
                    'click .clear.btn': 'clear'
                }
            );
        },

        fields: ['catalog_course_title', 'course_id'],

        template: _.template(listSearchTemplate, null, {variable: null}),

        initialize: function(options) {
            this.options = options || {};
            this.listenTo(options.collection, 'backgrid:refresh', this.render);
            Backgrid.Extension.ClientSideFilter.prototype.initialize.call(this, options);
        },

        clearButton: function() {
            return this.$el.find('[data-backgrid-action=clear]');
        },

        render: function() {
            this.value = this.options.collection.getSearchString();
            this.$el.empty().append(this.template({
                id: 'search-course-list',
                name: this.name,
                placeholder: this.placeholder,
                value: this.value,
                labelText: gettext('Search courses'),
                executeSearchText: gettext('search'),
                clearSearchText: gettext('clear search')
            }));
            this.showClearButtonMaybe();
            this.delegateEvents();
            return this;
        },

        search: function(event) {
            var searchString = this.searchBox().val().trim();
            if (event) event.preventDefault();
            if (searchString === '') {
                this.options.collection.unsetSearchString();
            } else {
                this.options.collection.setSearchString(searchString);
                this.options.trackingModel.trigger('segment:track', 'edx.bi.course_list.searched', {
                    category: 'search'
{'fraction_non_alphanumeric': 0.11972930765226444, 'fraction_numerical': 0.001041124414367517, 'mean_word_length': 2.105603448275862, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5043593', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1387, 'n_words': 294}