Skip to content

Commit 8da36bf

Browse files
committed
Typesetting.
1 parent be4a07f commit 8da36bf

File tree

11 files changed

+63
-69
lines changed

11 files changed

+63
-69
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Node-Backbone-Require Example Blog
2-
A RESTful example blog built with Node.js, Backbone.js, Require.js, and Mongoose.
2+
A RESTful example blog built with Node.js, Backbone.js, Require.js, and MongoDB.
33

44
## Usage
55
```sh

public/javascripts/router.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ define('router', [
1313
var router;
1414

1515
router = backbone.Router.extend({
16-
routes : {
16+
routes: {
1717
'' : 'home',
1818
'home' : 'home',
1919
'post/list' : 'showPostList',
@@ -49,9 +49,7 @@ define('router', [
4949
view = new PostListView({ collection: collection });
5050
that.appView.show(view);
5151
},
52-
error: function(collection, res) {
53-
// TODO
54-
}
52+
error: that.alert
5553
});
5654

5755
},
@@ -69,14 +67,12 @@ define('router', [
6967
view = new PostShowView({ model: model });
7068
that.appView.show(view);
7169

72-
view.model.on('delete-success', function() {
70+
view.model.on('success', function() {
7371
delete view;
7472
that.navigate('#/post/list', { trigger: true });
7573
});
7674
},
77-
error: function(model, res) {
78-
// TODO
79-
}
75+
error: that.alert
8076
});
8177
},
8278
addPost: function() {
@@ -91,7 +87,7 @@ define('router', [
9187
delete view;
9288
that.navigate('#/post/list', { trigger: true });
9389
});
94-
view.model.on('add-success', function(id) {
90+
view.model.on('success', function(id) {
9591
delete view;
9692
that.navigate('#/post/' + id, { trigger: true });
9793
});
@@ -114,15 +110,16 @@ define('router', [
114110
delete view;
115111
that.navigate('#/post/' + id, { trigger: true });
116112
});
117-
view.model.on('save-success', function() {
113+
view.model.on('success', function() {
118114
delete view;
119115
that.navigate('#/post/' + id, { trigger: true });
120116
});
121117
},
122-
error: function(model, res) {
123-
// TODO
124-
}
118+
error: that.alert
125119
});
120+
},
121+
alert: function() {
122+
alert('Error occurred');
126123
}
127124
});
128125

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
<h1>Node, Backbone, Require Example Blog</h1>
2-
<p>
3-
A RESTful example blog built with Node.js, Backbone.js, Require.js, and Mongoose.
4-
5-
</p>
1+
<h1>Node-Backbone-Require Example Blog</h1>
2+
<p>A RESTful example blog built with Node.js, Backbone.js, Require.js, and MongoDB.</p>
3+
<a target="_blank" href="https://github.com/trantorLiu/Node-Backbone-Require-Example-Blog">Fork me on GigtHub</a>
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
<label for="post-add-title">Title</label>
2-
<input type="text" name="title" id="post-add-title" />
1+
<label for="title">Title</label>
32
<br />
4-
<label for="post-add-author">Author</label>
5-
<input type="text" name="author" id="post-add-author" />
3+
<input type="text" name="title" id="title" size="36" />
64
<br />
7-
<label for="post-add-body">Body</label>
8-
<textarea name="body" id="post-add-body"></textarea>
5+
<label for="author">Author</label>
96
<br />
10-
<button id="post-add-back">Cancel</button>
11-
<input type="submit" id="post-add-submit" value="Save" />
7+
<input type="text" name="author" id="author" size="36" />
8+
<br />
9+
<label for="body">Body</label>
10+
<br />
11+
<textarea name="body" id="body" rows="10" cols="36"></textarea>
12+
<br />
13+
<br />
14+
<input type="submit" id="submit" value="Save" />
15+
<a href="#/post/list" id="cancel">Cancel</button>
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
<label for="post-edit-title">Title</label>
2-
<input type="text" name="title" id="post-edit-title" value="<%= post.title %>"/>
1+
<label for="title">Title</label>
32
<br />
4-
<label for="post-edit-author">Author</label>
5-
<input type="text" name="author" id="post-edit-author" value="<%= post.author %>"/>
3+
<input type="text" name="title" id="title" value="<%= post.title %>" size="36" />
64
<br />
7-
<label for="post-edit-body">Body</label>
8-
<textarea name="body" id="post-edit-body"><%= post.body %></textarea>
5+
<label for="author">Author</label>
96
<br />
10-
<button id="post-edit-back">Cancel</button>
11-
<button id="post-edit-save">Save</button/>
7+
<input type="text" name="author" id="author" value="<%= post.author %>" size="36"/>
8+
<br />
9+
<label for="body">Body</label>
10+
<br />
11+
<textarea name="body" id="body" rows="10" cols="36"><%= post.body %></textarea>
12+
<br />
13+
<br />
14+
<button id="save">Save</button/>
15+
<a href="#/post/<%= post._id %>" id="cancel">Cancel</button>
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<% _.each(posts, function (post) { %>
22
<div class="post">
3-
<h4 class="post-title"><a href="#/post/<%= post._id %>"><%= post.title %></a></h4>
4-
<p class="post-author"><%= post.author %></p>
5-
<p class="post-body"><%= post.body %></p>
3+
<h4 class="title"><a href="#/post/<%= post._id %>"><%= post.title %></a></h4>
4+
<p class="author"><%= post.author %></p>
5+
<p class="body"><%= post.body %></p>
66
</div>
77
<% }); %>
8+
<% if (_.isEmpty(posts)) { %>
9+
<p>Empty</p>
10+
<% } %>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h3 class="post-show-title"><%= post.title %></h3>
2-
<p class="post-show-author"><%= post.author %></p>
3-
<p class="post-show-body"><%= post.body %></p>
4-
<a href="#/post/<%= post._id %>/edit">Edit</a>&nbsp;|&nbsp;<span class="link post-show-delete">Delete</span>
1+
<h3 class="title"><%= post.title %></h3>
2+
<p class="author"><%= post.author %></p>
3+
<p class="body"><%= post.body %></p>
4+
<a href="#/post/<%= post._id %>/edit">Edit</a>&nbsp;|&nbsp;<span class="link delete">Delete</span>

public/javascripts/views/post/add.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,35 @@ define('PostAddView', [
1616
return this;
1717
},
1818
events: {
19-
'click #post-add-submit': 'addPost',
20-
'click #post-add-back': 'back'
19+
'click #submit': 'submit'
2120
},
22-
addPost: function(e) {
21+
submit: function(e) {
2322
var title, author, body, that;
2423

2524
e.preventDefault();
2625

2726
that = this;
28-
title = $.trim($('#post-add-title').val());
29-
author = $.trim($('#post-add-author').val());
30-
body = $.trim($('#post-add-body').val());
27+
title = $.trim(this.$el.find('#title').val());
28+
author = $.trim(this.$el.find('#author').val());
29+
body = $.trim(this.$el.find('#body').val());
3130

3231
this.model.save({
3332
title : title,
3433
author : author,
3534
body : body
3635
}, {
37-
silent : false,
38-
sync : true,
39-
success : function(model, res) {
36+
success: function(model, res) {
4037
if (res && res.error) {
4138
// TODO
4239
} else {
43-
model.trigger('add-success', model.get('_id'));
40+
model.trigger('success', model.id);
4441
}
4542
},
4643
error: function(model, res) {
4744
// TODO
4845
}
4946
});
5047
},
51-
back: function(e) {
52-
e.preventDefault();
53-
this.trigger('back');
54-
}
5548
});
5649

5750
return PostAddView;

public/javascripts/views/post/edit.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@ define('PostEditView', [
2020
return this;
2121
},
2222
events: {
23-
'click #post-edit-save': 'savePost'
24-
, 'click #post-edit-back': 'back'
23+
'click #save': 'savePost'
2524
},
2625
savePost: function(e) {
2726
var title, author, body, that;
2827

2928
e.preventDefault();
3029

3130
that = this;
32-
title = $.trim($('#post-edit-title').val());
33-
body = $.trim($('#post-edit-body').val());
31+
title = $.trim(this.$el.find('#title').val());
32+
body = $.trim(this.$el.find('#body').val());
3433

3534
this.model.save({
3635
title : title,
@@ -43,18 +42,14 @@ define('PostEditView', [
4342
if (res && res.error) {
4443
// TODO
4544
} else {
46-
model.trigger('save-success', model.get('_id'));
45+
model.trigger('success', model.id);
4746
}
4847
},
4948
error: function(model, res) {
5049
// TODO
5150
}
5251
});
5352
},
54-
back: function(e) {
55-
e.preventDefault();
56-
this.trigger('back');
57-
}
5853
});
5954

6055
return PostEditView;

public/javascripts/views/post/list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ define('PostListView', [
88
var PostAddView;
99

1010
PostAddView = backbone.View.extend({
11-
id: 'post-add-view',
11+
id: 'post-list-view',
1212
initialize: function(options) {
1313
this.collection = options.collection;
1414
this.compiled = _.template(tpl);

public/javascripts/views/post/show.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ define('PostShowView', [
1818
return this;
1919
},
2020
events: {
21-
'click .post-show-delete': 'deletePost'
21+
'click #delete': 'delete'
2222
},
23-
deletePost: function(e) {
23+
delete: function(e) {
2424
e.preventDefault();
2525
this.model.destroy({
2626
sync: true,
2727
success: function(model) {
28-
model.trigger('delete-success');
28+
model.trigger('success');
2929
},
3030
error: function() {
3131
// TODO handle 404 and 500

0 commit comments

Comments
 (0)