-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
54 lines (43 loc) · 1.83 KB
/
app.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
window.Daybed.SETTINGS.SERVER = 'https://daybed.lolnet.org';
window.Daybed.SETTINGS.TILES = (window.Daybed.SETTINGS.TILES || "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png");
window.Daybed.SETTINGS.STYLES = L.Util.extend((window.Daybed.SETTINGS.STYLES || {}), {
'default': {color: 'green', fillColor: 'green', opacity: 0.5},
'highlight': {color: 'yellow', fillColor: 'yellow', opacity: 1.0}
});
var DaybedMapApp = Backbone.Router.extend({
routes: {
"": "home",
":modelname/create": "create",
":modelname": "list"
},
initialize: function () {
this.definition = null;
},
home: function() {
$("#content").html(new HomeView().render().el);
},
create: function(modelname) {
$("#content").html(new DefinitionCreate({modelname: modelname}).render().el);
},
list: function(modelname) {
// If no definition loaded or model changed, fetch from server !
if (!this.definition || this.definition.modelname != modelname) {
this.definition = new MapModel({id: modelname});
// Redirect to creation page if unknown
var createIfMissing = function (model, xhr) {
if (xhr.status == 404) {
app.navigate(modelname + '/create', {trigger:true});
}
};
this.definition.fetch({error: createIfMissing});
// Do we know its token already ?
var storage = window.localStorage || {};
this.definition.set('token', storage["daybed.token." + modelname]);
}
this.definition.whenReady((function () {
var view = new ListView(this.definition);
$("#content").html(view.el); // Leaflet needs its container in DOM
view.render();
}).bind(this));
}
});