gallery.accords-library.com/client/js/views/registration_view.js

42 lines
1.2 KiB
JavaScript
Raw Normal View History

'use strict';
const config = require('../config.js');
const views = require('../util/views.js');
class RegistrationView {
constructor() {
this.template = views.getTemplate('user-registration');
}
2016-04-08 08:35:38 +00:00
render(ctx) {
ctx.userNamePattern = config.userNameRegex;
ctx.passwordPattern = config.passwordRegex;
const target = document.getElementById('content-holder');
const source = this.template(ctx);
2016-04-08 08:35:38 +00:00
const form = source.querySelector('form');
const userNameField = source.querySelector('#user-name');
const passwordField = source.querySelector('#user-password');
const emailField = source.querySelector('#user-email');
2016-04-07 17:03:49 +00:00
views.decorateValidator(form);
form.addEventListener('submit', e => {
e.preventDefault();
views.clearMessages(target);
views.disableForm(form);
2016-04-08 08:35:38 +00:00
ctx.register(
userNameField.value,
passwordField.value,
emailField.value)
.always(() => { views.enableForm(form); });
});
2016-04-08 08:35:38 +00:00
views.listenToMessages(target);
views.showView(target, source);
}
}
module.exports = RegistrationView;