szurubooru/client/js/views/registration_view.js

41 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 10:35:38 +02:00
render(ctx) {
const target = document.getElementById('content-holder');
2016-04-08 10:35:38 +02:00
const source = this.template();
2016-04-08 10:35:38 +02: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 19:03:49 +02:00
views.decorateValidator(form);
2016-04-06 20:38:45 +02:00
userNameField.setAttribute('pattern', config.userNameRegex);
passwordField.setAttribute('pattern', config.passwordRegex);
form.addEventListener('submit', e => {
e.preventDefault();
views.clearMessages(target);
views.disableForm(form);
2016-04-08 10:35:38 +02:00
ctx.register(
userNameField.value,
passwordField.value,
emailField.value)
.always(() => { views.enableForm(form); });
});
2016-04-08 10:35:38 +02:00
views.listenToMessages(target);
views.showView(target, source);
}
}
module.exports = RegistrationView;