This repository has been archived by the owner on Aug 2, 2019. It is now read-only.
forked from leplatrem/daybed-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
58 lines (45 loc) · 1.93 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
55
56
57
58
window.Daybed.SETTINGS.SERVER = 'https://daybed.io/v1';
window.Daybed.SETTINGS.TILES = (window.Daybed.SETTINGS.TILES || "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png");
window.Daybed.SETTINGS.PREFIX = 'daybed:map:';
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) {
if (modelname.indexOf(window.Daybed.SETTINGS.PREFIX) !== 0) {
modelname = window.Daybed.SETTINGS.PREFIX + modelname;
}
this.definition = new MapModel({id: modelname});
// Redirect to creation page if unknown
var createIfMissing = function (model, xhr) {
var destination = modelname + '/create';
if (xhr.status == 401 || xhr.status == 403) {
destination = ''; // exists but can't read
}
return app.navigate(destination, {trigger:true});
};
this.definition.fetch({error: createIfMissing});
}
this.definition.whenReady((function () {
var view = new MainView(this.definition);
$("#content").html(view.render().el);
}).bind(this));
}
});