forked from abdojulari/transcript-editor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
router.js
108 lines (86 loc) · 3.21 KB
/
router.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
app.routers.DefaultRouter = Backbone.Router.extend({
routes: {
"": "index",
"?*queryString": "index",
"transcripts/:id": "transcriptEdit",
"transcripts/:id?*queryString": "transcriptEdit",
"page/:id": "pageShow",
"dashboard": "dashboard",
},
before: function( route, params ) {
$('#main').empty().addClass('loading');
},
after: function( route, params ) {
window.scrollTo(0, 0);
},
dashboard: function(){
var data = this._getData(data);
var header = new app.views.Header(data);
var main = new app.views.Dashboard(data);
var footer = new app.views.Footer(data);
main.$el.attr('role', 'main');
},
index: function(queryString) {
var data = this._getData(data);
if (queryString) data.queryParams = deparam(queryString);
var header = new app.views.Header(data);
var main = new app.views.Home(data);
var footer = new app.views.Footer(data);
},
pageShow: function(id){
var data = this._getData(data);
var header = new app.views.Header(data);
var main = new app.views.Page(_.extend({}, data, {el: '#main', page_key: id}));
var footer = new app.views.Footer(data);
main.$el.removeClass('loading').attr('role', 'main');
},
transcriptEdit: function(id, queryString) {
var data = this._getData(data);
if (queryString) data.queryParams = deparam(queryString);
var header = new app.views.Header(data);
var toolbar = new app.views.TranscriptToolbar(_.extend({}, data, {el: '#secondary-navigation', menu: 'transcript_edit'}));
var modals = new app.views.Modals(data);
var footer = new app.views.Footer(data);
var verifyView = new app.views.TranscriptLineVerify(data);
modals.addModal(verifyView.$el);
var flagView = new app.views.TranscriptLineFlag(data);
modals.addModal(flagView.$el);
var downloadView = new app.views.TranscriptDownload(_.extend({}, data, {transcript_id: id}));
modals.addModal(downloadView.$el);
var transcript_model = new app.models.Transcript({id: id});
var main = new app.views.TranscriptEdit(_.extend({}, data, {el: '#main', model: transcript_model}));
},
_getData: function(data){
var user = {};
if ($.auth.user && $.auth.user.signedIn) {
user = $.auth.user;
}
data = data || {};
data = $.extend({}, {project: PROJECT, user: user, debug: DEBUG, route: this._getRouteData()}, data);
DEBUG && console.log('Route', data.route);
return data;
},
_getRouteData: function(){
var Router = this,
fragment = Backbone.history.fragment,
routes = _.pairs(Router.routes),
route = null, action = null, params = null, matched, path;
matched = _.find(routes, function(handler) {
action = _.isRegExp(handler[0]) ? handler[0] : Router._routeToRegExp(handler[0]);
return action.test(fragment);
});
if(matched) {
params = Router._extractParameters(action, fragment);
route = matched[0];
action = matched[1];
}
path = fragment ? '/#/' + fragment : '/';
return {
route: route,
action: action,
fragment : fragment,
path: path,
params : params
};
}
});