2015-05-09 13:26:31 +09:00
|
|
|
|
/**
|
|
|
|
|
* The Posts.controllers namespace
|
|
|
|
|
* @namespace Posts.controllers
|
|
|
|
|
*/
|
2015-04-22 08:13:43 +09:00
|
|
|
|
Posts.controllers = {};
|
|
|
|
|
|
2015-05-09 13:26:31 +09:00
|
|
|
|
/**
|
|
|
|
|
* Controller for all posts lists
|
|
|
|
|
*/
|
2015-04-22 08:13:43 +09:00
|
|
|
|
Posts.controllers.list = RouteController.extend({
|
2015-01-18 23:55:39 -08:00
|
|
|
|
|
2015-05-02 13:44:41 +09:00
|
|
|
|
template: "posts_list_controller",
|
|
|
|
|
|
2015-03-22 09:42:58 +09:00
|
|
|
|
onBeforeAction: function () {
|
2015-03-25 12:30:55 +09:00
|
|
|
|
var showViewsNav = (typeof this.showViewsNav === 'undefined') ? true : this.showViewsNav;
|
|
|
|
|
|
|
|
|
|
if (showViewsNav) {
|
2015-05-18 11:39:12 +09:00
|
|
|
|
this.render('posts_list_top', {to: 'postsListTop'});
|
2015-03-25 12:30:55 +09:00
|
|
|
|
}
|
2015-03-22 09:42:58 +09:00
|
|
|
|
this.next();
|
|
|
|
|
},
|
|
|
|
|
|
2015-04-29 14:38:14 +09:00
|
|
|
|
data: function () {
|
|
|
|
|
|
|
|
|
|
var terms = {
|
2014-11-17 14:45:23 +09:00
|
|
|
|
view: this.view,
|
2015-05-06 17:38:19 +09:00
|
|
|
|
limit: this.params.limit || Settings.get('postsPerPage', 10)
|
2014-11-17 14:45:23 +09:00
|
|
|
|
};
|
|
|
|
|
|
2015-05-02 13:44:41 +09:00
|
|
|
|
// console.log('----------------- router running');
|
2015-05-02 09:53:40 +09:00
|
|
|
|
|
2015-04-29 14:38:14 +09:00
|
|
|
|
// note: the post list controller template will handle all subscriptions, so we just need to pass in the terms
|
2014-11-17 14:45:23 +09:00
|
|
|
|
return {
|
2015-04-29 14:38:14 +09:00
|
|
|
|
terms: terms
|
2015-05-01 18:22:00 +02:00
|
|
|
|
};
|
2014-11-17 14:45:23 +09:00
|
|
|
|
},
|
2014-12-11 12:38:53 +09:00
|
|
|
|
|
|
|
|
|
getTitle: function () {
|
2015-05-02 13:44:41 +09:00
|
|
|
|
return i18n.t(this.view);
|
2014-12-11 12:38:53 +09:00
|
|
|
|
},
|
|
|
|
|
|
2014-12-15 09:46:51 +09:00
|
|
|
|
getDescription: function () {
|
2015-05-01 18:22:00 +02:00
|
|
|
|
if (Router.current().route.getName() === 'posts_default') { // return site description on root path
|
2015-03-28 18:30:26 +09:00
|
|
|
|
return Settings.get('description');
|
2014-12-17 09:49:56 +09:00
|
|
|
|
} else {
|
2015-05-18 11:11:14 +09:00
|
|
|
|
return i18n.t(_.findWhere(Telescope.menuItems.get("viewsMenu"), {label: this.view}).description);
|
2014-12-17 09:49:56 +09:00
|
|
|
|
}
|
2014-12-15 09:46:51 +09:00
|
|
|
|
},
|
|
|
|
|
|
2014-11-27 17:25:01 +05:30
|
|
|
|
fastRender: true
|
2014-11-17 14:45:23 +09:00
|
|
|
|
});
|
|
|
|
|
|
2015-02-12 18:57:37 +09:00
|
|
|
|
var getDefaultViewController = function () {
|
2015-03-28 18:30:26 +09:00
|
|
|
|
var defaultView = Settings.get('defaultView', 'top');
|
2015-05-19 18:29:54 +09:00
|
|
|
|
// if view we got from settings is available in Posts.views object, use it
|
|
|
|
|
if (!!Posts.controllers[defaultView]) {
|
|
|
|
|
return Posts.controllers[defaultView];
|
|
|
|
|
} else {
|
|
|
|
|
return Posts.controllers.top;
|
|
|
|
|
}
|
2015-02-12 18:57:37 +09:00
|
|
|
|
};
|
|
|
|
|
|
2015-02-11 19:15:29 +09:00
|
|
|
|
// wrap in startup block to make sure Settings collection is defined
|
|
|
|
|
Meteor.startup(function () {
|
2015-04-22 08:13:43 +09:00
|
|
|
|
Posts.controllers.default = getDefaultViewController().extend({
|
2015-02-11 19:15:29 +09:00
|
|
|
|
getTitle: function () {
|
2015-03-28 18:30:26 +09:00
|
|
|
|
var title = Settings.get('title', 'Telescope');
|
|
|
|
|
var tagline = Settings.get('tagline');
|
2015-02-11 19:15:29 +09:00
|
|
|
|
var fullTitle = !!tagline ? title + ' – ' + tagline : title ;
|
|
|
|
|
return fullTitle;
|
2015-02-12 18:57:37 +09:00
|
|
|
|
}
|
2015-02-11 19:15:29 +09:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2015-05-09 13:26:31 +09:00
|
|
|
|
/**
|
|
|
|
|
* Controller for top view
|
|
|
|
|
*/
|
2015-04-22 08:13:43 +09:00
|
|
|
|
Posts.controllers.top = Posts.controllers.list.extend({
|
2015-05-12 14:30:10 -07:00
|
|
|
|
view: 'top'
|
2014-11-17 14:45:23 +09:00
|
|
|
|
});
|
|
|
|
|
|
2015-05-09 13:26:31 +09:00
|
|
|
|
/**
|
|
|
|
|
* Controller for new view
|
|
|
|
|
*/
|
2015-04-22 08:13:43 +09:00
|
|
|
|
Posts.controllers.new = Posts.controllers.list.extend({
|
2015-05-12 14:30:10 -07:00
|
|
|
|
view: 'new'
|
2014-11-17 14:45:23 +09:00
|
|
|
|
});
|
|
|
|
|
|
2015-05-09 13:26:31 +09:00
|
|
|
|
/**
|
|
|
|
|
* Controller for best view
|
|
|
|
|
*/
|
2015-04-22 08:13:43 +09:00
|
|
|
|
Posts.controllers.best = Posts.controllers.list.extend({
|
2015-05-12 14:30:10 -07:00
|
|
|
|
view: 'best'
|
2014-11-17 14:45:23 +09:00
|
|
|
|
});
|
|
|
|
|
|
2015-05-09 13:26:31 +09:00
|
|
|
|
/**
|
|
|
|
|
* Controller for pending view
|
|
|
|
|
*/
|
|
|
|
|
Posts.controllers.pending = Posts.controllers.list.extend({
|
2015-05-12 14:30:10 -07:00
|
|
|
|
view: 'pending'
|
2014-11-17 14:45:23 +09:00
|
|
|
|
});
|
|
|
|
|
|
2015-05-09 13:26:31 +09:00
|
|
|
|
/**
|
|
|
|
|
* Controller for scheduled view
|
|
|
|
|
*/
|
2015-04-22 08:13:43 +09:00
|
|
|
|
Posts.controllers.scheduled = Posts.controllers.list.extend({
|
2015-05-12 14:30:10 -07:00
|
|
|
|
view: 'scheduled'
|
2014-12-08 16:39:10 +09:00
|
|
|
|
});
|
|
|
|
|
|
2015-05-09 13:26:31 +09:00
|
|
|
|
/**
|
|
|
|
|
* Controller for single post page
|
|
|
|
|
*/
|
2015-04-22 08:13:43 +09:00
|
|
|
|
Posts.controllers.page = RouteController.extend({
|
2015-01-18 23:55:39 -08:00
|
|
|
|
|
2015-04-13 16:29:33 +09:00
|
|
|
|
template: 'post_page',
|
2014-11-17 14:45:23 +09:00
|
|
|
|
|
2015-06-25 11:26:56 +09:00
|
|
|
|
waitOn: function () {
|
2014-11-17 14:45:23 +09:00
|
|
|
|
this.postSubscription = coreSubscriptions.subscribe('singlePost', this.params._id);
|
|
|
|
|
this.postUsersSubscription = coreSubscriptions.subscribe('postUsers', this.params._id);
|
2015-05-08 09:33:27 +09:00
|
|
|
|
this.commentSubscription = coreSubscriptions.subscribe('commentsList', {view: 'postComments', postId: this.params._id});
|
2014-11-17 14:45:23 +09:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
post: function() {
|
|
|
|
|
return Posts.findOne(this.params._id);
|
|
|
|
|
},
|
|
|
|
|
|
2014-12-11 12:38:53 +09:00
|
|
|
|
getTitle: function () {
|
2014-12-18 15:09:50 +09:00
|
|
|
|
if (!!this.post())
|
2015-04-01 11:00:31 +09:00
|
|
|
|
return this.post().title;
|
2014-12-11 12:38:53 +09:00
|
|
|
|
},
|
|
|
|
|
|
2015-06-18 13:04:38 +09:00
|
|
|
|
onBeforeAction: function () {
|
2015-06-25 11:26:56 +09:00
|
|
|
|
if (!this.post()) {
|
2014-11-17 14:45:23 +09:00
|
|
|
|
if (this.postSubscription.ready()) {
|
2015-04-13 16:29:33 +09:00
|
|
|
|
this.render('not_found');
|
2014-11-17 14:45:23 +09:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.next();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onRun: function() {
|
|
|
|
|
var sessionId = Meteor.default_connection && Meteor.default_connection._lastSessionId ? Meteor.default_connection._lastSessionId : null;
|
|
|
|
|
Meteor.call('increasePostViews', this.params._id, sessionId);
|
2015-01-10 12:46:44 +09:00
|
|
|
|
this.next();
|
2014-11-17 14:45:23 +09:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
data: function() {
|
|
|
|
|
return this.post();
|
2014-11-27 17:25:01 +05:30
|
|
|
|
},
|
2015-06-18 13:04:38 +09:00
|
|
|
|
|
|
|
|
|
onAfterAction: function () {
|
|
|
|
|
var post = this.post();
|
2015-06-19 16:39:13 +09:00
|
|
|
|
if (post) {
|
|
|
|
|
if (post.slug !== this.params.slug) {
|
|
|
|
|
window.history.replaceState({}, "", post.getPageUrl());
|
|
|
|
|
}
|
|
|
|
|
$('link[rel="canonical"]').attr("href", post.getPageUrl(true));
|
2015-06-18 13:04:38 +09:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2014-11-27 17:25:01 +05:30
|
|
|
|
fastRender: true
|
2014-11-17 14:45:23 +09:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Meteor.startup(function () {
|
|
|
|
|
|
|
|
|
|
Router.route('/', {
|
|
|
|
|
name: 'posts_default',
|
2015-04-22 08:13:43 +09:00
|
|
|
|
controller: Posts.controllers.default
|
2014-11-17 14:45:23 +09:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Router.route('/top/:limit?', {
|
|
|
|
|
name: 'posts_top',
|
2015-04-22 08:13:43 +09:00
|
|
|
|
controller: Posts.controllers.top
|
2014-11-17 14:45:23 +09:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// New
|
|
|
|
|
|
|
|
|
|
Router.route('/new/:limit?', {
|
|
|
|
|
name: 'posts_new',
|
2015-04-22 08:13:43 +09:00
|
|
|
|
controller: Posts.controllers.new
|
2014-11-17 14:45:23 +09:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Best
|
|
|
|
|
|
|
|
|
|
Router.route('/best/:limit?', {
|
|
|
|
|
name: 'posts_best',
|
2015-04-22 08:13:43 +09:00
|
|
|
|
controller: Posts.controllers.best
|
2014-11-17 14:45:23 +09:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Pending
|
|
|
|
|
|
|
|
|
|
Router.route('/pending/:limit?', {
|
|
|
|
|
name: 'posts_pending',
|
2015-04-22 08:13:43 +09:00
|
|
|
|
controller: Posts.controllers.pending
|
2014-11-17 14:45:23 +09:00
|
|
|
|
});
|
|
|
|
|
|
2014-12-08 16:39:10 +09:00
|
|
|
|
// Scheduled
|
|
|
|
|
|
|
|
|
|
Router.route('/scheduled/:limit?', {
|
|
|
|
|
name: 'posts_scheduled',
|
2015-04-22 08:13:43 +09:00
|
|
|
|
controller: Posts.controllers.scheduled
|
2014-12-08 16:39:10 +09:00
|
|
|
|
});
|
|
|
|
|
|
2014-11-17 14:45:23 +09:00
|
|
|
|
// Post Edit
|
|
|
|
|
|
|
|
|
|
Router.route('/posts/:_id/edit', {
|
|
|
|
|
name: 'post_edit',
|
2015-04-13 16:29:33 +09:00
|
|
|
|
template: 'post_edit',
|
2014-11-17 14:45:23 +09:00
|
|
|
|
waitOn: function () {
|
|
|
|
|
return [
|
|
|
|
|
coreSubscriptions.subscribe('singlePost', this.params._id),
|
|
|
|
|
coreSubscriptions.subscribe('allUsersAdmin')
|
|
|
|
|
];
|
|
|
|
|
},
|
|
|
|
|
data: function() {
|
|
|
|
|
return {
|
|
|
|
|
postId: this.params._id,
|
|
|
|
|
post: Posts.findOne(this.params._id)
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
fastRender: true
|
|
|
|
|
});
|
|
|
|
|
|
2015-06-25 12:03:10 +09:00
|
|
|
|
// Post Page
|
|
|
|
|
|
|
|
|
|
Router.route('/posts/:_id/:slug?', {
|
|
|
|
|
name: 'post_page',
|
|
|
|
|
controller: Posts.controllers.page
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Router.route('/posts/:_id/comment/:commentId', {
|
|
|
|
|
name: 'post_page_comment',
|
|
|
|
|
controller: Posts.controllers.page,
|
|
|
|
|
onAfterAction: function () {
|
|
|
|
|
// TODO: scroll to comment position
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2014-11-17 14:45:23 +09:00
|
|
|
|
// Post Submit
|
|
|
|
|
|
|
|
|
|
Router.route('/submit', {
|
|
|
|
|
name: 'post_submit',
|
2015-04-13 16:29:33 +09:00
|
|
|
|
template: 'post_submit',
|
2014-11-18 11:13:16 +09:00
|
|
|
|
waitOn: function () {
|
|
|
|
|
return coreSubscriptions.subscribe('allUsersAdmin');
|
|
|
|
|
}
|
2014-11-17 14:45:23 +09:00
|
|
|
|
});
|
|
|
|
|
|
2015-03-28 18:30:26 +09:00
|
|
|
|
});
|