From 53fb8167efe4100bf20df3bec5d6b844f4bf1617 Mon Sep 17 00:00:00 2001 From: Zaran Date: Wed, 18 May 2011 17:08:28 +0200 Subject: Add basic code for displaying received forms from xmpp. --- webclient/lib/alias.js | 76 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 9 deletions(-) (limited to 'webclient/lib') diff --git a/webclient/lib/alias.js b/webclient/lib/alias.js index de0d865..4adac04 100644 --- a/webclient/lib/alias.js +++ b/webclient/lib/alias.js @@ -17,28 +17,86 @@ var Alias = { */ connection: null, + form: { + render: function(form){ + var result = $('
'); + + if ( form.find('title').length !== 0 ){ + result.append('

' + form.find('title') + '

'); + } + + if ( form.find('instructions').length !== 0 ){ + result.append('

' + + form.find('instructions') + '

'); + } + + form.find('field').each(function(index){ + var type = $(this).attr("type"); + var name = $(this).attr("var"); + var required = $(this).find('required').length !== 0; + + if ( $(this).find('desc').length !== 0 ){ + result.append('

' + + $(this).find('desc').text() + + '

'); + } + + if ( $(this).attr('label') !== undefined ){ + result.append(''); + } + + switch(type){ + case("text-single"): + var input = $(''); + input.attr('type', 'text'); + input.attr('name', name); + input.attr('id', 'form-' + name); + + if ( $(this).find('value').length !== 0 ){ + input.attr('value', $(this).find('value').text()); + } + result.append(input); + result.append('
'); + } + }); + return result; + } + }, + /** - * Send initialization request to the component + * Send registration request to the component */ - getInit: function() { + getRegister: function() { var init = $iq({to: server_component, type:'get'}); init.c('query',{xmlns:'jabber:iq:register'}); - Alias.connection.sendIQ(init, Alias.onInit); + Alias.connection.sendIQ(init, Alias.onRegister); }, /** - * Receive initialization data + * Receive registration data */ - onInit: function(iq) { - - if ($(iq).find('query > registered').length() === 0){ + onRegister: function(iq) { + var form = $(iq).find('query x'); + if ($(iq).find('query > registered').length !== 0){ // user is registered, get the info from the form - var form = $(iq).find('query > x'); this.pubkey = form.find('field[var="pubkey"] > value'); this.salt = form.find('field[var="pubkey"] > value'); var privkey = form.find('field[var="pubkey"] > value'); var salt = form.find('field[var="salt"] > value'); this.privkey = sjcl.decrypt(Alias.connection.pass, privkey, {salt: salt}); + } + else{ + $('#register').empty(); + var instructions = $(iq).find('query > instructions'); + if ( instructions.length !== 0 ){ + $('#register').append('

' + instructions.text() + '

'); + } + var result = Alias.form.render(form); + $('#register').append(result); + $('#dialogs').dialog('show', 'register'); } }, @@ -237,7 +295,7 @@ var Alias = { */ onConnect: function() { Alias.getRoster(); - Alias.getInit(); + Alias.getRegister(); // hide the login dialog and load the interface $('#login').hide(); -- cgit v1.2.3-70-g09d2