-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
52 lines (44 loc) · 1.02 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
const RemoteStorage = require('remotestoragejs')
const Widget = require('remotestorage-widget')
let rs = new RemoteStorage({logging: false})
rs.access.claim('finance', 'rw')
rs.caching.enable('/finance/ledger/')
window.onLogged = function (fn) {
rs.on('connected', () => {
fn(true)
})
rs.on('disconnected', () => {
fn(false)
})
}
let widget = new Widget(rs, {
leaveOpen: false,
autoCloseAfter: 4000
})
setTimeout(() => {
widget.attach('rs-widget')
}, 1000)
window.client = rs.scope('/finance/ledger/journals/')
window.onGet = function (fn) {
window.getHandler = fn
}
window.onList = function (fn) {
window.listHandler = fn
}
window.retrieveFile = function (path) {
window.client.getFile(path)
.then(res => {
if (res.data) {
window.getHandler(path, res.data)
}
})
}
window.listFiles = function () {
window.client.getListing('')
.then(listing => {
window.listHandler(
Object.keys(listing)
.filter(name => name.slice(-1)[0] !== '/')
)
})
}