forked from ondras/my-mind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.backend.local.js
84 lines (71 loc) · 1.77 KB
/
ui.backend.local.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
MM.UI.Backend.Local = Object.create(MM.UI.Backend, {
id: {value: "local"}
});
MM.UI.Backend.Local.init = function(select) {
MM.UI.Backend.init.call(this, select);
this._list = this._node.querySelector(".list");
this._remove = this._node.querySelector(".remove");
this._remove.addEventListener("click", this);
}
MM.UI.Backend.Local.handleEvent = function(e) {
MM.UI.Backend.handleEvent.call(this, e);
switch (e.target) {
case this._remove:
var id = this._list.value;
if (!id) { break; }
this._backend.remove(id);
this.show(this._mode);
break;
}
}
MM.UI.Backend.Local.show = function(mode) {
MM.UI.Backend.show.call(this, mode);
this._go.disabled = false;
if (mode == "load") {
var list = this._backend.list();
this._list.innerHTML = "";
if (Object.keys(list).length) {
this._go.disabled = false;
this._remove.disabled = false;
this._buildList(list, this._list);
} else {
this._go.disabled = true;
this._remove.disabled = true;
var o = document.createElement("option");
o.innerHTML = "(no maps saved)";
this._list.appendChild(o);
}
}
}
MM.UI.Backend.Local.setState = function(data) {
this._load(data.id);
}
MM.UI.Backend.Local.getState = function() {
var data = {
b: this.id,
id: MM.App.map.getId()
};
return data;
}
MM.UI.Backend.Local.save = function() {
var json = MM.App.map.toJSON();
var data = MM.Format.JSON.to(json);
try {
this._backend.save(data, MM.App.map.getId(), MM.App.map.getName());
this._saveDone();
} catch (e) {
this._error(e);
}
}
MM.UI.Backend.Local.load = function() {
this._load(this._list.value);
}
MM.UI.Backend.Local._load = function(id) {
try {
var data = this._backend.load(id);
var json = MM.Format.JSON.from(data);
this._loadDone(json);
} catch (e) {
this._error(e);
}
}