<commit_before>/*jslint nomen: true */
/*globals define: true */

define([
  'jquery',
  'lib/lodash',
  'backbone',
  'lib/kissmetrics',

  // LocalData
  'settings',

  // Router
  'routers/index',

  // Views
  'views/home',
  'views/dashboard',
  'views/users',
  'views/surveys',
  'views/design',
  'views/settings'
],

function($, _, Backbone, _kmq, settings, IndexRouter, HomeView, DashboardView, UserViews, SurveyViews, DesignViews) {
  'use strict';

  var AllViews = {};
  AllViews.HomeView = HomeView;
  AllViews.DashboardView = DashboardView;

  AllViews.SurveyView = SurveyViews.SurveyView;
  AllViews.NewSurveyView= SurveyViews.NewSurveyView;
  AllViews.DesignView = DesignViews.DesignView;

  AllViews.LoginView = UserViews.LoginView;

  // The singleton view which manages all others.
  // Essentially, a "controller".
  var RootView = Backbone.View.extend({
    
    el: $("body"),
    views: {},
    _router: null,
    survey: null,
    
    initialize: function() {
      // Bind local methods
      _.bindAll(this);
      
      // Set up global router
      this._router = new IndexRouter({ controller: this });
      
      return this;
    },
    
    // Start Backbone routing. Separated from initialize() so that the
    // global controller is available for any preset routes (direct links).
    startRouting: function() {
      Backbone.history.start();
    },
      
    // Register each view as it is created and never create more than one.
    getOrCreateView: function(viewClass, viewName, options) {
      // _kmq.push(['record', name]);
      
      // If the view already exists, use it.
      // If it doesn't exist, create it.
      if (_.has(this.views, viewName)) {
        console.log("Going to " + viewName);

      } else {
        console.log("Creating view " + viewName);
        this.views[viewName] = new AllViews[viewClass](options);
      }

      this.views[viewName].update();
      return this.views[viewName];
    },
        
    // Handle routes (they're in routers/index.js) .............................
    // Home
    goto_home: function() {
      // this.currentContentView = this.getOrCreateView("HomeView", "HomeView");
      this.currentContentView = this.getOrCreateView("DashboardView", "DashboardView");

    },

    goto_login: function(redirectTo) {
      // We want to create this view from scratch every time
      this.currentContentView = this.views['LoginView'] = new AllViews['LoginView']({redirectTo: redirectTo});
      // this.getOrCreateView("LoginView", "LoginView", {redirectTo: redirectTo});
    },
    
    // Survey dashboard routes .................................................
    goto_survey: function(tab) {
      _kmq.push(['record', "SurveyView"]);

      // Get or create a view for the survey
      var surveyViewName = "Survey" + settings.surveyId;
      this.currentContentView = this.getOrCreateView("SurveyView", surveyViewName, {id: settings.surveyId});

      // Show the correct tab
      switch(tab) {
        case undefined:
          this.currentContentView.showResponses();
          break;
        case "export":
          this.currentContentView.showExport();
          break;
        case "form":
          this.currentContentView.showForm();
          break;
        case "settings":
          this.currentContentView.showSettings();
          break;
          
      }
    },

    goto_new: function() {
      console.log("Going to new");
      this.currentContentView = this.getOrCreateView("NewSurveyView", "NewSurveyView");
    },
    
    goto_settings: function() {
      console.log("-----------------------Going to settings");
      _kmq.push(['record', "SettingsView"]);
      this._router.navigate("surveys/" + settings.slug + "/settings");
      this.goto_survey("settings");
    },
    
    goto_form: function() {<commit_msg>remove errant comment<commit_after>/*jslint nomen: true */
/*globals define: true */

define([
  'jquery',
  'lib/lodash',
  'backbone',
  'lib/kissmetrics',

  // LocalData
  'settings',

  // Router
  'routers/index',

  // Views
  'views/home',
  'views/dashboard',
  'views/users',
  'views/surveys',
  'views/design',
  'views/settings'
],

function($, _, Backbone, _kmq, settings, IndexRouter, HomeView, DashboardView, UserViews, SurveyViews, DesignViews) {
  'use strict';

  var AllViews = {};
  AllViews.HomeView = HomeView;
  AllViews.DashboardView = DashboardView;

  AllViews.SurveyView = SurveyViews.SurveyView;
  AllViews.NewSurveyView= SurveyViews.NewSurveyView;
  AllViews.DesignView = DesignViews.DesignView;

  AllViews.LoginView = UserViews.LoginView;

  // The singleton view which manages all others.
  // Essentially, a "controller".
  var RootView = Backbone.View.extend({
    
    el: $("body"),
    views: {},
    _router: null,
    survey: null,
    
    initialize: function() {
      // Bind local methods
      _.bindAll(this);
      
      // Set up global router
      this._router = new IndexRouter({ controller: this });
      
      return this;
    },
    
    // Start Backbone routing. Separated from initialize() so that the
    // global controller is available for any preset routes (direct links).
    startRouting: function() {
      Backbone.history.start();
    },
      
    // Register each view as it is created and never create more than one.
    getOrCreateView: function(viewClass, viewName, options) {
      // _kmq.push(['record', name]);
      
      // If the view already exists, use it.
      // If it doesn't exist, create it.
      if (_.has(this.views, viewName)) {
        console.log("Going to " + viewName);

      } else {
        console.log("Creating view " + viewName);
        this.views[viewName] = new AllViews[viewClass](options);
      }

      this.views[viewName].update();
      return this.views[viewName];
    },
        
    // Handle routes (they're in routers/index.js) .............................
    // Home
    goto_home: function() {
      // this.currentContentView = this.getOrCreateView("HomeView", "HomeView");
      this.currentContentView = this.getOrCreateView("DashboardView", "DashboardView");

    },

    goto_login: function(redirectTo) {
      // We want to create this view from scratch every time
      this.currentContentView = this.views['LoginView'] = new AllViews['LoginView']({redirectTo: redirectTo});
      // this.getOrCreateView("LoginView", "LoginView", {redirectTo: redirectTo});
    },
    
    // Survey dashboard routes .................................................
    goto_survey: function(tab) {
      _kmq.push(['record', "SurveyView"]);

      // Get or create a view for the survey
      var surveyViewName = "Survey" + settings.surveyId;
      this.currentContentView = this.getOrCreateView("SurveyView", surveyViewName, {id: settings.surveyId});

      // Show the correct tab
      switch(tab) {
        case undefined:
          this.currentContentView.showResponses();
          break;
        case "export":
          this.currentContentView.showExport();
          break;
        case "form":
          this.currentContentView.showForm();
          break;
        case "settings":
          this.currentContentView.showSettings();
          break;
          
      }
    },

    goto_new: function() {
      console.log("Going to new");
      this.currentContentView = this.getOrCreateView("NewSurveyView", "NewSurveyView");
    },
    
    goto_settings: function() {
      _kmq.push(['record', "SettingsView"]);
      this._router.navigate("surveys/" + settings.slug + "/settings");
      this.goto_survey("settings");
    },
    
    goto_form: function() {
{'fraction_non_alphanumeric': 0.15097551394526645, 'fraction_numerical': 0.0, 'mean_word_length': 2.4098214285714286, 'pattern_counts': {'":': 6, '<': 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': '6839211', 'n_tokens_mistral': 2255, 'n_tokens_neox': 2218, 'n_words': 511}