diff --git a/client/helpers/router.js b/client/helpers/router.js
index d577dc74a..d940068e1 100644
--- a/client/helpers/router.js
+++ b/client/helpers/router.js
@@ -11,6 +11,7 @@ Router.map(function() {
this.route('posts_top', {path: '/top'});
this.route('posts_new', {path: '/new'});
this.route('posts_best', {path: '/best'});
+ this.route('posts_pending', {path: '/pending'});
this.route('post_page', {
path: '/posts/:_id',
@@ -22,6 +23,15 @@ Router.map(function() {
}
});
+ this.route('post_edit', {
+ path: '/posts/:_id/edit',
+ waitOn: function() {
+ return Meteor.subscribe('singlePost', this.params._id);
+ },
+ data: function() {
+ return Posts.findOne(this.params._id);
+ }
+ });
});
diff --git a/client/views/common/layout.js b/client/views/common/layout.js
index b0638cc12..aec999820 100644
--- a/client/views/common/layout.js
+++ b/client/views/common/layout.js
@@ -1,7 +1,10 @@
Template.layout.helpers({
pageName : function(){
- // return Meteor.Router.page();
- return "pageNameHere"
+ if(Router._current){
+ var currentPath = Router._current.path;
+ var currentRoute = _.findWhere(Router.routes, {originalPath: currentPath});
+ return currentRoute.name;
+ }
},
backgroundColor: function(){
return getSetting('backgroundColor');
diff --git a/client/views/posts/post_edit.html b/client/views/posts/post_edit.html
index 526f244c5..d35c5ea19 100644
--- a/client/views/posts/post_edit.html
+++ b/client/views/posts/post_edit.html
@@ -1,6 +1,6 @@
- {{#constant}}{{#with post}}
+ {{#constant}}
- {{/with}}{{/constant}}
+ {{/constant}}
\ No newline at end of file
diff --git a/client/views/posts/post_edit.js b/client/views/posts/post_edit.js
index e24b6da42..81cc3571c 100644
--- a/client/views/posts/post_edit.js
+++ b/client/views/posts/post_edit.js
@@ -5,13 +5,13 @@
// '[name]': function(node) { return node.getAttribute('name');}
// });
+Template.post_edit.created = function(){
+ post = this.data;
+}
+
Template.post_edit.helpers({
- post: function(){
- return Posts.findOne(Session.get('selectedPostId'));
- },
created: function(){
- var post= Posts.findOne(Session.get('selectedPostId'));
- return moment(post.createdAt).format("MMMM Do, h:mm:ss a");
+ return moment(this.createdAt).format("MMMM Do, h:mm:ss a");
},
categories: function(){
var post = this;
@@ -27,8 +27,6 @@ Template.post_edit.helpers({
return this.sticky ? 'checked' : '';
},
isSelected: function(){
- // console.log('isSelected?')
- var post= Posts.findOne(Session.get('selectedPostId'));
return post && this._id == post.userId ? 'selected' : '';
},
submittedDate: function(){
@@ -58,7 +56,6 @@ Template.post_edit.helpers({
});
Template.post_edit.rendered = function(){
- var post= Posts.findOne(Session.get('selectedPostId'));
if(post && !this.editor){
this.editor= new EpicEditor(EpicEditorOptions).load();
@@ -80,8 +77,6 @@ Template.post_edit.events = {
return false;
}
- var selectedPostId=Session.get('selectedPostId');
- var post = Posts.findOne(selectedPostId);
var categories = [];
var url = $('#url').val();
var shortUrl = $('#short-url').val();
@@ -121,7 +116,7 @@ Template.post_edit.events = {
properties = _.extend(properties, adminProperties);
}
- Posts.update(selectedPostId,
+ Posts.update(post._id,
{
$set: properties
}
@@ -130,8 +125,8 @@ Template.post_edit.events = {
console.log(error);
throwError(error.reason);
}else{
- trackEvent("edit post", {'postId': selectedPostId});
- Meteor.Router.to("/posts/"+selectedPostId);
+ trackEvent("edit post", {'postId': post._id});
+ Router.go("/posts/"+post._id);
}
}
);
@@ -139,13 +134,12 @@ Template.post_edit.events = {
'click .delete-link': function(e){
e.preventDefault();
if(confirm("Are you sure?")){
- var selectedPostId=Session.get('selectedPostId');
- Meteor.call("deletePostById", selectedPostId, function(error) {
+ Meteor.call("deletePostById", post._id, function(error) {
if (error) {
console.log(error);
throwError(error.reason);
} else {
- Meteor.Router.to("/posts/deleted");
+ Router.go("/posts/deleted");
}
});
}
diff --git a/client/views/posts/post_item.html b/client/views/posts/post_item.html
index c80752563..346b41d0a 100644
--- a/client/views/posts/post_item.html
+++ b/client/views/posts/post_item.html
@@ -38,9 +38,9 @@
{{name}}
{{/each}}
-
{{votes}} {{pointsUnitDisplayText}} by {{authorName}} {{ago}}
+
{{votes}} {{pointsUnitDisplayText}} by {{authorName}} {{ago}}
{{#if can_edit}}
- | Edit
+ | Edit
{{/if}}
{{#if currentUser.isAdmin}}
| status: {{status}}, votes: {{votes}}, baseScore: {{baseScore}}, score: {{short_score}}, clicks: {{clicks}}
diff --git a/lib/helpers.js b/lib/helpers.js
index 77adefc59..63dc48c39 100644
--- a/lib/helpers.js
+++ b/lib/helpers.js
@@ -51,9 +51,15 @@ getDateRange= function(pageNumber){
// return _.filter(postCategories, function(e){return e});
// }
// ---------------------------------- URL Helper Functions ----------------------------------- //
+goTo = function(url){
+ Router.go(url);
+}
getPostUrl = function(id){
return Meteor.absoluteUrl()+'posts/'+id;
}
+getPostEditUrl = function(id){
+ return Meteor.absoluteUrl()+'posts/'+id+'/edit';
+}
getCommentUrl = function(id){
return Meteor.absoluteUrl()+'comments/'+id;
}