-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.html
89 lines (77 loc) · 3.64 KB
/
options.html
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
85
86
87
88
89
<html>
<head>
<title>Dictionary Options</title>
<h2>Option Editor</h2>
<meta http-equiv="X-UA-Compatible" content="IE=9">
<script type="text/javascript" src="https://apis.google.com/js/api.js"></script>
<script type="text/javascript" src="realtime-client-utils.js"></script>
<script>
// called by controller.js
function onFileLoaded(ignoredDoc) {
//configuration.keys().forEach(key => if (key != 'langs') textarea1.textContent += keys[k] + " = " + configuration.get(keys[k]) + "\n")
var configuration = controller.getConfiguration();
configuration.keys().forEach(key => {if (key != 'langs') textarea1.textContent += key + " = " + configuration.get(key) + "\n"})
//controller.getConfig('langs').keys().forEach((k, lang) => textarea1.textContent += k + ": " + lang + "\n")
let langs = controller.getConfig('langs') ; for (let k in langs) { textarea1.textContent += k + ": " + langs[k] + "\n" }
textarea1.disabled = savebutton.disabled = false
}
function onMapValueChanged(evt) {
//console.log("event = " + showAll(evt))
// null => "" when created
// "something" => null when deleted
if (evt.newValue == null) console.log("remote event: deleted " + evt.property)
else if (evt.oldValue == null) console.log("remote event: created " + evt.property)
else console.log("remote event: model updated " + evt.property + ": " + evt.oldValue + " => " + evt.newValue)
}
function saveButtonClick() {
// Replaced \n ->, we shoud have JSON. Unortunately,
// it fails
//alert(JSON.parse(textarea1.value.replace(/\n/g, ",")))
// let's parse manualy
var json = {} ; var configuration = controller.getConfiguration();
controller.compound(function() {
configuration.clear() ; textarea1.value.split('\n').forEach( line => {
function decouple(separator, todo) {
if (line.indexOf(separator) != -1) {
var pair = line.split(separator).map(function(item) {return item.trim()})
todo(pair[0], pair[1])
}
}
decouple(':', (first, second) => json[first] = second)
decouple('=', (property, value) => configuration.set(property, value))
})
configuration.set('langs', json)
})
}
function defaultButtonClick() {
controller.model.getRoot().set('configuration', controller.model.createMap(controller.defaultConfig))
textarea1.textContent = ""
onFileLoaded(undefined)
}
</script>
<script type="text/javascript" src="controller.js"></script>
</head>
<!-- Start Realtime when the body has loaded. -->
<body onLoad='controller = new Controller(onFileLoaded)'>
<button id="authorizeButton" disabled>You must authorize</button>
<button id="pick" onclick="rtclient.selectOrCreateNew()">Pick another file</button>
<!-- Undo and redo buttons. -->
<button id="undoButton" disabled>Undo</button>
<button id="redoButton" disabled>Redo</button>
<p>
<table style="float:left;margin:0px 10px 0px 0px;">
<tr><td><textarea disabled id="textarea1" rows=7 cols=50 align="right" ></textarea></td></tr>
<tr><td><button disabled id="savebutton" onclick="saveButtonClick()">Save</button>
<button id="defltbutton" onclick="defaultButtonClick()">Defaults</button> and <a href="javascript:window.location = 'index.html' + location.hash">Graph the dictionary</a></td></tr>
</table>
Leading and ending whitespaces are stripped
in keys and values. <br>
Normally you use = to separate key from values. Extraordinary
form, like <code>en: red</code> and <code>ru: green</code>
is used to link language with node colors.<br>
The options are just an example and have no effect in the
dictinary besides the separator.<br> Separator is used to separate
associated words.
<p>
</body>
</html>