123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- Router.configure({
- layoutTemplate: 'layout',
- loadingTemplate: 'loading',
- notFoundTemplate: 'notFound',
- waitOn: function () {
- return [
- Meteor.subscribe('notifications')
- ];
- }
- });
- PostsListController = RouteController.extend({
- template: 'postsList',
- increment: 5,
- postsLimit: function () {
- return parseInt(this.params.postsLimit) || this.increment;
- },
- findOptions: function () {
- return {
- sort: { submitted: -1 },
- limit: this.postsLimit()
- };
- },
- subscriptions: function () {
- this.postSub = Meteor.subscribe('posts', this.findOptions());
- },
- posts: function () {
- return Posts.find({}, this.findOptions());
- },
- data: function () {
- var hasMore = this.posts().count() === this.postsLimit();
- var nextPath = this.route.path({
- postsLimit: this.postsLimit() + this.increment
- });
- return {
- posts: this.posts(),
- ready: this.postSub.ready,
- nextPath: hasMore ? nextPath : null
- };
- }
- });
- Router.route('/posts/:_id', {
- name: 'postPage',
- waitOn: function () {
- return [
- Meteor.subscribe('comments', this.params._id),
- Meteor.subscribe('singlePost', this.params._id)
- ];
- },
- data: function () {
- // "this" is the matched route.
- return Posts.findOne(this.params._id);
- }
- });
- Router.route('/posts/:_id/edit', {
- name: 'postEdit',
- waitOn: function () {
- return Meteor.subscribe('singlePost', this.params._id);
- },
- data: function () {
- // "this" is the matched route.
- return Posts.findOne(this.params._id);
- }
- });
- Router.route('/submit', {
- name: 'postSubmit'
- });
- // C'est un nom de route, pas un nom de template. Mais IR le prend comme nom de
- // template par défaut.
- Router.route('/:postsLimit?', {
- name: 'postsList'
- });
- var requireLogin = function () {
- if (!Meteor.user()) {
- if (Meteor.loggingIn()) {
- // Défini dans Router.configure().
- this.render(this.loadingTemplate);
- } else {
- this.render('accessDenied');
- }
- } else {
- this.next();
- }
- };
- // Faire une 404 si la page matche la route postPage, mais pas son argument.
- // Déclenché pour toute valeur "falsy" (null, false, undefined, empty).
- Router.onBeforeAction('dataNotFound', {
- only: 'postPage'
- });
- // Appliquer le contrôle d'accès à la route postSubmit.
- Router.onBeforeAction(requireLogin, {
- only: 'postSubmit'
- });
|