diff options
| -rw-r--r-- | webclient/lib/alias.js | 76 | ||||
| -rw-r--r-- | webclient/style/alias.css | 6 | ||||
| -rw-r--r-- | webclient/style/dialog.css | 3 |
3 files changed, 75 insertions, 10 deletions
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 = $('<form></form>'); + + if ( form.find('title').length !== 0 ){ + result.append('<p class="title">' + form.find('title') + '</p>'); + } + + if ( form.find('instructions').length !== 0 ){ + result.append('<p class="instructions">' + + form.find('instructions') + '</p>'); + } + + 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('<p class="description">' + + $(this).find('desc').text() + + '</p>'); + } + + if ( $(this).attr('label') !== undefined ){ + result.append('<label for="form-' + name + '">' + + $(this).attr('label') + + (required ? ' (*): ' : ': ') + + '</label>'); + } + + switch(type){ + case("text-single"): + var input = $('<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('<br/>'); + } + }); + 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('<p>' + instructions.text() + '</p>'); + } + 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(); diff --git a/webclient/style/alias.css b/webclient/style/alias.css index c3945ba..b925e39 100644 --- a/webclient/style/alias.css +++ b/webclient/style/alias.css @@ -47,6 +47,12 @@ div font-style: italic; } +#register label{ + display: block; + float: left; + width: 150px; +} + input { border: 1px solid black; diff --git a/webclient/style/dialog.css b/webclient/style/dialog.css index ea9266e..5fbc208 100644 --- a/webclient/style/dialog.css +++ b/webclient/style/dialog.css @@ -11,5 +11,6 @@ display:none; z-index:9999; padding:5px; - background-color: red; + border: 1px solid #727272; + background-color: #F5F5F5; }
\ No newline at end of file |
