// Generated by CoffeeScript 1.3.3
var __slice = [].slice;

define(['environ', 'jquery', 'underscore', 'backbone', 'router', 'session', 'models/datafield', 'models/dataconcept'], function(environ, $, _, Backbone) {
  var modules, routes;
  routes = App.routes;
  modules = _.pluck(routes, 'module');
  return require(modules, function() {
    var config, fragment, i, klasses, root, _i, _len;
    klasses = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
    root = environ.SCRIPT_NAME || '/';
    if (root.substr(root.length - 1) !== '/') {
      root = root + '/';
    }
    for (i = _i = 0, _len = routes.length; _i < _len; i = ++_i) {
      config = routes[i];
      if (!config.module) {
        continue;
      }
      fragment = config.url ? config.url.substr(root.length) : false;
      App.register(fragment, config.name, new klasses[i](config.options));
    }
    Backbone.history.start({
      root: root,
      pushState: true
    });
    App.preferences.load();
    require(['models/datacontext', 'models/dataview']);
    return $(function() {
      var li, nav, route, _j, _len1;
      nav = $('<ul class="nav pull-left" />');
      for (_j = 0, _len1 = routes.length; _j < _len1; _j++) {
        route = routes[_j];
        if (!route.url) {
          continue;
        }
        li = $("<li><a href=\"" + route.url + "\" data-route=\"" + route.name + "\">" + route.label + "</a></li>");
        nav.append(li);
      }
      nav.appendTo('header .container-fluid');
      return $('body').on('click', '[data-route]', function(event) {
        var frag;
        event.preventDefault();
        frag = $(this).data('route');
        if (frag.substr(frag.length - 1) !== '/') {
          frag = frag + '/';
        }
        return App.router.navigate(frag, {
          trigger: true
        });
      });
    });
  });
});
