X-Git-Url: http://cgit.babelmonkeys.de/?p=adhocweb.git;a=blobdiff_plain;f=js%2Fmain.js;h=73ace060a8394f96a984b32e9ba61fa9080e287c;hp=8724764fc49cb711496bb102ebd044a48c171df8;hb=61e5961e4a4db4362a2ac0d59da5929671b583cc;hpb=f4cb3215b33bff04fce978513f77aff1e621a1ff diff --git a/js/main.js b/js/main.js index 8724764..73ace06 100644 --- a/js/main.js +++ b/js/main.js @@ -1,12 +1,8 @@ var BOSH_SERVICE = 'http://localhost:5280/http-bind/'; -var show_log = false; - -Strophe.addNamespace("ADHOC", "http://jabber.org/protocol/commands"); +var show_log = true; var localJID = null; var connection = null; -var sessionid = null; -var cmdNode = null; function log(msg) { var entry = $('
').append(document.createTextNode(msg)); @@ -39,217 +35,24 @@ function onConnect(status) { } } else if (status == Strophe.Status.CONNECTED) { log('Strophe is connected.'); - checkFeatures(); - } -} - -function addNote(elem, text, type) { - if (!type) { - type = "info"; - } - $(elem).append("" + text + "
"); -} - -function addForm(elem, x) { - var form = $(""); - form.submit(function(){return false;}); - 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(){ - var item = null; - var type = $(this).attr("type"); - if($(this).attr("label")) { - $("").text($(this).attr("label")).attr("for", $(this).attr("var")).appendTo(fieldset); - } - switch(type) { - case "hidden": - item = $(""); - break; - case "boolean": - item = $(""); - break; - case "text-multi": - item = $(""); - break; - case "text-single": - item = $(""); - break; - case "fixed": - item = $("").attr("readonly",true); - break; - case "jid-multi": - item = $(""); - break; - case "jid-single": - item = $(""); - break; - case "list-multi": - item = $(""); - $(this).find("option").each(function(){ - $("").val($(this).find("value").text()).text($(this).attr("label")).appendTo(item); - }); - break; - case "list-single": - item = $(""); - $(this).find("option").each(function(){ - $("").val($(this).find("value").text()).text($(this).attr("label")).appendTo(item); - }); - break; - case "text-private": - item = $(""); - break; - default: - item = $(""); - } - item.addClass("df-item"); - if ($(this).find("value").length > 0) { - var value = null; - if ((type == "text-multi") || (type == "jid-multi")) { - value = ""; - $(this).find("value").each(function() { - value = value + $(this).text() + "\n"; - }); - item.val(value); - } else if (type == "list-multi") { - value = new Array(); - $(this).find("value").each(function() { - value[value.length] = $(this).text(); - }); - } else { - item.val($(this).find("value").text()); - } - } - if ($(this).attr("var")) { - item.attr("name", $(this).attr("var")); - item.attr("id", $(this).attr("var")); - } - fieldset.append(item); - fieldset.append("This entitiy does support AdHoc commands
"); - } else { - $('#output').append("This entitiy does NOT support AdHoc commands
"); - } - }); - getCommandNodes(); -} - function showConnect() { var jid = $('#jid'); var pass = $('#pass'); var button = $('#connect').get(0); button.value = 'connect'; + $('#query').hide(); pass.show(); jid.show(); - $('label').show(); + $('#cred label').show(); + $('#cred br').show(); $('#output').empty(); - return false; } function showDisconnect() { @@ -260,8 +63,8 @@ function showDisconnect() { button.value = 'disconnect'; pass.hide(); jid.hide(); - $('label').hide(); - return false; + $('#cred label').hide(); + $('#cred br').hide(); } $(document).ready(function () { @@ -276,7 +79,7 @@ $(document).ready(function () { $("#log").toggle(); }); - $('#cred').bind('submit', function () { + $('#cred').bind('submit', function (event) { var button = $('#connect').get(0); var jid = $('#jid'); var pass = $('#pass'); @@ -291,13 +94,17 @@ $(document).ready(function () { } else { connection.disconnect(); } - return false; + event.preventDefault(); + }); + + $('#queryForm').bind('submit', function (event) { + Adhoc.checkFeatures("#output", $('#queryJID').val()); + event.preventDefault(); }); }); -onunload = function() { +window.onunload = window.onbeforeunload = function() { if (connection) { connection.disconnect(); } } -