17:d0dc83ebbf95
Anton Shestakov <av6@dwimlabs.net>, Sun, 20 Mar 2016 11:53:21 +0800
config: add config.js as a way to override values in Tram namespace

next change 18:be40f584efc1
previous change 15:52b632342209

js/register.js

Permissions: -rw-r--r--

Other formats: Feeds:
// Generated by CoffeeScript 1.10.0
(function() {
var conn, onConnect, savevCard;
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:', conn.jid);
return R.trigger('v/start');
case Strophe.Status.REGISTER:
console.debug('Got registration prompt');
return R.trigger('r/start');
case Strophe.Status.REGISTERED:
console.debug('Registered!');
R.trigger('r/done');
return conn.authenticate();
case Strophe.Status.CONFLICT:
console.debug('Contact already exists!');
return R.trigger('r/conflict');
case Strophe.Status.NOTACCEPTABLE:
console.debug('Registration form not properly filled out.');
return R.trigger('r/failed');
case Strophe.Status.REGIFAIL:
console.debug('The Server does not support In-Band Registration');
return R.trigger('r/closed');
}
};
savevCard = function(data) {
var $vcard, b, bi, binval, bl, d, dl, failcb, okcb, type;
$vcard = $iq({
type: 'set'
}).c('vCard', {
xmlns: Strophe.NS.VCARD
});
if (data.nickname) {
$vcard.c('NICKNAME').t(data.nickname).up();
}
if (data.fullname) {
$vcard.c('FN').t(data.fullname).up();
}
if (data.avatar) {
b = ';base64,';
d = 'data:';
dl = d.length;
bl = b.length;
bi = data.avatar.indexOf(b);
type = data.avatar.substr(dl, bi - dl);
binval = data.avatar.substr(bi + bl);
$vcard.c('PHOTO').c('TYPE').t(type).up().c('BINVAL').t(binval);
}
okcb = function() {
console.debug('vcard is set!', arguments);
return R.trigger('v/done');
};
failcb = function() {
console.warn('vcard is NOT set!', arguments);
return R.trigger('v/failed');
};
return conn.sendIQ($vcard.tree(), okcb, failcb);
};
window.R = _.clone(Backbone.Events);
_(R).extend({
register: function(username, password) {
conn.register.fields.username = username;
conn.register.fields.password = password;
return conn.register.submit();
},
savevCard: savevCard
});
conn = new Strophe.Connection("https://" + Tram.config.host + "/http-bind");
conn.register.connect(Tram.config.domain, onConnect);
$('#register').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 R.register($('#username').val().trim(), $('#password1').val());
}
});
$('#save').on('click', function() {
var file, reader;
file = $('#avatar').get(0).files[0];
if (file) {
reader = new FileReader();
reader.onloadend = function() {
return R.savevCard({
fullname: $('#fullname').val(),
nickname: $('#nickname').val(),
avatar: this.result
});
};
return reader.readAsDataURL(file);
} else {
return R.savevCard({
fullname: $('#fullname').val(),
nickname: $('#nickname').val()
});
}
});
R.on('r/start', function() {
return $('[data-step="registration"]').removeClass('uk-hidden');
});
R.on('r/done', function() {
return $('[data-step="registration"]').addClass('uk-hidden');
});
R.on('r/closed', function() {
return $('[data-msg="r/closed"]').removeClass('uk-hidden');
});
R.on('r/conflict', function() {
return Tram.validation.setError($('#username'), 'A user with this username already exists.');
});
R.on('r/failed', function() {
return $('[data-msg="r/failed"]').removeClass('uk-hidden');
});
R.on('v/start', function() {
$('#nickname').val($('#username').val());
return $('[data-step="vcard"]').removeClass('uk-hidden');
});
R.on('v/done', function() {
$('[data-step="vcard"]').addClass('uk-hidden');
return location.href = '/';
});
R.on('v/failed', function() {
return $('[data-msg="v/failed"]').removeClass('uk-hidden');
});
}).call(this);
//# sourceMappingURL=register.js.map