define([
  "app",

  // Libs
  "backbone"

  // Plugins
],

function(app, Backbone) {
  var Views = {};

  Views.Item = Backbone.View.extend({
    template: "databases/item",
    tagName: "tr",

    serialize: function() {
      return {
        database: this.model
      };
    }
  });

  Views.List = Backbone.View.extend({
    template: "databases/list",
    events: {
      "click button.all": "selectAll"
    },

    initialize: function(options) {
      this.collection.on("add", this.render, this);
    },

    serialize: function() {
      return {
        databases: this.collection
      };
    },

    beforeRender: function() {
      this.collection.each(function(database) {
        this.insertView("table.databases tbody", new Views.Item({
          model: database
        }));
      }, this);
    },

    selectAll: function(evt){
      $("input:checkbox").attr('checked', !$(evt.target).hasClass('active'));
    }
  });

  Views.Sidebar = Backbone.View.extend({
    template: "databases/sidebar",
    events: {
      "click a#new": "newDatabase",
      "click a#owned": "showMine",
      "click a#shared": "showShared"
    },

    newDatabase: function() {
      // TODO: use a modal here instead of the prompt
      var name = prompt('Name of database', 'newdatabase');
      var db = new this.collection.model({
        id: encodeURIComponent(name),
        name: name
      });
      db.save();
      this.collection.add(db);
      // FIXME: The render that is triggered here fails to get status
      console.log("The render that is triggered here fails to get status");
    },

    showMine: function(){
      console.log('will show users databases and hide shared');
    },

    showShared: function(){
      console.log('will show shared databases and hide the users');
      alert('Support for shared databases coming soon');
    }
  });

  return Views;
});

@@ -1411,184 +1411,164 @@
 ve()
-;%0A      this.collection.add(db);%0A      // FIXME: The render that is triggered here fails to get status%0A      console.log(%22The render that is triggered here fails to get status%22
+.done(function() %7B%0A        var route = %22#/database/%22 +  name + %22/_all_docs?limit=100%22;%0A        app.router.navigate(route, %7B trigger: true %7D);%0A      %7D%0A      
 );%0A 

change create db workflow - redirect