summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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'));
}