X-Git-Url: http://cgit.babelmonkeys.de/?p=adhocweb.git;a=blobdiff_plain;f=js%2Fadhoc.js;h=cbe27523ab1ab905719fa82ca2fdce232d15c503;hp=68b14c9efa073bf295435f5076492d9e68aa7c43;hb=87bfedccdb91e2ff7cfb165e989e5259c155b513;hpb=813071fb6508e35f97a9893ac7f50b11c59431d3 diff --git a/js/adhoc.js b/js/adhoc.js index 68b14c9..cbe2752 100644 --- a/js/adhoc.js +++ b/js/adhoc.js @@ -1,130 +1,149 @@ -var Adhoc = { - status: { +/* + * Implementation of ECMA Script 5 like bind from: + * https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind + */ +if (!Function.prototype.bind) { + Function.prototype.bind = function (oThis) { + if (typeof this !== "function") { + /* closest thing possible to the ECMAScript 5 internal IsCallable function */ + throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable"); + } + var fSlice = Array.prototype.slice, + aArgs = fSlice.call(arguments, 1), + fToBind = this, + fNOP = function () {}, + fBound = function () { + return fToBind.apply(this instanceof fNOP ? this : oThis || window, Args.concat(fSlice.call(arguments))); + }; + fNOP.prototype = this.prototype; + fBound.prototype = new fNOP(); + return fBound; + }; +} + +Strophe.addNamespace("ADHOC", "http://jabber.org/protocol/commands"); + +function Adhoc(view, readycb) { + this.status = { sessionid: null, cmdNode: null, - queryJID: null - }, + queryJID: null, + readycb: readycb, + view: view + }; +} + +Adhoc.prototype = { + constructor: Adhoc, - addNote: function (elem, text, type) { + addNote: function (text, type) { if (!type) { type = "info"; } text = text.replace(/\n/g, "
"); - $(elem).append("

" + text + "

"); + $(this.status.view).append("

" + text + "

"); }, - addForm: function (elem, x) { - var form = $("
"); + addForm: function (x) { + var self = this; + var form = $(""); form.submit(function(event) { - Adhoc.executeCommand("execute", Adhoc.serializeToDataform('form'), - function(e) { Adhoc.displayResult(elem, e) }); + self.executeCommand("execute", self.serializeToDataform('form'), + function(e) { self.displayResult(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("title").each(function() { $("").text($(this).text()).appendTo(fieldset); }); + $(x).find("instructions").each(function() { $("

").text($(this).text()).appendTo(fieldset); }); $(x).find("field").each(function() { - var item = null; - var type = $(this).attr("type"); - if($(this).attr("label")) { - $("