3 window.SliverView = Backbone.View.extend({
5 className: 'XOSLib.sliver',
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.InputView = Backbone.View.extend({
45 'click .sliver': 'createSliver',
46 'keypress #message': 'createOnEnter'
49 createOnEnter: function(e){
50 if((e.keyCode || e.which) == 13){
57 createSliver: function(){
58 var message = this.$('#message').val();
60 this.collection.create({
63 this.$('#message').val('');
69 window.ListView = Backbone.View.extend({
70 initialize: function(){
71 _.bindAll(this, 'addOne', 'addAll');
73 this.collection.bind('add', this.addOne);
74 this.collection.bind('reset', this.addAll, this);
80 this.collection.each(this.addOne);
83 addOne: function(sliver){
84 var view = new SliverView({
87 $(this.el).prepend(view.render().el);
88 this.views.push(view);
89 view.bind('all', this.rethrow, this);
93 this.trigger.apply(this, arguments);
98 window.ListApp = Backbone.View.extend({
102 this.trigger.apply(this, arguments);
106 console.log("listApp.render");
107 $(this.el).html(ich.listApp({}));
108 var list = new ListView({
109 collection: this.collection,
110 el: this.$('#slivers')
113 list.bind('all', this.rethrow, this);
115 collection: this.collection,
122 window.Router = Backbone.Router.extend({
128 navigate_to: function(model){
129 var path = (model && model.get('id') + '/') || '';
130 console.log("Router.navigate_to");
131 this.navigate(path, true);
134 detail: function(){ console.log("Router.detail"); },
136 list: function(){ console.log("Router.list"); }
140 window.app = window.app || {};
141 app.router = new Router();
142 app.slivers = new XOSLib.slivers();
143 app.list = new ListApp({
145 collection: app.slivers
147 app.detail = new DetailApp({
150 app.router.bind('route:list', function(){
151 console.log("Router:list2");
152 app.slivers.maybeFetch({
153 success: _.bind(app.list.render, app.list)
156 app.router.bind('route:detail', function(id){
157 console.log("Router:detail2");
158 app.slivers.getOrFetch(app.slivers.urlRoot + id + '/', {
159 success: function(model){
160 app.detail.model = model;
166 app.slivers.maybeFetch({
167 success: _.bind(app.list.render, app.list)
170 app.list.bind('navigate', app.router.navigate_to, app.router);
171 app.detail.bind('home', app.router.navigate_to, app.router);
172 Backbone.history.start({