szurubooru/client/js/views/registration_view.js
rr- 69fe8ec31a client/general: refactor all the things
- Move controls to the "controls/" directory
- Make controls interface look similar to each other
- Prefix "private" methods and attributes with underscore
2016-05-21 00:08:43 +02:00

41 lines
1.2 KiB
JavaScript

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