18:be40f584efc1
Anton Shestakov <av6@dwimlabs.net>, Sun, 20 Mar 2016 23:30:16 +0800
register: improve scripting, move XMPP interface to a separate file

next change 20:aa1eeed14fff
previous change 15:52b632342209

js/register.js

Permissions: -rw-r--r--

Other formats: Feeds:
// Generated by CoffeeScript 1.10.0
(function() {
var onConnect;
onConnect = function(status, error) {
switch (status) {
case Strophe.Status.CONNECTING:
return console.debug('Strophe is connecting.');
case Strophe.Status.AUTHENTICATING:
return console.debug('Strophe is authenticating.');
case Strophe.Status.AUTHFAIL:
return console.debug('Strophe failed to authenticate:', error);
case Strophe.Status.ERROR:
return console.debug('Strophe received an error:', error);
case Strophe.Status.CONNFAIL:
return console.debug('Strophe failed to connect:', error);
case Strophe.Status.DISCONNECTING:
return console.debug('Strophe is disconnecting.');
case Strophe.Status.DISCONNECTED:
return console.debug('Strophe is disconnected.');
case Strophe.Status.CONNECTED:
console.debug('Strophe is connected.');
console.info('My jid:', X.conn.jid);
return X.trigger('v/start');
case Strophe.Status.REGISTER:
console.debug('Got registration prompt.');
return X.trigger('r/start');
case Strophe.Status.REGISTERED:
console.debug('Registered!');
X.trigger('r/done');
return X.conn.authenticate();
case Strophe.Status.CONFLICT:
console.debug('Contact already exists!');
return X.trigger('r/conflict');
case Strophe.Status.NOTACCEPTABLE:
console.debug('Registration form not properly filled out.');
return X.trigger('r/failed');
case Strophe.Status.REGIFAIL:
console.debug('The server does not support In-Band Registration.');
return X.trigger('r/closed');
}
};
window.X = new Tram.XMPPInterface();
X.startRegistration(onConnect);
$('[data-form="registration"], [data-form="vcard"]').each(function() {
var $form;
$form = $(this);
return $form.find('input').on('keydown', function(e) {
var $next, index;
if ((!this.required || this.value !== '') && e.keyCode === 13) {
e.preventDefault();
index = $form.find('input').index(this);
$next = $form.find('input').eq(index + 1);
if ($next.length !== 0) {
return $next.focus();
} else {
return $form.find('button').trigger('click');
}
}
});
});
$('[data-form="registration"] button').on('click', function() {
var ok;
ok = true;
Tram.validation.unsetError($('#username, #password1, #password2'));
ok &= Tram.validation.validateRequired($('#username'), true);
ok &= Tram.validation.validatePasswords($('#password1'), $('#password2'));
ok &= Tram.validation.validateRequired($('#password1'));
ok &= Tram.validation.validateRequired($('#password2'));
if (ok) {
return X.register($('#username').val().trim(), $('#password1').val());
}
});
$('[data-form="vcard"] button').on('click', function() {
var file, reader;
file = $('#avatar').get(0).files[0];
if (file) {
reader = new FileReader();
reader.onloadend = function() {
return X.savevCard({
fullname: $('#fullname').val(),
nickname: $('#nickname').val(),
avatar: this.result
});
};
return reader.readAsDataURL(file);
} else {
return X.savevCard({
fullname: $('#fullname').val(),
nickname: $('#nickname').val()
});
}
});
X.on('r/start', function() {
return $('[data-step="registration"]').removeClass('uk-hidden');
});
X.on('r/done', function() {
return $('[data-step="registration"]').addClass('uk-hidden');
});
X.on('r/closed', function() {
return $('[data-msg="r/closed"]').removeClass('uk-hidden');
});
X.on('r/conflict', function() {
return Tram.validation.setError($('#username'), 'A user with this username already exists.');
});
X.on('r/failed', function() {
return $('[data-msg="r/failed"]').removeClass('uk-hidden');
});
X.on('v/start', function() {
$('#nickname').val($('#username').val());
$('[data-step="vcard"]').removeClass('uk-hidden');
return $('#fullname').focus();
});
X.on('v/done', function() {
$('[data-step="vcard"]').addClass('uk-hidden');
return location.href = '/';
});
X.on('v/failed', function() {
return $('[data-msg="v/failed"]').removeClass('uk-hidden');
});
}).call(this);
//# sourceMappingURL=register.js.map