forked from tilemill-project/tilemill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRouter.bones
151 lines (135 loc) · 4.31 KB
/
Router.bones
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
144
145
146
147
148
149
150
controller = Backbone.Controller.extend();
controller.prototype.initialize = function() {
if (Bones.server) return;
new views.App({ el: $('body') });
// Check whether there is a new version of TileMill or not.
(new models.Config).fetch({success: function(m) {
if (window.abilities.platform === 'darwin') return;
if (!m.get('updates')) return;
if (!semver.gt(m.get('updatesVersion'),
window.abilities.tilemill.version)) return;
new views.Modal({
content:_('\
A new version of TileMill is available.<br />\
Update to TileMill <%=version%> today.<br/>\
<small>You can disable update notifications in the <strong>Settings</strong> panel.</small>\
').template({ version:m.get('updatesVersion') }),
affirmative: 'Update',
negative: 'Later',
callback: function() { window.open('http://tilemill.com') }
});
}});
// Add catchall routes for error page.
this.route(/^(.*?)/, 'error', this.error);
};
controller.prototype.routes = {
'.*\?goto=*path': 'goto',
'': 'projects',
'/': 'projects',
'/project/:id': 'project',
'/project/:id/export': 'projectExport',
'/project/:id/export/:format': 'projectExport',
'/project/:id/settings': 'projectSettings',
'/oauth/success': 'oauthSuccess',
'/oauth/error': 'oauthError',
'/manual': 'manual',
'/manual/:page?': 'manual',
'/settings': 'config',
'/plugins': 'plugins',
};
controller.prototype.goto = function(path) {
var go = !window.onbeforeunload || window.onbeforeunload() !== false;
if (go !== false) window.location.hash = path;
};
controller.prototype.error = function() {
new views.Error(new Error('Page not found.'));
};
controller.prototype.projects = function(next) {
(new models.Projects()).fetch({
success: function(collection) {
new views.Projects({
el: $('#page'),
collection: collection
});
if (next) next();
},
error: function(m, e) { new views.Modal(e); }
});
};
controller.prototype.project = function(id, next) {
(new models.Project({ id: id })).fetch({
success: function(model) {
new views.Project({
el: $('#page'),
model: model
});
if (next) next();
},
error: function(m, e) { new views.Modal(e); }
});
};
controller.prototype.projectExport = function(id, format) {
this.project(id, _(function() {
if (format) {
$('.actions a[href=#export-'+format+']').click();
} else {
$('.actions a[href=#exports]').click();
}
}).bind(this));
};
controller.prototype.projectSettings = function(id, format) {
this.project(id, _(function() {
$('.actions a[href=#settings]').click();
}).bind(this));
};
controller.prototype.manual = function(page) {
Bones.utils.fetch({
page: new models.Page({ id: page }),
pages: new models.Pages()
}, function(err, data) {
if (err) return new views.Modal(err);
new views.Manual({
el: $('#page'),
model: data.page,
collection: data.pages,
page: page
});
});
};
controller.prototype.config = function() {
(new models.Config).fetch({
success: function(model, resp) {
new views.Config({
el: $('#page'),
model: model
});
},
error: function(model, err) {
new views.Modal(err);
}
});
};
controller.prototype.plugins = function() {
new views.Plugins({
el: $('#page'),
collection: new models.Plugins(_(window.abilities.plugins).toArray())
});
};
controller.prototype.oauthSuccess = function() {
this.projects(function() {
new views.Modal({
content: 'Your MapBox account was authorized successfully.',
negative: '',
callback: function() {}
});
});
};
controller.prototype.oauthError = function() {
this.projects(function() {
new views.Modal({
content: 'An error occurred while authorizing your MapBox account.',
negative: '',
callback: function() {}
});
});
};