-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui.backend.webdav.js
executable file
·74 lines (58 loc) · 1.6 KB
/
ui.backend.webdav.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
MM.UI.Backend.WebDAV = Object.create(MM.UI.Backend, {
id: {value: "webdav"}
});
MM.UI.Backend.WebDAV.init = function(select) {
MM.UI.Backend.init.call(this, select);
this._url = this._node.querySelector(".url");
this._url.value = localStorage.getItem(this._prefix + "url") || "";
this._current = "";
}
MM.UI.Backend.WebDAV.getState = function() {
var data = {
url: this._current
};
return data;
}
MM.UI.Backend.WebDAV.setState = function(data) {
this._load(data.url);
}
MM.UI.Backend.WebDAV.save = function() {
MM.App.setThrobber(true);
var map = MM.App.map;
var url = this._url.value;
localStorage.setItem(this._prefix + "url", url);
if (url.match(/\.mymind$/)) { /* complete file name */
} else { /* just a path */
if (url.charAt(url.length-1) != "/") { url += "/"; }
url += map.getName() + "." + MM.Format.JSON.extension;
}
this._current = url;
var json = map.toJSON();
var data = MM.Format.JSON.to(json);
this._backend.save(data, url).then(
this._saveDone.bind(this),
this._error.bind(this)
);
}
MM.UI.Backend.WebDAV.load = function() {
this._load(this._url.value);
}
MM.UI.Backend.WebDAV._load = function(url) {
this._current = url;
MM.App.setThrobber(true);
var lastIndex = url.lastIndexOf("/");
this._url.value = url.substring(0, lastIndex);
localStorage.setItem(this._prefix + "url", this._url.value);
this._backend.load(url).then(
this._loadDone.bind(this),
this._error.bind(this)
);
}
MM.UI.Backend.WebDAV._loadDone = function(data) {
try {
var json = MM.Format.JSON.from(data);
} catch (e) {
this._error(e);
}
MM.UI.Backend._loadDone.call(this, json);
}