<commit_before>var cdb = require('cartodb.js');
var _ = require('underscore');

/**
 *  Create footer view
 *
 *  It will show possible choices depending the
 *  selected option and the state of the main model
 *
 */

module.exports = cdb.core.View.extend({

  events: {
    'click .js-templates': '_goToTemplates',
    'click .js-guessing': '_setContentGuessing',
    'click .js-create_map': '_createMap',
    'click .js-connect': '_connectDataset',
    'click .js-start': '_start'
  },

  initialize: function() {
    this.user = this.options.user;
    this.createModel = this.options.createModel
    this.model = new cdb.core.Model({ type_guessing: true });
    this.template = cdb.templates.getTemplate('new_common/views/create/create_footer');
    this._initBinds();
  },

  render: function() {
    var userCanUpgrade = window.upgrade_url && !cdb.config.get('custom_com_hosted') && (!this.user.isInsideOrg() || this.user.isOrgAdmin() );

    this.$el.html(
      this.template({
        isMapType: this.createModel.isMapType(),
        typeGuessing: this.model.get('type_guessing'),
        option: this.createModel.getOption(),
        listingState: this.createModel.getListingState(),
        datasetsState: this.createModel.getDatasetsState(),
        importState: this.createModel.getImportState(),
        enabledUpload: this._enabledUpload(),
        isUploadValid: this._validUpload(),
        selectedDatasetsCount: this.createModel.getSelectedDatasets().length,
        maxSelectedDatasets: this.user.get('max_layers') || 10,
        mapTemplate: this.createModel.get('mapTemplate'),
        customHosted: cdb.config.get('custom_com_hosted'),
        userCanUpgrade: userCanUpgrade,
        upgradeUrl: window.upgrade_url,
        currentUrl: window.location.href
      })
    );
    return this;
  },

  _initBinds: function() {
    this.createModel.bind('change:upload', this.render, this);
    this.createModel.bind('change:option', this.render, this);
    this.createModel.bind('change:selectedDatasets', this.render, this);
    this.model.bind('change:type_guessing', this.render, this);
    this.add_related_model(this.createModel);
  },

  _connectDataset: function() {
    if (this._validUpload()) {
      var d = _.extend(this.createModel.getUpload(), { type_guessing: this.model.get('type_guessing') });
      this.createModel.setUpload(d);
      this.trigger('datasetSelected', this);
    }
  },

  _setContentGuessing: function() {
    if (this._validUpload()) {
      this.model.set('type_guessing', !this.model.get('type_guessing'));
    }
  },

  _enabledUpload: function() {
    var upload = this.createModel.getUpload();
    return upload && !_.isEmpty(upload)
  },

  _validUpload: function() {
    var upload = this.createModel.getUpload();
    return upload && !_.isEmpty(upload) && upload.value && upload.state !== "error";
  },

  _start: function(e) {
    e.preventDefault();
    e.stopPropagation();

    this.trigger('start', this);

  },

  _goToTemplates: function(e) {
    if (e) e.preventDefault();<commit_msg>uses convenient method<commit_after>var cdb = require('cartodb.js');
var _ = require('underscore');

/**
 *  Create footer view
 *
 *  It will show possible choices depending the
 *  selected option and the state of the main model
 *
 */

module.exports = cdb.core.View.extend({

  events: {
    'click .js-templates': '_goToTemplates',
    'click .js-guessing': '_setContentGuessing',
    'click .js-create_map': '_createMap',
    'click .js-connect': '_connectDataset',
    'click .js-start': '_start'
  },

  initialize: function() {
    this.user = this.options.user;
    this.createModel = this.options.createModel
    this.model = new cdb.core.Model({ type_guessing: true });
    this.template = cdb.templates.getTemplate('new_common/views/create/create_footer');
    this._initBinds();
  },

  render: function() {
    var userCanUpgrade = window.upgrade_url && !cdb.config.get('custom_com_hosted') && (!this.user.isInsideOrg() || this.user.isOrgAdmin() );

    this.$el.html(
      this.template({
        isMapType: this.createModel.isMapType(),
        typeGuessing: this.model.get('type_guessing'),
        option: this.createModel.getOption(),
        listingState: this.createModel.getListingState(),
        datasetsState: this.createModel.getDatasetsState(),
        importState: this.createModel.getImportState(),
        enabledUpload: this._enabledUpload(),
        isUploadValid: this._validUpload(),
        selectedDatasetsCount: this.createModel.getSelectedDatasets().length,
        maxSelectedDatasets: this.user.get('max_layers') || 10,
        mapTemplate: this.createModel.get('mapTemplate'),
        customHosted: cdb.config.get('custom_com_hosted'),
        userCanUpgrade: userCanUpgrade,
        upgradeUrl: window.upgrade_url,
        currentUrl: window.location.href
      })
    );
    return this;
  },

  _initBinds: function() {
    this.createModel.bind('change:upload', this.render, this);
    this.createModel.bind('change:option', this.render, this);
    this.createModel.bind('change:selectedDatasets', this.render, this);
    this.model.bind('change:type_guessing', this.render, this);
    this.add_related_model(this.createModel);
  },

  _connectDataset: function() {
    if (this._validUpload()) {
      var d = _.extend(this.createModel.getUpload(), { type_guessing: this.model.get('type_guessing') });
      this.createModel.setUpload(d);
      this.trigger('datasetSelected', this);
    }
  },

  _setContentGuessing: function() {
    if (this._validUpload()) {
      this.model.set('type_guessing', !this.model.get('type_guessing'));
    }
  },

  _enabledUpload: function() {
    var upload = this.createModel.getUpload();
    return upload && !_.isEmpty(upload)
  },

  _validUpload: function() {
    var upload = this.createModel.getUpload();
    return upload && !_.isEmpty(upload) && upload.value && upload.state !== "error";
  },

  _start: function(e) {
    if (e) this.killEvents(e)

    this.trigger('start', this);
  },

  _goToTemplates: function(e) {
    if (e) e.preventDefault();
{'fraction_non_alphanumeric': 0.1494177464326718, 'fraction_numerical': 0.0006560603575528948, 'mean_word_length': 3.56437125748503, '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': '1794844', 'n_tokens_mistral': 1939, 'n_tokens_neox': 1893, 'n_words': 326}