12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- 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);
- },
- 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'
- });
|