"use strict";

$(function(){
  var Workspace = Backbone.Router.extend({
    routes: {
      "": "index",
      "event/:id": "event"
    },

    index: function() {
      console.log('showing index');
    },

    event: function(id) {
      console.log('showing event');

      window.Evento = Backbone.Model.extend({
        url: '/event'
      });

      window.EventList = Backbone.Collection.extend({
        url: '/event-col',
        model: Evento
      });

      window.Events = new EventList;

      window.EventView = Backbone.View.extend({
        initialize: function() {
          //this.model.bind('change', this.render, this);
          //this.model.bind('destroy', this.remove, this);


          console.log('EventView: init');
        },
        remove: function() {
          $(this.el).remove();
        },
        render: function(callback) {
          dust.render('event_nginx_access', this.model.toJSON(), function(err, out) {
            console.log('rendering', err, out);
            console.log('EventView: rendering', this.parent);
            callback(out);
          });
        }
      });

      window.EventPageView = Backbone.View.extend({
        el: $('#backbone-view'),
        initialize: function() {
          Events.bind('add', this.addOne, this);

          /*var data = {
    "host": "127.0.0.1",
    "user": "-",
    "time": "16/Feb/2012:12:05:59 +0000",
    "method": "GET",
    "path": "/js/jquery-ui-1.8.16.custom.min.js",
    "code": "200",
    "size": "581",
    "referer": "http://diana/js/jquery-1.7.1.min.js",
    "agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:10.0.1) Gecko/20100101 Firefox/10.0.1",
    "parser": "nginx_access",
    "tags": 'none'
          };*/
          /*var m = new Evento({id: "4f3cf1279010fd0a11000004"});
          console.log(m.url());
          m.fetch({
            success: function(model, response) {
              console.log('fetch success', model, response);
              Events.create(m);
            },
            error: function(model, response) {
              console.log('fetch error', model, response);
            }
          });*/
          var m = new Evento();
          m.fetch({
            url: '/event/' + id,
            success: function(model, response) {
              console.log('fetch success', model, response);
              Events.add(m);
            },
            error: function(model, response) {
              console.log('fetch error', model, response);
            }
          });*/
          console.log('fetch called');
        },
        addOne: function(event) {
          // not really adding one, just updating the template with actual values
          //this.render();
          var view = new EventView({model: event});
          var parent = $(this.el);
          view.render(function(out) {
            console.log('addone got', out);
            parent.html(out);
          });
          console.log('adding one', event);
        },
      });

      window.EventPageView= new EventPageView();
    },
  });


  new Workspace();
  Backbone.history.start();
});

@@ -165,339 +165,119 @@
     
-  console.log('showing index');%0A    %7D,%0A%0A    event: function(id) %7B%0A      console.log('showing event');%0A%0A      window.Evento = Backbone.Model.extend(%7B%0A        url: '/event'%0A      %7D);%0A%0A      window.EventList = Backbone.Collection.extend(%7B%0A        url: '/event-col',%0A        model: Evento%0A      %7D);%0A%0A      window.Events = new EventList
+%7D,%0A%0A    event: function(id) %7B%0A      window.Evento = Backbone.Model.extend(%7B%0A        urlRoot: '/event',%0A      %7D)
 ;%0A%0A 
@@ -358,34 +358,32 @@
 n() %7B%0A          
-//
 this.model.bind(
@@ -416,182 +416,8 @@
 s);%0A
-          //this.model.bind('destroy', this.remove, this);%0A%0A%0A          console.log('EventView: init');%0A        %7D,%0A        remove: function() %7B%0A          $(this.el).remove();%0A
     
@@ -456,24 +456,67 @@
 callback) %7B%0A
+          var foo = this.model.get('foo');%0A
           du
@@ -605,126 +605,19 @@
     
-console.log('rendering', err, out);%0A            console.log('EventView: rendering', this.parent);%0A            callback
+$(foo).html
 (out
@@ -786,1456 +786,88 @@
     
-Events.bind('add', this.addOne, this);%0A%0A          /*var data = %7B%0A    %22host%22: %22127.0.0.1%22,%0A    %22user%22: %22-%22,%0A    %22time%22: %2216/Feb/2012:12:05:59 +0000%22,%0A    %22method%22: %22GET%22,%0A    %22path%22: %22/js/jquery-ui-1.8.16.custom.min.js%22,%0A    %22code%22: %22200%22,%0A    %22size%22: %22581%22,%0A    %22referer%22: %22http://diana/js/jquery-1.7.1.min.js%22,%0A    %22agent%22: %22Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:10.0.1) Gecko/20100101 Firefox/10.0.1%22,%0A    %22parser%22: %22nginx_access%22,%0A    %22tags%22: 'none'%0A          %7D;*/%0A          /*var m = new Evento(%7Bid: %224f3cf1279010fd0a11000004%22%7D);%0A          console.log(m.url());%0A          m.fetch(%7B%0A            success: function(model, response) %7B%0A              console.log('fetch success', model, response);%0A              Events.create(m);%0A            %7D,%0A            error: function(model, response) %7B%0A              console.log('fetch error', model, response);%0A            %7D%0A          %7D);*/%0A          var m = new Evento();%0A          m.fetch(%7B%0A            url: '/event/' + id,%0A            success: function(model, response) %7B%0A              console.log('fetch success', model, response);%0A              Events.add(m);%0A            %7D,%0A            error: function(model, response) %7B%0A              console.log('fetch error', model, response);%0A            %7D%0A          %7D);*/%0A          console.log('fetch called');%0A        %7D,%0A        addOne: function(event) %7B%0A          // not really adding one, just updating the template with actual values%0A          //this.render
+var m = new Evento(%7Bid: id%7D);%0A          m.set('foo', this.el);%0A          m.fetch
 ();%0A
@@ -909,21 +909,17 @@
 %7Bmodel: 
-event
+m
 %7D);%0A    
@@ -929,199 +929,19 @@
    v
-ar parent = $(this.el);%0A          view.render(function(out) %7B%0A            console.log('addone got', out);%0A            parent.html(out);%0A          %7D);%0A          console.log('adding one', event
+iew.render(
 );%0A 
@@ -944,25 +944,24 @@
 );%0A        %7D
-,
 %0A      %7D);%0A%0A
@@ -1023,17 +1023,16 @@
 %0A  %7D);%0A%0A
-%0A
   new Wo

Simplify event viewer w/out collection