forked from Openki/Openki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routing.js
143 lines (126 loc) · 3.5 KB
/
routing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import '/imports/Profile.js';
import '/imports/LocalTime.js';
Router.configure({
layoutTemplate: 'layout',
notFoundTemplate: 'notFound',
loadingTemplate: 'loadingPage',
});
Router.onBeforeAction('dataNotFound');
webpagename = 'Openki - '; // global (document title init)
Router.map(function () {
this.route('pages', { ///////// static /////////
path: 'page/:page_name',
action: function() {
this.render(this.params.page_name);
},
onAfterAction: function() {
document.title = webpagename + '' + this.params.page_name;
}
});
});
Router.map(function () {
this.route('showEvent', {
path: 'event/:_id/:slug?',
template: 'eventPage',
notFoundTemplate: 'eventNotFound',
waitOn: function () {
var subs = [
Meteor.subscribe('event', this.params._id)
];
var courseId = this.params.query.courseId;
if (courseId) {
subs.push(Meteor.subscribe('courseDetails', courseId));
}
return subs;
},
data: function () {
var event;
var create = 'create' == this.params._id;
if (create) {
var propose = LocalTime.now().add(1, 'week').startOf('hour');
event = {
new: true,
startLocal: LocalTime.toString(propose),
endLocal: LocalTime.toString(moment(propose).add(2, 'hour')),
};
var course = Courses.findOne(this.params.query.courseId);
if (course) {
event.title = course.name;
event.courseId = course._id;
event.region = course.region;
event.description = course.description;
event.internal = course.internal;
}
} else {
event = Events.findOne({_id: this.params._id});
if (!event) return false;
}
return event;
},
onAfterAction: function() {
var event = Events.findOne({_id: this.params._id});
if (event) {
document.title = webpagename + mf('event.windowtitle', {EVENT:event.title, DATE: moment(event.start).calendar()}, '{DATE} {EVENT}');
} else {
document.title = webpagename + mf('event.windowtitle.create', 'Create event');
}
}
});
});
Router.map(function () {
this.route('profile', {
path: 'profile',
waitOn: function () {
return [
Meteor.subscribe('currentUser'),
Meteor.subscribe('groupsFind', { own: true }),
Meteor.subscribe('venuesFind', { editor: Meteor.userId() })
];
},
data: function () {
var data = {};
var user = Meteor.user();
data.loggedIn = !!user;
if (data.loggedIn) {
var userdata = {
_id: user._id,
name: user.username,
privacy: user.privacy,
notifications: user.notifications,
groups: GroupLib.find({ own: true }),
venues: Venues.find({ editor: user._id })
};
userdata.have_email = user.emails && user.emails.length > 0;
if (userdata.have_email) {
userdata.email = user.emails[0].address;
userdata.verified = !!user.emails[0].verified;
}
data.user = userdata;
data.involvedIn = coursesFind({ userInvolved: user._id });
}
return data;
},
onAfterAction: function() {
var user = Meteor.users.findOne();
if (!user) return;
document.title = webpagename + 'My Profile_Settings - ' + user.username;
}
});
});
Router.route('/profile/unsubscribe/:token', function() {
var unsubToken = this.params.token;
var accepted = Profile.Notifications.unsubscribe(unsubToken);
var query = {};
if (accepted) {
query.unsubscribed = '';
} else {
query['unsubscribe-error'] = '';
}
this.response.writeHead(302, {
'Location': Router.url('profile', {}, { query: query })
});
this.response.end();
}, {
name: 'profile.unsubscribe',
where: 'server'
});