forked from leangjia/mymind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.backend.file.js
57 lines (46 loc) · 1.54 KB
/
ui.backend.file.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
MM.UI.Backend.File = Object.create(MM.UI.Backend, {
id: {value: "file"}
});
MM.UI.Backend.File.init = function(select) {
MM.UI.Backend.init.call(this, select);
this._format = this._node.querySelector(".format");
this._format.appendChild(MM.Format.JSON.buildOption());
this._format.appendChild(MM.Format.FreeMind.buildOption());
this._format.appendChild(MM.Format.MMA.buildOption());
this._format.appendChild(MM.Format.Mup.buildOption());
this._format.appendChild(MM.Format.Plaintext.buildOption());
this._format.value = localStorage.getItem(this._prefix + "format") || MM.Format.JSON.id;
}
MM.UI.Backend.File.show = function(mode) {
MM.UI.Backend.show.call(this, mode);
this._go.innerHTML = (mode == "save" ? "Save" : "Browse");
}
MM.UI.Backend.File._action = function() {
localStorage.setItem(this._prefix + "format", this._format.value);
MM.UI.Backend._action.call(this);
}
MM.UI.Backend.File.save = function() {
var format = MM.Format.getById(this._format.value);
var json = MM.App.map.toJSON();
var data = format.to(json);
var name = MM.App.map.getName() + "." + format.extension;
this._backend.save(data, name).then(
this._saveDone.bind(this),
this._error.bind(this)
);
}
MM.UI.Backend.File.load = function() {
this._backend.load().then(
this._loadDone.bind(this),
this._error.bind(this)
);
}
MM.UI.Backend.File._loadDone = function(data) {
try {
var format = MM.Format.getByName(data.name) || MM.Format.JSON;
var json = format.from(data.data);
} catch (e) {
this._error(e);
}
MM.UI.Backend._loadDone.call(this, json);
}