<commit_before>define([
  'backbone',
  'handlebars',
  'chosen',
  'compare/presenters/CompareSelectorsPresenter',
  'compare/collections/CountriesCollection',
  'text!compare/templates/compareSelectorTpl.handlebars'
], function(Backbone, Handlebars, chosen, CompareSelectorsPresenter, CountriesCollection, tpl) {

  var CompareSelectorsView = Backbone.View.extend({

    el: '#compareSelectorsView',

    collection: CountriesCollection,

    template: Handlebars.compile(tpl),

    events: {
      'change select' : '_selectCountry'
    },

    status: new (Backbone.Model.extend({
    })),


    initialize:function() {
      this.presenter = new CompareSelectorsPresenter(this);

      this._setListeners();
      this._cacheVars();

      // Fetching data
      var complete = _.invoke([
        this.collection,
      ], 'fetch');

      $.when.apply($, complete).done(function() {
        this.render();
      }.bind(this));

    },

    _setListeners: function() {
    },

    _cacheVars: function() {
    },

    _getActiveCountries: function() {
      return _.where(this.collection.toJSON().countries, { 'enabled' : true });
    },

    render: function() {
      var countries = this._getActiveCountries();
      this.$el.html(this.template({'countries': countries}))

      this._stopSpinner();

      $('#country1').chosen();
      $('#country2').chosen();
      $('#country3').chosen();

      $('#country1').on('change', function(){
        console.log($("#country1").chosen().val());
      });

    },

    _stopSpinner: function() {
      this.$el.removeClass('is-loading');
    },

    _selectCountry: function(e) {
      var selector = $(e.currentTarget).attr('id');
      var selectedCountry = $(e.currentTarget).val();

      this.countrySelected(selectedCountry, selector);
    },

    countrySelected: function(country, selector) {
      this._updateStatus(country, selector);
      this._disableSelectors(country, selector);
      // this._updateUrl(country);
    },

    _updateStatus: function(country, selector) {
      this.status.set(selector, country);
    },

    _disableSelectors: function(country, selector) {
      var selectors = [country1, country2, country3];
      var index = selectors.indexOf(selector);

      selectors.splice(index, 1);

      console.log()


    },

    _updateUrl: function(country) {
      //Quien escucha esto? El presenter? Y se lo manda al PS?
      var route = location + country
      this.router.navigateTo(route, { silent: true });
      mps.publish('Compare/countrySelected', [this]);
    }

<commit_msg>separates chosen.js invocation into funcion<commit_after>define([
  'backbone',
  'handlebars',
  'chosen',
  'compare/presenters/CompareSelectorsPresenter',
  'compare/collections/CountriesCollection',
  'text!compare/templates/compareSelectorTpl.handlebars'
], function(Backbone, Handlebars, chosen, CompareSelectorsPresenter, CountriesCollection, tpl) {

  var CompareSelectorsView = Backbone.View.extend({

    el: '#compareSelectorsView',

    collection: CountriesCollection,

    template: Handlebars.compile(tpl),

    events: {
      'change select' : '_selectCountry'
    },

    status: new (Backbone.Model.extend({
    })),


    initialize:function() {
      this.presenter = new CompareSelectorsPresenter(this);

      this._setListeners();
      this._cacheVars();

      // Fetching data
      var complete = _.invoke([
        this.collection,
      ], 'fetch');

      $.when.apply($, complete).done(function() {
        this.render();
      }.bind(this));

    },

    _setListeners: function() {
    },

    _cacheVars: function() {
    },

    _getActiveCountries: function() {
      return _.where(this.collection.toJSON().countries, { 'enabled' : true });
    },

    render: function() {
      var countries = this._getActiveCountries();
      this.$el.html(this.template({'countries': countries}))
      this._invokeChosen();
      this._stopSpinner();



    },

    _stopSpinner: function() {
      this.$el.removeClass('is-loading');
    },

    _selectCountry: function(e) {
      var selector = $(e.currentTarget).attr('id');
      var selectedCountry = $(e.currentTarget).val();

      this.countrySelected(selectedCountry, selector);
    },

    countrySelected: function(country, selector) {
      this._updateStatus(country, selector);
      this._disableSelectors(country, selector);
      // this._updateUrl(country);
    },

    _updateStatus: function(country, selector) {
      this.status.set(selector, country);
    },

    _disableSelectors: function(country, selector) {
      var selectors = [country1, country2, country3];
      var index = selectors.indexOf(selector);

      selectors.splice(index, 1);

      console.log()
    },

    _updateUrl: function(country) {
      //Quien escucha esto? El presenter? Y se lo manda al PS?
      var route = location + country
      this.router.navigateTo(route, { silent: true });
      mps.publish('Compare/countrySelected', [this]);
    },


    _invokeChosen: function() {
      var countrySelectors = ['#country1', '#country2', '#country3'];
      for(var i = 0; i < countrySelectors.length; i++) {
        $(countrySelectors[i]).chosen();
      }
    }


{'fraction_non_alphanumeric': 0.1475598086124402, 'fraction_numerical': 0.0032535885167464117, 'mean_word_length': 3.0637636080870916, 'pattern_counts': {'":': 0, '<': 4, '<?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': '828888', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1511, 'n_words': 277}