Skip to content

Commit f76d91a

Browse files
committedOct 19, 2015
Added a submit post page and linked to it in the header.
chapter7-1
1 parent 22c0d6d commit f76d91a

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed
 

‎client/templates/includes/header.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<a class="navbar-brand" href="{{pathFor 'postsList'}}">Microscope</a>
1111
</div>
1212
<div class="collapse navbar-collapse" id="navigation">
13+
<ul class="nav navbar-nav">
14+
<li><a href="{{pathFor 'postSubmit'}}">Submit Post</a></li>
15+
</ul>
1316
<ul class="nav navbar-nav navbar-right">
1417
{{> loginButtons}}
1518
</ul>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<template name="postSubmit">
2+
<form class="main form page">
3+
<div class="form-group">
4+
<label class="control-label" for="url">URL</label>
5+
<div class="controls">
6+
<input name="url" id="url" type="text" value="" placeholder="Your URL" class="form-control"/>
7+
</div>
8+
</div>
9+
<div class="form-group">
10+
<label class="control-label" for="title">Title</label>
11+
<div class="controls">
12+
<input name="title" id="title" type="text" value="" placeholder="Name your post" class="form-control"/>
13+
</div>
14+
</div>
15+
<input type="submit" value="Submit" class="btn btn-primary"/>
16+
</form>
17+
</template>

‎client/templates/posts/post_submit.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Template.postSubmit.events({
2+
'submit form': function(e) {
3+
e.preventDefault();
4+
5+
var post = {
6+
url: $(e.target).find('[name=url]').val(),
7+
title: $(e.target).find('[name=title]').val()
8+
};
9+
10+
post._id = Posts.insert(post);
11+
Router.go('postPage', post);
12+
}
13+
});

‎lib/router.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ Router.route('/posts/:_id', {
1212
data: function() { return Posts.findOne(this.params._id); }
1313
});
1414

15+
Router.route('/submit', {name: 'postSubmit'});
16+
1517
Router.onBeforeAction('dataNotFound', {only: 'postPage'});

0 commit comments

Comments
 (0)
Please sign in to comment.