2016-03-19 20:37:04 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const config = require('../config.js');
|
2016-04-09 16:54:23 +00:00
|
|
|
const views = require('../util/views.js');
|
2016-03-19 20:37:04 +00:00
|
|
|
|
2016-04-09 16:54:23 +00:00
|
|
|
class RegistrationView {
|
2016-03-29 10:32:51 +00:00
|
|
|
constructor() {
|
2016-04-09 16:54:23 +00:00
|
|
|
this.template = views.getTemplate('user-registration');
|
2016-03-19 20:37:04 +00:00
|
|
|
}
|
|
|
|
|
2016-04-08 08:35:38 +00:00
|
|
|
render(ctx) {
|
2016-04-09 16:54:23 +00:00
|
|
|
const target = document.getElementById('content-holder');
|
2016-04-08 08:35:38 +00:00
|
|
|
const source = this.template();
|
2016-03-19 20:37:04 +00:00
|
|
|
|
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
|
|
|
|
2016-04-09 16:54:23 +00:00
|
|
|
views.decorateValidator(form);
|
2016-04-06 18:38:45 +00:00
|
|
|
userNameField.setAttribute('pattern', config.userNameRegex);
|
|
|
|
passwordField.setAttribute('pattern', config.passwordRegex);
|
2016-03-19 20:37:04 +00:00
|
|
|
|
2016-03-28 20:33:20 +00:00
|
|
|
form.addEventListener('submit', e => {
|
2016-03-19 20:37:04 +00:00
|
|
|
e.preventDefault();
|
2016-04-09 16:54:23 +00:00
|
|
|
views.clearMessages(target);
|
|
|
|
views.disableForm(form);
|
2016-04-08 08:35:38 +00:00
|
|
|
ctx.register(
|
2016-03-28 20:33:20 +00:00
|
|
|
userNameField.value,
|
|
|
|
passwordField.value,
|
|
|
|
emailField.value)
|
2016-04-09 16:54:23 +00:00
|
|
|
.always(() => { views.enableForm(form); });
|
2016-03-19 20:37:04 +00:00
|
|
|
});
|
2016-04-08 08:35:38 +00:00
|
|
|
|
2016-04-09 16:54:23 +00:00
|
|
|
views.listenToMessages(target);
|
|
|
|
views.showView(target, source);
|
2016-03-19 20:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = RegistrationView;
|