3 window.SliverView = Backbone.View.extend({
8 'click .permalink': 'navigate'
11 initialize: function(){
12 this.model.bind('change', this.render, this);
15 navigate: function(e){
16 this.trigger('navigate', this.model);
21 $(this.el).html(ich.sliverTemplate(this.model.toJSON()));
27 window.DetailApp = Backbone.View.extend({
38 $(this.el).html(ich.detailApp(this.model.toJSON()));
43 window.ListView = Backbone.View.extend({
44 initialize: function(){
45 _.bindAll(this, 'addOne', 'addAll');
47 this.collection.bind('add', this.addOne);
48 this.collection.bind('reset', this.addAll, this);
54 this.collection.each(this.addOne);
57 addOne: function(sliver){
58 var view = new SliverView({
61 $(this.el).prepend(view.render().el);
62 this.views.push(view);
63 view.bind('all', this.rethrow, this);
67 this.trigger.apply(this, arguments);
72 window.ListApp = Backbone.View.extend({
76 this.trigger.apply(this, arguments);
80 console.log("listApp.render");
81 console.log(this.collection);
82 $(this.el).html(ich.listApp({}));
83 var list = new ListView({
84 collection: this.collection,
85 el: this.$('#slivers')
88 list.bind('all', this.rethrow, this);
93 window.Router = Backbone.Router.extend({
99 navigate_to: function(model){
100 var path = (model && model.get('id') + '/') || '';
101 console.log("Router.navigate_to");
102 this.navigate(path, true);
105 detail: function(){ console.log("Router.detail"); },
107 list: function(){ console.log("Router.list"); }
111 window.app = window.app || {};
112 app.router = new Router();
113 app.slivers = xos.slivers; //new XOSLib.slivers();
114 app.list = new ListApp({
116 collection: app.slivers
118 app.detail = new DetailApp({
121 app.router.bind('route:list', function(){
122 app.slivers.maybeFetch({
123 success: _.bind(app.list.render, app.list)
126 app.router.bind('route:detail', function(id){
127 app.slivers.getOrFetch(app.slivers.urlRoot + id + '/', {
128 success: function(model){
129 app.detail.model = model;
135 app.slivers.maybeFetch({
136 success: _.bind(app.list.render, app.list)
139 app.list.bind('navigate', app.router.navigate_to, app.router);
140 app.detail.bind('home', app.router.navigate_to, app.router);
141 Backbone.history.start({