aboutsummaryrefslogtreecommitdiffstats
path: root/webclient/lib/alias.js
diff options
context:
space:
mode:
Diffstat (limited to 'webclient/lib/alias.js')
-rw-r--r--webclient/lib/alias.js76
1 files changed, 67 insertions, 9 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();