103:0b0540f08404
Anton Shestakov <av6@dwimlabs.net>, Wed, 06 Apr 2016 22:06:08 +0800
index: receiving an incoming chat message

next change 118:f7022798c64a
previous change 46:e3696f4866fc

js/register.js

Permissions: -rw-r--r--

Other formats: Feeds:
// Generated by CoffeeScript 1.10.0
(function() {
var ProfileData, RegistrationData, registerfn, savefn,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
RegistrationData = (function(superClass) {
extend(RegistrationData, superClass);
function RegistrationData() {
return RegistrationData.__super__.constructor.apply(this, arguments);
}
RegistrationData.prototype.defaults = {
username: '',
password1: '',
password2: ''
};
RegistrationData.prototype.validate = function(attrs, options) {
var ref, ref1, ref2, ref3, ref4;
this.unset('username-errors');
this.unset('password1-errors');
this.unset('password2-errors');
if (((ref = attrs.username) != null ? ref : '').trim() === '') {
this.set('username-errors', ['This field is required.']);
}
if (((ref1 = attrs.password1) != null ? ref1 : '') === '') {
this.set('password1-errors', ['This field is required.']);
}
if (((ref2 = attrs.password1) != null ? ref2 : '') !== ((ref3 = attrs.password2) != null ? ref3 : '')) {
this.set('password2-errors', ['Passwords must match.']);
} else if (((ref4 = attrs.password2) != null ? ref4 : '') === '') {
this.set('password2-errors', ['This field is required.']);
}
return this.has('username-errors') || this.has('password1-errors') || this.has('password2-errors');
};
return RegistrationData;
})(Backbone.Model);
ProfileData = (function(superClass) {
extend(ProfileData, superClass);
function ProfileData() {
return ProfileData.__super__.constructor.apply(this, arguments);
}
ProfileData.prototype.defaults = {
fullname: '',
nickname: '',
avatar: ''
};
return ProfileData;
})(Backbone.Model);
window.regData = new RegistrationData();
window.vcData = new ProfileData();
registerfn = function() {
if (regData.isValid()) {
return X.register(regData.get('username').trim(), regData.get('password1'));
}
};
savefn = function() {
var data, failcb, file, okcb, reader;
data = {
fullname: vcData.get('fullname').trim(),
nickname: vcData.get('nickname').trim()
};
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 != null) {
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);
}
};
window.regRivet = rivets.bind($('[data-form="registration"]'), {
data: regData,
register: registerfn
});
window.vcRivet = rivets.bind($('[data-form="vcard"]'), {
data: vcData,
save: savefn
});
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 regData.set('username-errors', ['A user with this username already exists.']);
});
X.on('notacceptable', function() {
return $('[data-msg="registration-failed"]').removeClass('uk-hidden');
});
X.on('connected', function() {
vcData.set('nickname', regData.get('username').trim());
$('[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');
}
}
});
});
}).call(this);
//# sourceMappingURL=register.js.map