From e884cb9cd018043b4ac4599ce577bf8b7bc22ae1 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 29 Sep 2016 22:57:07 +0200 Subject: use callbacks for rhctl as well 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')); } -- cgit v0.10.2