mirror of
https://github.com/vale981/Vulcan
synced 2025-03-09 20:16:39 -04:00

This commit touch a lot of lines of code with the goal to be more rigorous about JavaScript code conventions defined in the `.jshintrc`. Some modification: * Add a list of used global symbols in the corresponding section of `.jshintrc` * Use local variables instead of global in a lot of places where the keyword `var` was mistakenly forgotten * Add missing semi-colons after instructions * Add new lines at the end of files * Remove trailing whitespaces * Use newer name of some Meteor APIs, eg `addFiles` instead of `add_files` * Add missing `break` statements in `switch` blocks * Use `===` instead of `==` and `!==` instead of `!=` * Remove unused variables This commit should also fix a few bugs due to this lack of rigor. One example of that was the test `typeof navElements === "array"` that was never true because in JavaScript, `typeof [] === "object"`, we replaced this test by the `_.isArray` method provided by underscore. It might also fix some potential collision related to global variables. There is still plenty of work until Telescope code base passes jsHint validation, but at least this commit is a step in the right direction.
221 lines
4.9 KiB
JavaScript
221 lines
4.9 KiB
JavaScript
Posts.controllers = {};
|
||
|
||
// Controller for all posts lists
|
||
|
||
Posts.controllers.list = RouteController.extend({
|
||
|
||
template: 'postsListController',
|
||
|
||
onBeforeAction: function () {
|
||
var showViewsNav = (typeof this.showViewsNav === 'undefined') ? true : this.showViewsNav;
|
||
|
||
if (showViewsNav) {
|
||
this.render('postListTop', {to: 'postListTop'});
|
||
}
|
||
this.next();
|
||
},
|
||
|
||
data: function () {
|
||
|
||
var terms = {
|
||
view: this.view,
|
||
limit: this.params.limit || Settings.get('postsPerPage', 10),
|
||
category: this.params.slug
|
||
};
|
||
|
||
if(Meteor.isClient) {
|
||
terms.query = Session.get("searchQuery");
|
||
}
|
||
|
||
console.log('-----------------\nrouter running');
|
||
console.log(terms);
|
||
// note: the post list controller template will handle all subscriptions, so we just need to pass in the terms
|
||
return {
|
||
terms: terms
|
||
};
|
||
},
|
||
|
||
getTitle: function () {
|
||
return i18n.t("this.view");
|
||
},
|
||
|
||
getDescription: function () {
|
||
if (Router.current().route.getName() === 'posts_default') { // return site description on root path
|
||
return Settings.get('description');
|
||
} else {
|
||
return i18n.t(_.findWhere(Telescope.menus.get("viewsMenu"), {label: this.view}).description);
|
||
}
|
||
},
|
||
|
||
fastRender: true
|
||
});
|
||
|
||
var getDefaultViewController = function () {
|
||
var defaultView = Settings.get('defaultView', 'top');
|
||
return Posts.controllers[defaultView];
|
||
};
|
||
|
||
// wrap in startup block to make sure Settings collection is defined
|
||
Meteor.startup(function () {
|
||
Posts.controllers.default = getDefaultViewController().extend({
|
||
getTitle: function () {
|
||
var title = Settings.get('title', 'Telescope');
|
||
var tagline = Settings.get('tagline');
|
||
var fullTitle = !!tagline ? title + ' – ' + tagline : title ;
|
||
return fullTitle;
|
||
}
|
||
});
|
||
|
||
});
|
||
|
||
Posts.controllers.top = Posts.controllers.list.extend({
|
||
view: 'top',
|
||
});
|
||
|
||
Posts.controllers.new = Posts.controllers.list.extend({
|
||
view: 'new'
|
||
});
|
||
|
||
Posts.controllers.best = Posts.controllers.list.extend({
|
||
view: 'best'
|
||
});
|
||
|
||
Posts.controllers.view = Posts.controllers.list.extend({
|
||
view: 'pending'
|
||
});
|
||
|
||
Posts.controllers.scheduled = Posts.controllers.list.extend({
|
||
view: 'scheduled'
|
||
});
|
||
|
||
// Controller for post pages
|
||
|
||
Posts.controllers.page = RouteController.extend({
|
||
|
||
template: 'post_page',
|
||
|
||
waitOn: function() {
|
||
this.postSubscription = coreSubscriptions.subscribe('singlePost', this.params._id);
|
||
this.postUsersSubscription = coreSubscriptions.subscribe('postUsers', this.params._id);
|
||
this.commentSubscription = coreSubscriptions.subscribe('postComments', this.params._id);
|
||
},
|
||
|
||
post: function() {
|
||
return Posts.findOne(this.params._id);
|
||
},
|
||
|
||
getTitle: function () {
|
||
if (!!this.post())
|
||
return this.post().title;
|
||
},
|
||
|
||
onBeforeAction: function() {
|
||
if (! this.post()) {
|
||
if (this.postSubscription.ready()) {
|
||
this.render('not_found');
|
||
} else {
|
||
this.render('loading');
|
||
}
|
||
} 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);
|
||
this.next();
|
||
},
|
||
|
||
data: function() {
|
||
return this.post();
|
||
},
|
||
fastRender: true
|
||
});
|
||
|
||
Meteor.startup(function () {
|
||
|
||
Router.route('/', {
|
||
name: 'posts_default',
|
||
controller: Posts.controllers.default
|
||
});
|
||
|
||
Router.route('/top/:limit?', {
|
||
name: 'posts_top',
|
||
controller: Posts.controllers.top
|
||
});
|
||
|
||
// New
|
||
|
||
Router.route('/new/:limit?', {
|
||
name: 'posts_new',
|
||
controller: Posts.controllers.new
|
||
});
|
||
|
||
// Best
|
||
|
||
Router.route('/best/:limit?', {
|
||
name: 'posts_best',
|
||
controller: Posts.controllers.best
|
||
});
|
||
|
||
// Pending
|
||
|
||
Router.route('/pending/:limit?', {
|
||
name: 'posts_pending',
|
||
controller: Posts.controllers.pending
|
||
});
|
||
|
||
// Scheduled
|
||
|
||
Router.route('/scheduled/:limit?', {
|
||
name: 'posts_scheduled',
|
||
controller: Posts.controllers.scheduled
|
||
});
|
||
|
||
// Post Page
|
||
|
||
Router.route('/posts/:_id', {
|
||
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
|
||
}
|
||
});
|
||
|
||
// Post Edit
|
||
|
||
Router.route('/posts/:_id/edit', {
|
||
name: 'post_edit',
|
||
template: 'post_edit',
|
||
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
|
||
});
|
||
|
||
// Post Submit
|
||
|
||
Router.route('/submit', {
|
||
name: 'post_submit',
|
||
template: 'post_submit',
|
||
waitOn: function () {
|
||
return coreSubscriptions.subscribe('allUsersAdmin');
|
||
}
|
||
});
|
||
|
||
});
|