24:04329aa80b7a
Anton Shestakov <av6@dwimlabs.net>, Mon, 21 Mar 2016 19:57:24 +0800
messages: new ui element and related things

next change 46:e3696f4866fc
previous change 21:e43ed046f909

js/register.js

Permissions: -rw-r--r--

Other formats: Feeds:
// Generated by CoffeeScript 1.10.0
(function() {
window.X = new Tram.XMPPInterface();
X.on('register', function() {
return $('[data-step="registration"]').removeClass('uk-hidden');
});
X.on('registered', function() {
X.finishRegistration();
return $('[data-step="registration"]').addClass('uk-hidden');
});
X.on('regifail', function() {
return $('[data-msg="registration-closed"]').removeClass('uk-hidden');
});
X.on('conflict', function() {
return Tram.validation.setError($('#username'), 'A user with this username already exists.');
});
X.on('notacceptable', function() {
return $('[data-msg="registration-failed"]').removeClass('uk-hidden');
});
X.on('connected', function() {
$('#nickname').val($('#username').val());
$('[data-step="vcard"]').removeClass('uk-hidden');
return $('#fullname').focus();
});
X.startRegistration();
$('[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 data, failcb, file, okcb, reader;
data = {
fullname: $('#fullname').val(),
nickname: $('#nickname').val()
};
okcb = function() {
console.debug('vcard is set!', arguments);
$('[data-step="vcard"]').addClass('uk-hidden');
return location.href = '/';
};
failcb = function() {
console.warn('vcard is NOT set!', arguments);
return $('[data-msg="save-failed"]').removeClass('uk-hidden');
};
file = $('#avatar').get(0).files[0];
if (file) {
reader = new FileReader();
reader.onloadend = function() {
_(data).extend({
avatar: reader.result
});
return X.savevCard(data, okcb, failcb);
};
return reader.readAsDataURL(file);
} else {
return X.savevCard(data, okcb, failcb);
}
});
}).call(this);
//# sourceMappingURL=register.js.map