Vulcan/packages/telescope-base/lib/base.js

382 lines
7.5 KiB
JavaScript
Raw Normal View History

2014-09-18 07:24:42 +09:00
// ------------------------------------- Schemas -------------------------------- //
2014-07-06 14:09:55 +09:00
// array containing properties to be added to the post/settings/comments schema on startup.
addToPostSchema = [];
2014-07-06 14:09:55 +09:00
addToCommentsSchema = [];
addToSettingsSchema = [];
addToUserSchema = [];
2014-10-05 17:20:15 +09:00
SimpleSchema.extendOptions({
editable: Match.Optional(Boolean), // editable: true means the field can be edited by the document's owner
hidden: Match.Optional(Boolean) // hidden: true means the field is never shown in a form no matter what
});
// ----------------------------------- Posts Statuses ------------------------------ //
postStatuses = [
{
value: 1,
label: 'Pending'
},
{
value: 2,
label: 'Approved'
},
{
value: 3,
label: 'Rejected'
}
]
STATUS_PENDING=1;
STATUS_APPROVED=2;
STATUS_REJECTED=3;
2014-09-18 07:24:42 +09:00
// ------------------------------------- Navigation -------------------------------- //
2015-03-21 18:43:35 +09:00
// array containing nav items;
primaryNav = [
];
2014-09-18 07:24:42 +09:00
secondaryNav = [
{
template: 'userMenu',
order: 10
},
{
template:'notificationsMenu',
order: 20
},
{
template: 'submitButton',
order: 30
}
];
2014-09-18 07:24:42 +09:00
// array containing items in the views menu
viewsMenu = [
{
route: 'posts_top',
label: 'top',
description: 'most_popular_posts'
},
{
route: 'posts_new',
label: 'new',
description: 'newest_posts'
},
{
route: 'posts_best',
label: 'best',
description: 'highest_ranked_posts_ever'
},
{
route: 'posts_pending',
2015-03-22 10:55:30 +09:00
label: 'pending',
description: 'posts_awaiting_moderation',
adminOnly: true
},
{
route: 'posts_scheduled',
2015-03-22 10:55:30 +09:00
label: 'scheduled',
description: 'future_scheduled_posts',
adminOnly: true
},
];
// array containing items in the admin menu
adminMenu = [
{
route: 'settings',
label: 'Settings',
description: 'telescope_settings_panel'
},
{
2015-03-23 10:32:56 +09:00
route: 'usersDashboard',
label: 'Users',
description: 'users_dashboard'
2014-12-08 11:15:20 +09:00
}
];
userMenu = [
{
route: function () {
return Router.path('user_profile', {_idOrSlug: Meteor.user().slug});
},
label: 'profile',
description: 'view_your_profile'
},
{
route: function () {
return Router.path('user_edit', {slug: Meteor.user().slug});
},
label: 'edit_account',
description: 'edit_your_profile'
},
{
route: 'settings',
label: 'settings',
description: 'settings',
adminOnly: true
},
{
route: 'signOut',
label: 'sign_out',
description: 'sign_out'
}
]
2014-09-18 07:24:42 +09:00
// ------------------------------------- Views -------------------------------- //
// object containing post list view parameters
viewParameters = {};
// will be common to all other view unless specific properties are overwritten
viewParameters.baseParameters = {
find: {
status: STATUS_APPROVED
},
options: {
limit: 10
}
};
viewParameters.top = function (terms) {
return {
options: {sort: {sticky: -1, score: -1}}
};
}
viewParameters.new = function (terms) {
return {
options: {sort: {sticky: -1, postedAt: -1}}
};
}
viewParameters.best = function (terms) {
return {
options: {sort: {sticky: -1, baseScore: -1}}
};
}
viewParameters.pending = function (terms) {
return {
2014-10-06 10:27:28 +09:00
find: {
status: 1
},
options: {sort: {createdAt: -1}},
showFuture: true
};
}
viewParameters.scheduled = function (terms) {
return {
find: {postedAt: {$gte: new Date()}},
2014-12-10 09:48:24 +09:00
options: {sort: {postedAt: -1}}
};
}
viewParameters.userPosts = function (terms) {
return {
find: {userId: terms.userId},
options: {limit: 5, sort: {postedAt: -1}}
};
}
viewParameters.userUpvotedPosts = function (terms) {
var user = Meteor.users.findOne(terms.userId);
var postsIds = _.pluck(user.votes.upvotedPosts, "itemId");
return {
find: {_id: {$in: postsIds}, userId: {$ne: terms.userId}}, // exclude own posts
options: {limit: 5, sort: {postedAt: -1}}
};
}
viewParameters.userDownvotedPosts = function (terms) {
var user = Meteor.users.findOne(terms.userId);
var postsIds = _.pluck(user.votes.downvotedPosts, "itemId");
// TODO: sort based on votedAt timestamp and not postedAt, if possible
return {
find: {_id: {$in: postsIds}},
options: {limit: 5, sort: {postedAt: -1}}
};
}
heroModules = [];
2014-09-18 07:24:42 +09:00
footerModules = [];
2015-01-20 11:42:03 +09:00
threadModules = [];
2015-03-22 11:19:27 +09:00
postListTopModules = [
{
template: 'postViewsNav',
order: 99
}
];
2014-07-04 12:44:36 +09:00
postModules = [
{
template: 'postRank',
order: 1
2014-07-04 12:44:36 +09:00
},
{
template: 'postUpvote',
order: 10
},
2014-07-04 12:44:36 +09:00
{
template: 'postContent',
order: 20
2014-07-04 12:44:36 +09:00
},
{
2014-12-16 14:18:32 +09:00
template: 'postAvatars',
2014-12-13 17:43:52 +09:00
order: 30
},
2014-12-16 13:34:01 +09:00
{
2014-12-16 14:18:32 +09:00
template: 'postDiscuss',
2014-12-16 13:34:01 +09:00
order: 40
},
2014-07-04 12:44:36 +09:00
{
template: 'postActions',
order: 50
2014-07-04 12:44:36 +09:00
}
2014-07-05 11:24:28 +09:00
];
2014-12-13 17:43:52 +09:00
postThumbnail = [];
postHeading = [
{
template: 'postTitle',
2014-12-13 17:43:52 +09:00
order: 10
},
{
template: 'postDomain',
2014-12-13 17:43:52 +09:00
order: 20
}
];
postMeta = [
{
template: 'postAuthor',
2014-12-13 17:43:52 +09:00
order: 10
},
{
template: 'postInfo',
2014-12-13 17:43:52 +09:00
order: 20
},
{
template: 'postCommentsLink',
2014-12-13 17:43:52 +09:00
order: 30
2014-12-14 15:15:34 +09:00
},
{
template: 'postAdmin',
2014-12-14 15:15:34 +09:00
order: 50
}
]
2014-07-05 18:06:28 +09:00
// ------------------------------ Callbacks ------------------------------ //
postClassCallbacks = [];
2014-07-05 18:06:28 +09:00
postSubmitClientCallbacks = [];
postSubmitMethodCallbacks = [];
2014-12-24 09:42:10 +09:00
postAfterSubmitMethodCallbacks = []; // runs on server only in a timeout
2014-07-05 18:06:28 +09:00
postEditClientCallbacks = []; // loops over modifier object
postEditMethodCallbacks = []; // loops over modifier (i.e. "{$set: {foo: bar}}") object
postAfterEditMethodCallbacks = []; // loops over modifier object
2014-07-05 18:06:28 +09:00
2015-01-21 16:47:02 +09:00
postApproveCallbacks = [];
commentClassCallbacks = [];
commentSubmitRenderedCallbacks = [];
commentSubmitClientCallbacks = [];
commentSubmitMethodCallbacks = [];
2014-09-20 10:42:42 +09:00
commentAfterSubmitMethodCallbacks = [];
2014-07-05 18:06:28 +09:00
commentEditRenderedCallbacks = [];
commentEditClientCallbacks = [];
commentEditMethodCallbacks = []; // not used yet
2014-09-20 10:42:42 +09:00
commentAfterEditMethodCallbacks = []; // not used yet
2014-07-05 18:06:28 +09:00
userEditRenderedCallbacks = [];
userEditClientCallbacks = [];
userCreatedCallbacks = [];
userProfileCompleteChecks = [];
2015-01-21 10:38:59 +09:00
upvoteCallbacks = [];
downvoteCallbacks = [];
cancelUpvoteCallbacks = [];
cancelDownvoteCallbacks = [];
upvoteMethodCallbacks = [];
downvoteMethodCallbacks = [];
cancelUpvoteMethodCallbacks = [];
cancelDownvoteMethodCallbacks = [];
2015-01-21 10:38:59 +09:00
2014-12-08 14:53:26 +09:00
// ------------------------------------- User Profiles -------------------------------- //
userProfileDisplay = [
{
template: 'userInfo',
order: 1
},
{
template: 'userPosts',
order: 2
},
{
template: 'userUpvotedPosts',
order: 3
},
2014-12-08 14:53:26 +09:00
{
template: 'userDownvotedPosts',
2014-12-08 14:53:26 +09:00
order: 5
},
2014-12-08 14:53:26 +09:00
{
template: 'userComments',
2014-12-08 14:53:26 +09:00
order: 5
}
2014-12-08 20:36:46 +09:00
];
userProfileEdit = [
{
template: 'userAccount',
order: 1
}
2014-12-08 14:53:26 +09:00
]
userProfileCompleteChecks.push(
function(user) {
2014-12-06 18:19:54 +09:00
return !!getEmail(user) && !!getUserName(user);
}
);
2014-07-05 18:06:28 +09:00
// ------------------------------ Dynamic Templates ------------------------------ //
2014-07-05 11:24:28 +09:00
templates = {}
getTemplate = function (name) {
// if template has been overwritten, return this; else return template name
return !!templates[name] ? templates[name] : name;
}
// ------------------------------ Theme Settings ------------------------------ //
themeSettings = {
'useDropdowns': true // whether or not to use dropdown menus in a theme
2014-09-18 07:24:42 +09:00
};
// ------------------------------ Subscriptions ------------------------------ //
// array containing subscriptions to be preloaded
preloadSubscriptions = [];
// ------------------------------- Vote Power -------------------------------- //
2015-03-11 17:49:42 +09:00
// The equation to determine voting power
// Default to returning 1 for everybody
getVotePower = function (user) {
return 1;
};