<commit_before>var cdb = require('cartodb.js');
var RouterModel = require('../../../new_dashboard/router/model');
var NavigationView = require('./listing/navigation_view');
var DatasetsView = require('./listing/datasets_view');
var ImportsView = require('./listing/imports_view');

/**
 *  Create listing view
 *
 *  It will display all the possibilities to select
 *  any of your current datasets or connect a new dataset.
 *
 */

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

  className: 'CreateDialog-listing',

  initialize: function() {
    var self = this;
    this.user = this.options.user;
    this.currentUserUrl = this.options.currentUserUrl;
    this.createModel = this.options.createModel;
    this.template = cdb.templates.getTemplate('new_common/views/create/create_listing');
    this.model = new cdb.core.Model({
      state: !this.user.canCreateDatasets() || this.createModel.get('type') === "map" ? 'list' : 'import', // import or list states
      collectionFetched: false
    });

    this.routerModel = new RouterModel({
      content_type: 'datasets',
      library: this.createModel.isDatasetType(),
      rootUrlForCurrentTypeFn: function() {
        return self.currentUserUrl[ 'datasetsUrl' ]();
      }
    });

    this.collection = new cdb.admin.Visualizations();

    this._initBinds();
    this._optionCheck();
  },

  render: function() {
    this.clearSubViews();
    this.$el.html(this.template());
    this._initViews();
    return this;
  },

  _initBinds: function() {
    this.model.bind('change:state', this._setState, this);
    this.createModel.bind('change:option', this._optionCheck, this);
    this.routerModel.bind('change', this._fetchCollection, this);
    this.add_related_model(this.routerModel);
    this.add_related_model(this.createModel);
  },

  _initViews: function() {
    // Navigation view
    var navigationView = new NavigationView({
      el: this.$('.js-navigation'),
      user: this.user,
      routerModel: this.routerModel,
      createModel: this.createModel,
      collection: this.collection,
      model: this.model
    })
    navigationView.render();
    this.addView(navigationView);

    // Listing content pane
    // - Datasets view
    // - Imports view

    // Listing pane
    this.listingPane = new cdb.ui.common.TabPane({
      el: this.$(".ListingContent")
    });
    this.addView(this.listingPane);

    // Datasets view
    var datasetsView = new DatasetsView({
      user: this.user,
      createModel: this.createModel,
      routerModel: this.routerModel,
      collection: this.collection
    });

    datasetsView.bind('remoteSelected', function(d) {
      this.trigger('remoteSelected', d, this);
    }, this);

    datasetsView.render();
    this.listingPane.addTab('list', datasetsView);

    // Imports view
    if (this.user.canCreateDatasets()) {
      var importsView = new ImportsView({
        user: this.user,
        createModel: this.createModel,
        currentUserUrl: this.currentUserUrl
      });

      importsView.render();
      this.listingPane.addTab('import', importsView);
    }
  },

  _setState: function() {
    this.listingPane.active(this.model.get('state'));
    this.createModel.setListingState(this.model.get('state'));<commit_msg>Fixing problem setting active pane within new create dialog<commit_after>var cdb = require('cartodb.js');
var RouterModel = require('../../../new_dashboard/router/model');
var NavigationView = require('./listing/navigation_view');
var DatasetsView = require('./listing/datasets_view');
var ImportsView = require('./listing/imports_view');

/**
 *  Create listing view
 *
 *  It will display all the possibilities to select
 *  any of your current datasets or connect a new dataset.
 *
 */

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

  className: 'CreateDialog-listing',

  initialize: function() {
    var self = this;
    this.user = this.options.user;
    this.currentUserUrl = this.options.currentUserUrl;
    this.createModel = this.options.createModel;
    this.template = cdb.templates.getTemplate('new_common/views/create/create_listing');
    this.model = new cdb.core.Model({
      state: !this.user.canCreateDatasets() || this.createModel.get('type') === "map" ? 'list' : 'import', // import or list states
      collectionFetched: false
    });

    this.routerModel = new RouterModel({
      content_type: 'datasets',
      library: this.createModel.isDatasetType(),
      rootUrlForCurrentTypeFn: function() {
        return self.currentUserUrl[ 'datasetsUrl' ]();
      }
    });

    this.collection = new cdb.admin.Visualizations();

    this._initBinds();
    this._optionCheck();
  },

  render: function() {
    this.clearSubViews();
    this.$el.html(this.template());
    this._initViews();
    return this;
  },

  _initBinds: function() {
    this.model.bind('change:state', this._setState, this);
    this.createModel.bind('change:option', this._optionCheck, this);
    this.routerModel.bind('change', this._fetchCollection, this);
    this.add_related_model(this.routerModel);
    this.add_related_model(this.createModel);
  },

  _initViews: function() {
    // Navigation view
    var navigationView = new NavigationView({
      el: this.$('.js-navigation'),
      user: this.user,
      routerModel: this.routerModel,
      createModel: this.createModel,
      collection: this.collection,
      model: this.model
    })
    navigationView.render();
    this.addView(navigationView);

    // Listing content pane
    // - Datasets view
    // - Imports view

    // Listing pane
    this.listingPane = new cdb.ui.common.TabPane({
      el: this.$(".ListingContent")
    });
    this.addView(this.listingPane);

    // Datasets view
    var datasetsView = new DatasetsView({
      user: this.user,
      createModel: this.createModel,
      routerModel: this.routerModel,
      collection: this.collection
    });

    datasetsView.bind('remoteSelected', function(d) {
      this.trigger('remoteSelected', d, this);
    }, this);

    datasetsView.render();
    this.listingPane.addTab('list', datasetsView);

    // Imports view
    if (this.user.canCreateDatasets()) {
      var importsView = new ImportsView({
        user: this.user,
        createModel: this.createModel,
        currentUserUrl: this.currentUserUrl
      });

      importsView.render();
      this.listingPane.addTab('import', importsView);
    }
  },

  _setState: function() {
    if (this.listingPane) {
      this.listingPane.active(this.model.get('state'));
    }
    this.createModel.setListingState(this.model.get('state'));
{'fraction_non_alphanumeric': 0.14005474452554745, 'fraction_numerical': 0.0, 'mean_word_length': 3.173223350253807, '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': '2278901', 'n_tokens_mistral': 1991, 'n_tokens_neox': 1950, 'n_words': 381}