]> cgit.babelmonkeys.de Git - adhocweb.git/blobdiff - js/main.js
Restructure adhoc "class"
[adhocweb.git] / js / main.js
index 15a0fd079a41a87b3d9f4a807495856c41e42486..621596162d3ce61b9068efa0eed6c07c7fd9605e 100644 (file)
@@ -1,11 +1,11 @@
 var BOSH_SERVICE = 'http://localhost:5280/http-bind/';
 var show_log = true;
 
-Strophe.addNamespace("ADHOC", "http://jabber.org/protocol/commands");
-
 var localJID = null;
 var connection   = null;
 
+var commandCenter = null;
+
 function log(msg) {
     var entry = $('<div></div>').append(document.createTextNode(msg));
     $('#log').append(entry);
@@ -19,6 +19,17 @@ function rawOutput(data) {
     log('SENT: ' + data);
 }
 
+function getFeatures(jid) {
+    var cb, ecb;
+    cb = function(result) { /* Callback */
+       commandCenter.getCommandNodes(function(items) { $('#output').empty(); $('#output').append(items) });
+    }
+    ecb = function(result) { /* Errback */
+       $('#output').append("<p>" + jid + " does NOT support AdHoc commands</p>");
+    }
+    commandCenter.checkFeatures(jid, cb, ecb);
+}
+
 function onConnect(status) {
     if (status == Strophe.Status.CONNECTING) {
         log('Strophe is connecting.');
@@ -39,7 +50,13 @@ function onConnect(status) {
         log('Strophe is connected.');
         $('#queryJID').val(connection.domain);
         $('#query').show();
-        Adhoc.checkFeatures("#output", connection.domain);
+       commandCenter = new Adhoc("#output", function() {
+               $("<input type='button' value='Start over'/>").bind("click", function() {
+                       $('#output').empty();
+                       commandCenter.getCommandNodes(function(items) { $('#output').append(items) });
+               }).appendTo('#output');
+       });
+        getFeatures(connection.domain);
     }
 }
 
@@ -100,7 +117,7 @@ $(document).ready(function () {
     });
 
     $('#queryForm').bind('submit', function (event) {
-        Adhoc.checkFeatures("#output", $('#queryJID').val());
+        getFeatures($('#queryJID').val());
         event.preventDefault();
     });
 });