-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathroutes.js
123 lines (114 loc) · 3.47 KB
/
routes.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
/**
* @author Benjamin Berman
* © 2014 All Rights Reserved
**/
RouteControllers = {};
var gameAction = function () {
var gameId = getCurrentGameId();
var game = Games.findOne(gameId, {fields: {judgeId: 1, round: 1, open: 1, players: 1}});
if (_.isUndefined(this.currentRound)) {
this.currentRound = game.round;
}
var myPlayerId = playerIdForUserId(Meteor.userId());
if (_.isUndefined(this.isCurrentJudgeMe)) {
this.isCurrentJudgeMe = myPlayerId === game.judgeId;
}
var currentRouteName = this.route.getName();
if (this.currentRound !== game.round
&& currentRouteName !== 'roundSummary') {
// If the round has changed, go to the round summary
this.currentRound = game.round;
this.redirect('roundSummary', {gameId: gameId});
} else if (!canPlay(game)
&& currentRouteName !== 'roundSummary') {
// If I can't play, redirect to waiting
this.redirect('roundSummary', {gameId: gameId});
} else if (myPlayerId === game.judgeId
&& !this.isCurrentJudgeMe) {
// If I became the judge due to a drop out, switch views
this.isCurrentJudgeMe = true;
this.redirect('roundSummary', {gameId: gameId});
} else if (myPlayerId !== game.judgeId
&& this.isCurrentJudgeMe) {
// If I am not currently the judge but previously I was, record so. No changing of views necessary.
this.isCurrentJudgeMe = false;
} else if (game.open === false
&& currentRouteName !== 'gameOver') {
// If the game is over, redirect to game over
this.redirect('gameOver', {gameId: gameId});
} else {
this.render();
}
};
RouteControllers.home = {
path: '/'
};
RouteControllers.accountLogin = {};
RouteControllers.anonymousLogin = {};
RouteControllers.browse = {};
RouteControllers.chooseCardFromHand = {
path: '/g/:gameId/hand',
action: gameAction
};
RouteControllers.createGame = {
path: '/cg/'
};
RouteControllers.gameOver = {
path: '/g/:gameId/over',
action: gameAction
};
RouteControllers.history = {};
RouteControllers.invitation = {};
RouteControllers.judge = {
path: '/g/:gameId/judge',
action: gameAction
};
RouteControllers.login = {};
RouteControllers.myGames = {};
RouteControllers.news = {};
RouteControllers.pickFriends = {};
RouteControllers.pickQuestion = {};
RouteControllers.preview = {
path: '/g/:gameId/p/:cardId',
action: gameAction
};
RouteControllers.roundSummary = {
path: '/g/:gameId',
action: gameAction
};
RouteControllers.waitForPlayers = {
path: '/g/:gameId/w',
action: gameAction
};
_.each(RouteControllers, function (routeController, routeName) {
if (!routeController.path) {
routeController.path = '/' + routeName;
}
if (!routeController.template) {
routeController.template = routeName + 'View';
}
if (!routeController.yieldRegions) {
routeController.yieldRegions = {
'navbar': {to: 'navbar'}
};
}
if (!routeController.layoutTemplate) {
routeController.layoutTemplate = 'layout';
}
Router.route(routeName, routeController);
});
if (Meteor.isClient) {
$.mobile = {
initializePage: function () {
},
// Shim for jQuqeryMobile
changePage: function (destination) {
Router.go(destination.slice(1));
},
activePage: {
attr: function () {
return Router.current().route.getName();
}
}
};
}