import { MeetingSeries } from '/imports/meetingseries'

Router.configure({
    // set default application template for all routes
    layoutTemplate: 'appLayout'
});


Router.route('/', {name: 'home'});

Router.route('/meetingseries/:_id', function () {
    var meetingSeriesID = this.params._id;
    this.render('meetingSeriesDetails', {data: meetingSeriesID});
});

Router.route('/minutesadd/:_id', function () {
    let meetingSeriesID = this.params._id;
    ms = new MeetingSeries(meetingSeriesID);

    let id = '';
    ms.addNewMinutes(newMinutesID => {
        id = newMinutesID;
    });

    this.redirect('/minutesedit/' + id);
});

Router.route('/minutesedit/:_id', function () {
    var minutesID = this.params._id;
    this.render('minutesedit', {data: minutesID});
});

import { MeetingSeries } from '/imports/meetingseries'

Router.configure({
    // set default application template for all routes
    layoutTemplate: 'appLayout'
});


Router.route('/', {name: 'home'});

Router.route('/meetingseries/:_id', function () {
    var meetingSeriesID = this.params._id;
    this.render('meetingSeriesDetails', {data: meetingSeriesID});
});

Router.route('/minutesadd/:_id', function () {
    let meetingSeriesID = this.params._id;
    ms = new MeetingSeries(meetingSeriesID);

    let id;
    ms.addNewMinutes(newMinutesID => {
        id = newMinutesID;
    });

    // callback should have been called by now
    if (id) {
        this.redirect('/minutesedit/' + id);
    } else {
        // todo: use error page
        this.redirect('/meetingseries/' + meetingSeriesID);
    }
});

Router.route('/minutesedit/:_id', function () {
    var minutesID = this.params._id;
    this.render('minutesedit', {data: minutesID});
});

Add a fallback redirect in case an error occurs
Add a fallback redirect in case an error occurs

In case something goes wrong while adding new minutes,
the user is now redirected to something that most
likely exists. Should be extended to redirect the
user to an error page that explains what happened.
Or the meetingseries/:_id page with a flash message/
modal box, that explains what happened.

Important: Really redirect the user, otherwise the
minutesadd/:_id page will be re-rendered because
minutesAdd changes the meeting series document.
Re-rendering potentially causes re-adding of new
minutes which might trap the user in an endless loop,
creating numerous new minutes.
