<commit_before>app.filterWidgets.OptionView = Backbone.View.extend({

  tagName: 'li',

  template: _.template('<a href="#">' +
                       '  <%= optionValue || "unknown" %> (<%= count %>)' +
                       '</a>'),

  events: {
    'click': 'select'
  },

  render: function() {
    var context = _.extend({
      count: this.model.countNotExcluded()
    }, this.model.attributes);
    this.$el.html(this.template(context));
    if (this.model.get('selected')) {
      this.$el.addClass('selected');
    }
    return this;
  },

  select: function() {
    this.model.trigger('selectme', this.model);
  }

});


app.filterWidgets.Select = Backbone.View.extend({

  tagName: 'li',

  template: _.template('<a class="activate" href="#"><%= name %></a>' +
                       '<div class="map-control-dropdown">' +
                       '</div>'),

  dropDownTemplate: _.template('<ul></ul>'),  // broken out to easily override

  events: {
    'click >.activate': 'selectUIActivate',
    'keyup': 'selectUIKeyNav'
  },

  initialize: function() {
    this.rendered = false;
    // this.optionViews = {};  // {cid: el}
    this.model.options.each(this.addOption);
    this.listenTo(this.model, 'change:value', this.setSelect);
    this.listenTo(this.model.options, 'add', this.addOption);
    this.listenTo(this.model.options, 'sort', this.reorderOptions);
    this.listenTo(this.model, 'filtersupdated', this.filtersUpdated);
  },

  render: function() {
    this.$el.html(this.template(this.model.attributes));
    this.$('.map-control-dropdown').html(this.dropDownTemplate());
    if (! this.rendered) {
      this.reorderOptions();
      this.rendered = true;
    }
    return this;
  },

  addOption: function(option) {
    // var view = new app.filterWidgets.OptionView({ model: option });
    // this.optionViews[option.cid] = view;
    this.reorderOptions();
  },

  reorderOptions: function() {
    if (! this.rendered) {
      return;
    }
    this.$('.map-control-dropdown > ul').html(this.model.options.map(function(option) {
      return (new app.filterWidgets.OptionView({ model: option })).render().el;
    }, this));
  },

  setSelect: function(model, newValue) {
    this.$('> .activate').text(newValue || 'unknown');
  },

  filtersUpdated: function() {
    this.model.options.sort();
  },

  selectUIActivate: function(e) {
    e.preventDefault();
    this.$el.toggleClass('active');
  },

  selectUIKeyNav: function(e) {
    console.log('selectUIKeyNav');
  }

});<commit_msg>dropdowns are sane sort of<commit_after>app.filterWidgets.OptionView = Backbone.View.extend({

  tagName: 'li',

  template: _.template('<a href="#">' +
                       '  <%= optionValue || "unknown" %> (<%= count %>)' +
                       '</a>'),

  events: {
    'click': 'select'
  },

  initialize: function() {
    this.listenTo(this.model, 'change:selected', this.changeSelected);
  },

  render: function() {
    var context = _.extend({
      count: this.model.countNotExcluded()
    }, this.model.attributes);
    this.$el.html(this.template(context));
    return this;
  },

  select: function(e) {
    e.preventDefault();
    this.model.trigger('selectme', this.model);
  },

  changeSelected: function(myModel, selected) {
    this.$el[selected? 'addClass' : 'removeClass']('selected');
  }

});


app.filterWidgets.Select = Backbone.View.extend({

  tagName: 'li',

  template: _.template('<a class="activate" href="#"><%= name %></a>' +
                       '<div class="map-control-dropdown">' +
                       '</div>'),

  dropDownTemplate: _.template('<ul></ul>'),  // broken out to easily override

  events: {
    'click >.activate': 'selectUIActivate',
    'keyup': 'selectUIKeyNav'
  },

  initialize: function() {
    this.rendered = false;
    // this.optionViews = {};  // {cid: el}
    this.model.options.each(this.addOption);
    this.listenTo(this.model, 'change:value', this.setSelect);
    this.listenTo(this.model.options, 'add', this.addOption);
    this.listenTo(this.model.options, 'sort', this.reorderOptions);
  },

  render: function() {
    this.$el.html(this.template(this.model.attributes));
    this.$('.map-control-dropdown').html(this.dropDownTemplate());
    if (! this.rendered) {
      this.reorderOptions();
      this.rendered = true;
    }
    return this;
  },

  addOption: function(option) {
    // var view = new app.filterWidgets.OptionView({ model: option });
    // this.optionViews[option.cid] = view;
    this.reorderOptions();
  },

  reorderOptions: function() {
    if (! this.rendered) {
      return;
    }
    this.$('.map-control-dropdown > ul').html(this.model.options.map(function(option) {
      return (new app.filterWidgets.OptionView({ model: option })).render().el;
    }, this));
  },

  setSelect: function(model, newValue) {
    this.$('> .activate').text(newValue || 'unknown');
  },

  selectUIActivate: function(e) {
    e.preventDefault();
    this.$el.toggleClass('active');
  },

  selectUIKeyNav: function(e) {
    console.log('selectUIKeyNav');
  }

});
{'fraction_non_alphanumeric': 0.18731534370691352, 'fraction_numerical': 0.0, 'mean_word_length': 2.9456099456099456, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 31, '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': '2954761', 'n_tokens_mistral': 1656, 'n_tokens_neox': 1610, 'n_words': 267}