Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chapter8-1
- Loading branch information
Showing
5 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<template name="postEdit"> | ||
<form class="main form page"> | ||
<div class="form-group"> | ||
<label class="control-label" for="url">URL</label> | ||
<div class="controls"> | ||
<input name="url" id="url" type="text" value="{{url}}" placeholder="Your URL" class="form-control"/> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<label class="control-label" for="title">Title</label> | ||
<div class="controls"> | ||
<input name="title" id="title" type="text" value="{{title}}" placeholder="Name your post" class="form-control"/> | ||
</div> | ||
</div> | ||
<input type="submit" value="Submit" class="btn btn-primary submit"/> | ||
<hr/> | ||
<a class="btn btn-danger delete" href="#">Delete post</a> | ||
</form> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Template.postEdit.events({ | ||
'submit form': function(e) { | ||
e.preventDefault(); | ||
|
||
var currentPostId = this._id; | ||
|
||
var postProperties = { | ||
url: $(e.target).find('[name=url]').val(), | ||
title: $(e.target).find('[name=title]').val() | ||
} | ||
|
||
Posts.update(currentPostId, {$set: postProperties}, function(error) { | ||
if (error) { | ||
// display the error to the user | ||
alert(error.reason); | ||
} else { | ||
Router.go('postPage', {_id: currentPostId}); | ||
} | ||
}); | ||
}, | ||
|
||
'click .delete': function(e) { | ||
e.preventDefault(); | ||
|
||
if (confirm("Delete this post?")) { | ||
var currentPostId = this._id; | ||
Posts.remove(currentPostId); | ||
Router.go('postsList'); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85f91b0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
‘Delete’ works but “Modification of the userId and URL" doesn't work. that is, posts can be deleted but can't be updated.
85f91b0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More specifically,
var postProperties = { url: $(e.target).find('[name=url]').val(), title: $(e.target).find('[name=title]').val() }
seems doesn't work
85f91b0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I realized I made a mistake, something wrong with my post_edit.html. So, the codes are good, sorry again