forked from EndangeredMassa/cwc2012-backbone-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
source.js
97 lines (76 loc) · 1.96 KB
/
source.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
$(function(){
// use a hard-coded id so that it always fetches
// the same value from localstorage
window.user = new UserModel({id: 1});
window.user.fetch();
var router = new Router;
// we always want to pass true, so this wraps
// that extra work
window.navigate = function(path){
router.navigate(path, true);
};
Backbone.history.start();
});
var Router = Backbone.Router.extend({
routes: {
'': 'index',
'timeline': 'timeline',
'signup': 'signup'
},
index: function(){
if(window.user.get('name') == null) {
window.navigate('/signup');
} else {
window.navigate('/timeline');
}
},
signup: function(){
var view = new SignupView;
view.render();
$('#container').children().remove();
$('#container').append(view.el);
},
timeline: function(){
if(window.user.get('name') == null) {
window.navigate('/signup');
return;
}
$('#container').html('<h1>Hello ' + window.user.get('name') + '!</h1>');
}
});
var SignupView = Backbone.View.extend({
template: '<form class="form-inline"><input type="text" placeholder="user name" /><button class="btn btn-primary">Sign In</button></form>',
events: {
'click button': 'submit'
},
render: function(){
this.$el.html(this.template);
},
submit: function(){
var name = this.$('input').val();
window.user.set('name', name);
window.user.save();
window.navigate('/timeline');
}
});
var UserModel = Backbone.Model.extend({
localStorage: new Store('User')
});
var CreateStatusView = Backbone.View.extend({
});
var PostModel = Backbone.Model.extend({
});
var PostCollection = Backbone.Collection.extend({
});
var PostView = Backbone.View.extend({
});
var PostCollectionView = Backbone.View.extend({
});
var CreateCommentView = Backbone.View.extend({
});
var CommentCollection = Backbone.Collection.extend({
});
var CommentView = Backbone.View.extend({
});
var CommentCollectionView = Backbone.View.extend({
});