$(function() {
  App.users = new App.Users;
  App.posts = new App.Posts;
  App.tags = new App.Tags;
  App.session = new App.Session;

  App.region = new App.Region;
  App.overlay = new App.Overlay;
  App.router = new App.Router;

  // Router

  App.router.on('all', function routeAll(route) {
    var name = route.split(':')[1];
    if(name) {
      App.menuView.select(name);
    }
  });

  // Form

  App.loginForm = new App.FormView({
    name: 'login',
    model: App.session,
    fields: {
      username: {type: 'string', label: 'Username'},
      password: {type: 'string', label: 'Password', attributes: {'type': 'password'}}
    },
    onSuccess: function() {
      App.overlay.hide();
      App.router.navigate('dashboard', {trigger: true});
    }
  });

  App.postForm = new App.FormView({
    name: 'posts',
    collection: App.posts,
    fields: {
      title: {type: 'string', label: 'Title'},
      body: {type: 'text', label: 'Body'},
      published: {type: 'boolean', label: 'Published'}
    },
    onRender: function() {
      var $label = $('<div/>', {text:'Tags:'});
      var $ul = $('<ul/>', {'class': 'editable'});
      this.addWidget($label);
      this.addWidget($ul);
      $($ul).editable();
    }
  });

  App.userForm = new App.FormView({
    name: 'users',
    collection: App.users,
    fields: {
      username: {type: 'string', label: 'Username'},
      password: {type: 'string', label: 'Password', attributes: {'type': 'password'}},
      firstname: {type: 'string', label: 'First name'},
      lastname: {type: 'string', label: 'Last name'},
      email: {type: 'string', label: 'Email'},
      isStaff: {type: 'boolean', label: 'Is staff'}
    }
  });

  App.tagForm = new App.FormView({
    name: 'tags',
    collection: App.tags,
    fields: {
      title: {type: 'string', label: 'Title'}
    }
  });

  // Views

  App.userView = new App.UserView({model: App.session});
  App.menuView = new App.MenuView;

  App.postsView = new App.ListView({
    collection: App.posts,
    name: 'posts',
    columns: [
      {'label': 'Title', 'value': 'title'},
      {'label': 'Created at', 'value': 'createdAt', 'type': 'date'},
      {'label': 'Published', 'value': 'published', 'type': 'bool'}
    ]
  });

  App.tagsView = new App.ListView({
    collection: App.tags,
    name: 'tags',
    columns: [
      {'label': 'Title', 'value': 'title'},
      {'label': 'Created at', 'value': 'createdAt', 'type': 'date'}
    ]
  });

  App.usersView = new App.ListView({
    collection: App.users,
    name: 'users',
    columns: [
      {'label': 'Username', 'value': 'username'},
      {'label': 'Created at', 'value': 'createdAt', 'type': 'date'},
      {'label': 'Is staff', 'value': 'isStaff', 'type': 'bool'}
    ]
  });
  Backbone.history.start();
  App.session.fetch();
});
@@ -636,24 +636,45 @@
    %7D
-,
 %0A  
-  onS
+%7D);%0A%0A  App.loginForm.on('s
 uccess
-:
+',
  fun
@@ -680,25 +680,22 @@
 nction()
- 
 %7B%0A    
- 
- 
 App.over
@@ -706,18 +706,16 @@
 hide();%0A
-  
     App.
@@ -761,22 +761,16 @@
 true%7D);%0A
-    %7D%0A
   %7D);%0A%0A 
@@ -1203,28 +1203,1309 @@
 l);%0A
+%0A
       
-$($ul).editabl
+this.editable = $($ul).editable();%0A    %7D%0A  %7D);%0A%0A  App.postForm.on('unload', function() %7B%0A    this.editable.clear();%0A  %7D);%0A%0A  App.postForm.on('load', function(model) %7B%0A    $.getJSON('/posts/' + model.get('id') + '/tags', this.editable.load.bind(this.editable));%0A  %7D);%0A%0A  App.postForm.on('saved', function() %7B%0A    var data = this.editable.serialize();%0A    var unsaved = data.filter(function(tag) %7B return !tag.id; %7D);%0A    var saved = 0;%0A%0A    var onSave = (function(model) %7B%0A      this.editable.getElements().filter(function() %7B%0A          return $(this).text() === model.get('title');%0A        %7D).data('id', model.get('id'));%0A    %7D.bind(this));%0A%0A    var done = (function() %7B%0A      var url = '/posts/' + this.model.get('id') + '/tags';%0A      var data = this.editable.serialize();%0A      //TODO Try to simplify this?%0A      $.ajax(%7B%0A        url: url,%0A        data: JSON.stringify(%7Bdata: data%7D),%0A        type: 'POST',%0A        contentType: 'application/json'%0A      %7D);%0A    %7D.bind(this));%0A%0A    if(unsaved.length) %7B%0A      unsaved.forEach(function(tag, index, tags) %7B%0A        var model = App.tags.create(tag);%0A        model.on('sync', function() %7B%0A          saved ++;%0A          onSave(model);%0A          if(saved === tags.length) %7B%0A            done();%0A          %7D%0A        %7D);%0A      %7D);%0A    %7D else %7B%0A      don
 e();

Add tag association