X-Git-Url: http://cgit.babelmonkeys.de/?p=adhocweb.git;a=blobdiff_plain;f=js%2Fmain.js;h=188dfc762eda4af93e1ac45659c9671bf8046d5f;hp=52e6296a5c54908a740595d00a36e3712faa3c6f;hb=e3f2eb03a5f4dc014e034cdfc65a572544421336;hpb=0a815dbe7d2fac797c905149988ac5e540b663bc
diff --git a/js/main.js b/js/main.js
index 52e6296..188dfc7 100644
--- a/js/main.js
+++ b/js/main.js
@@ -1,5 +1,5 @@
var BOSH_SERVICE = 'http://localhost:5280/http-bind/';
-var show_log = false;
+var show_log = true;
Strophe.addNamespace("ADHOC", "http://jabber.org/protocol/commands");
@@ -51,6 +51,7 @@ function addNote(elem, text, type) {
if (!type) {
type = "info";
}
+ text = text.replace(/\n/g, "
");
$(elem).append("
" + text + "
"); } @@ -87,7 +88,7 @@ function addForm(elem, x) { item = $("").attr("readonly",true); break; case "jid-multi": - item = $(""); + item = $(""); break; case "jid-single": item = $(""); @@ -142,7 +143,7 @@ function addForm(elem, x) { } function serializeToDataform(form, st) { - st.c("x", {"xmlns":"jabber:x:data", "type": "submit"}); + st.c("x", {"xmlns": "jabber:x:data", "type": "submit"}); $(form).find(".df-item").each(function(){ st.c("field", {"var": $(this).attr("name")}); if (this.nodeName.toLowerCase() == "select" && this.multiple) { @@ -197,12 +198,24 @@ function displayResult(result) { }); $('#cancelButton').bind("click", function() { - var cancelIQ = $iq({ type: "set", to: queryJID, id: connection.getUniqueId() }) - .c("command", { xmlns: Strophe.NS.ADHOC, node: cmdNode, sessionid: sessionid, action: "cancel" }); - cmdNode = null - sessionid = null; - connection.sendIQ(cancelIQ, displayResult); + cancelCommand(displayResult); }); + + $('#queryForm').unbind('submit'); + $('#queryForm').bind('submit', function (event) { + cancelCommand(function(result) { + $('#queryForm').unbind('submit'); + $('#queryForm').bind('submit', function (event) { + queryJID = $('#queryJID').val(); + checkFeatures(); + event.preventDefault(); + }); + }); + queryJID = $('#queryJID').val(); + checkFeatures(); + event.preventDefault(); + }); + } else { input = $("").bind("click", function() { $('#output').empty(); @@ -225,6 +238,14 @@ function runCommand(event) { event.preventDefault(); } +function cancelCommand(callback) { + var cancelIQ = $iq({ type: "set", to: queryJID, id: connection.getUniqueId() }) + .c("command", { xmlns: Strophe.NS.ADHOC, node: cmdNode, sessionid: sessionid, action: "cancel" }); + cmdNode = null + sessionid = null; + connection.sendIQ(cancelIQ, callback); +} + function getCommandNodes() { var nodesIQ = $iq({ type: "get", to: queryJID, id: "nodes1" }).c("query", {xmlns: Strophe.NS.DISCO_ITEMS, node: Strophe.NS.ADHOC}); connection.sendIQ(nodesIQ, function(result) { @@ -239,15 +260,20 @@ function getCommandNodes() { 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
"); - } - }); $('#output').empty(); - getCommandNodes(); + connection.sendIQ(featureIQ, + function(result) { /* Callback */ + if ($(result).find("feature[var='" + Strophe.NS.ADHOC + "']").length > 0) { + $('#output').append("This entitiy does support AdHoc commands
"); + getCommandNodes(); + } else { + $('#output').append("This entitiy does NOT support AdHoc commands
"); + } + }, + function(result) { /* Errback */ + $('#output').append("Couldn't get list of supported features
"); + } + ); } function showConnect() { @@ -303,19 +329,18 @@ $(document).ready(function () { } else { connection.disconnect(); } - event.preventDefault(); + event.preventDefault(); }); $('#queryForm').bind('submit', function (event) { queryJID = $('#queryJID').val(); checkFeatures(); - event.preventDefault(); + event.preventDefault(); }); }); -onunload = function() { +window.onunload = window.onbeforeunload = function() { if (connection) { connection.disconnect(); } } -