summaryrefslogtreecommitdiff
path: root/www
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-09-29 20:57:07 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-09-29 20:57:35 (GMT)
commite884cb9cd018043b4ac4599ce577bf8b7bc22ae1 (patch)
treef67a0a41dc7ba0b533decac1ac24ecddcdbcd17a /www
parent8dc413a488c300c7a018a15e9c71b62cdd2d9ac0 (diff)
use callbacks for rhctl as well
Diffstat (limited to 'www')
-rw-r--r--www/js/rhctl.js15
1 files changed, 13 insertions, 2 deletions
diff --git a/www/js/rhctl.js b/www/js/rhctl.js
index 5b5b438..103f12c 100644
--- a/www/js/rhctl.js
+++ b/www/js/rhctl.js
@@ -22,6 +22,7 @@
'use strict';
function Rhctl() {
+ this.draw_callbacks = $.Callbacks('unique');
this.state = 'NEW';
this.sock_onmessage = function(event) {
@@ -31,7 +32,7 @@ function Rhctl() {
} else {
switch(msg.TYPE) {
case 'state':
- $('#rhctl').text(JSON.stringify(msg.STATE, null, '\t'));
+ this.draw_callbacks.fireWith(window, [ msg.STATE ]);
break;
case 'ack':
break;
@@ -41,6 +42,10 @@ function Rhctl() {
}
}
+ this.addCallback = function(cb) {
+ this.draw_callbacks.add(cb);
+ }
+
this.sock_onopen = function() {
this.state = 'CONNECTED';
console.log('rhctl: ' + this.state)
@@ -69,6 +74,12 @@ function Rhctl() {
var rhctl = new Rhctl();
function rhctl_init() {
- $('#rhctl').text("loading...");
rhctl.connect();
+ $('#rhctl').text("loading...");
+ rhctl.addCallback(rhctl_draw_state);
+}
+
+function rhctl_draw_state(state) {
+ console.log(state);
+ $('#rhctl').text(JSON.stringify(state, null, '\t'));
}