X-Git-Url: http://cgit.babelmonkeys.de/?p=adhocweb.git;a=blobdiff_plain;f=js%2Fmain.js;h=85f2ccaeaa2ec8887710ca2fe8baed05aff0ada7;hp=6bd32412743739166210a6cc07f5d3c9e3df1a29;hb=7ef6024aa84881aba55e61c38073fc9465aac876;hpb=e5d4fe480e02907b80e91d9ed42854700c5866c1 diff --git a/js/main.js b/js/main.js index 6bd3241..85f2cca 100644 --- a/js/main.js +++ b/js/main.js @@ -1,13 +1,15 @@ var BOSH_SERVICE = 'http://localhost:5280/http-bind/'; -var show_log = false; +var show_log = true; Strophe.addNamespace("ADHOC", "http://jabber.org/protocol/commands"); var localJID = null; var connection = null; -var sessionid = null; -var cmdNode = null; -var queryJID = null; +var adhoc_status = { + sessionid: null, + cmdNode: null, + queryJID: null +}; function log(msg) { var entry = $('
').append(document.createTextNode(msg)); @@ -40,10 +42,10 @@ function onConnect(status) { } } else if (status == Strophe.Status.CONNECTED) { log('Strophe is connected.'); - queryJID = connection.domain; - $('#queryJID').val(queryJID); + adhoc_status.queryJID = connection.domain; + $('#queryJID').val(adhoc_status.queryJID); $('#query').show(); - checkFeatures(); + checkFeatures("#output"); } } @@ -56,15 +58,18 @@ function addNote(elem, text, type) { } function addForm(elem, x) { - var form = $("
"); - form.submit(function(event){event.preventDefault();}); + var form = $(""); + form.submit(function(event) { + executeCommand("execute", serializeToDataform('form'), function(e) { displayResult(elem, e) }); + event.preventDefault(); + }); var fieldset = $("
"); form.append(fieldset); if ($(x).find("title").length > 0) $("").text($(x).find("title").text()).appendTo(fieldset); if ($(x).find("instructions").length > 0) $("

").text($(x).find("instructions").text()).appendTo(fieldset); - $(x).find("field").each(function(){ + $(x).find("field").each(function() { var item = null; var type = $(this).attr("type"); if($(this).attr("label")) { @@ -95,15 +100,15 @@ function addForm(elem, x) { break; case "list-multi": item = $(""); - $(this).find("option").each(function(){ - $("

    "); + var items = $("
      "); + $(elem).append(items); $(result).find("item").each(function(index, e) { - link = $("" + $(e).attr("name") + "").click(runCommand) - item = $("
    • ").append(link); - $("#items").append(item); + $("
    • ").append($("" + $(e).attr("name") + "").click(function (event) { + runCommand(this, function (result) { displayResult(elem, result); }); + event.preventDefault(); + })).appendTo(items); }); }); } -function checkFeatures() { - featureIQ = $iq({ type: "get", to: queryJID, id: "features1" }).c("query", {xmlns: Strophe.NS.DISCO_INFO}); - connection.sendIQ(featureIQ, function(result) { - if ($(result).find("feature[var='" + Strophe.NS.ADHOC + "']").length > 0) { - $('#output').append("

      This entitiy does support AdHoc commands

      "); - } else { - $('#output').append("

      This entitiy does NOT support AdHoc commands

      "); +function checkFeatures(elem) { + if (adhoc_status.sessionid) + cancelCommand(); + featureIQ = $iq({ type: "get", to: adhoc_status.queryJID, id: connection.getUniqueId() }).c("query", {xmlns: Strophe.NS.DISCO_INFO}); + $(elem).empty(); + connection.sendIQ(featureIQ, + function(result) { /* Callback */ + if ($(result).find("feature[var='" + Strophe.NS.ADHOC + "']").length > 0) { + getCommandNodes(elem); + } else { + $(elem).append("

      " + adhoc_status.queryJID + " does NOT support AdHoc commands

      "); + } + }, + function(result) { /* Errback */ + $(elem).append("

      Couldn't get list of supported features

      "); } - }); - $('#output').empty(); - getCommandNodes(); + ); } function showConnect() { @@ -328,15 +335,14 @@ $(document).ready(function () { }); $('#queryForm').bind('submit', function (event) { - queryJID = $('#queryJID').val(); - checkFeatures(); + adhoc_status.queryJID = $('#queryJID').val(); + checkFeatures("#output"); event.preventDefault(); }); }); -onunload = function() { +window.onunload = window.onbeforeunload = function() { if (connection) { connection.disconnect(); } } -