converting post edit page

This commit is contained in:
Sacha Greif 2013-10-06 09:17:37 +09:00
parent 95d8727964
commit d8070e51fa
6 changed files with 35 additions and 22 deletions

View file

@ -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);
}
});
});

View file

@ -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');

View file

@ -1,6 +1,6 @@
<template name="post_edit">
<div class="grid submit">
{{#constant}}{{#with post}}
{{#constant}}
<form class="grid-block form-horizontal">
<div class="control-group">
<label class="control-label post-form-headline">Created</label>
@ -95,6 +95,6 @@
<input type="submit" value="Submit" />
</div>
</form>
{{/with}}{{/constant}}
{{/constant}}
</div>
</template>

View file

@ -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");
}
});
}

View file

@ -38,9 +38,9 @@
<a href="{{categoryLink}}" class="post-category category-{{slug}}">{{name}}</a>
{{/each}}
</h3>
<p class="post-meta"><span class="points">{{votes}} <span class="unit">{{pointsUnitDisplayText}} </span></span>by <a class="post-author" href="/users/{{userId}}">{{authorName}}</a> <span class="post-time">{{ago}}</span><span class="comments">, <a class="go-to-comments" href="/posts/{{_id}}">{{comments}} {{commentsDisplayText}}</a></span>
<p class="post-meta"><span class="points">{{votes}} <span class="unit">{{pointsUnitDisplayText}} </span></span>by <a class="post-author" href="/users/{{userId}}">{{authorName}}</a> <span class="post-time">{{ago}}</span><span class="comments">, <a class="go-to-comments" href="{{post_pagePath this}}">{{comments}} {{commentsDisplayText}}</a></span>
{{#if can_edit}}
| <a href="/posts/{{_id}}/edit" class="edit-link goto-edit">Edit</a>
| <a href="{{post_editPath this}}" class="edit-link goto-edit">Edit</a>
{{/if}}
{{#if currentUser.isAdmin}}
| status: {{status}}</span>, votes: {{votes}}, baseScore: {{baseScore}}, score: {{short_score}}, clicks: {{clicks}}

View file

@ -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;
}