summaryrefslogtreecommitdiff
path: root/cmd/dolmetschctld/web-static
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2019-02-13 19:19:39 +0100
committerChristian Pointner <equinox@spreadspace.org>2019-02-13 19:19:39 +0100
commitb9f081d1aeb87186e7118ed796ab51eeac9b8fab (patch)
tree0a21dece426ecd7f002af26063e444f00bdcb23c /cmd/dolmetschctld/web-static
parentimplemented set_language command via web sockets (diff)
implemented command to fetch list of languages
Diffstat (limited to 'cmd/dolmetschctld/web-static')
-rw-r--r--cmd/dolmetschctld/web-static/socket.html23
1 files changed, 17 insertions, 6 deletions
diff --git a/cmd/dolmetschctld/web-static/socket.html b/cmd/dolmetschctld/web-static/socket.html
index b9bebbb..0dd88c5 100644
--- a/cmd/dolmetschctld/web-static/socket.html
+++ b/cmd/dolmetschctld/web-static/socket.html
@@ -26,13 +26,25 @@
function Controller(url) {
this.sock = new WebSocket(url);
this.sock_onmessage = function (event) {
- $('#rawmsg').text(event.data);
+ data = JSON.parse(event.data)
+ if(data.type == 'languages') {
+ sel = $('#selectlang');
+ sel.empty();
+ for (var i=0; i < data.languages.length; i++) {
+ sel.append('<option>' + data.languages[i] + '</option>')
+ }
+ } else {
+ $('#rawmsg').text(event.data);
+ }
$('#buttonstate').removeAttr('disabled','disabled');
+ $('#buttonlang').removeAttr('disabled','disabled');
}
this.sock.onmessage = this.sock_onmessage.bind(this);
this.sock_onopen = function() {
+ this.send({ command: "languages" });
$('#buttonstate').removeAttr('disabled','disabled');
+ $('#buttonlang').removeAttr('disabled','disabled');
}
this.sock.onopen = this.sock_onopen.bind(this);
@@ -45,17 +57,16 @@
var ctrl = new Controller("ws://localhost:8234/api/v1/socket");
function state() {
- req = { command: "state" };
- ctrl.send(req);
+ ctrl.send({ command: "state" });
}
function set_language() {
- req = { command: "language", arguments: [ $('#inputlang').val() ] };
- ctrl.send(req);
+ ctrl.send({ command: "language", arguments: [ $('#selectlang').val() ] });
}
function init() {
$('#buttonstate').attr('disabled','disabled')
+ $('#buttonslang').attr('disabled','disabled')
}
</script>
</head>
@@ -66,7 +77,7 @@
<div>
<button id="buttonstate" onclick="state()">get state</button>
<button id="buttonlang" onclick="set_language()">set language</button>
- <input type="text" id="inputlang" length="10">
+ <select id="selectlang"></select>
<div id="rawmsg" class="data"></div>
</div>