szurubooru/client/js/views/registration_view.js

42 lines
1.2 KiB
JavaScript
Raw Normal View History

'use strict';
const config = require('../config.js');
2016-04-07 19:03:49 +02:00
const events = require('../events.js');
const BaseView = require('./base_view.js');
class RegistrationView extends BaseView {
constructor() {
super();
this.template = this.getTemplate('user-registration-template');
}
2016-04-08 10:35:38 +02:00
render(ctx) {
const target = this.contentHolder;
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
this.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();
2016-03-31 22:33:49 +02:00
this.clearMessages();
2016-04-06 15:11:20 +02:00
this.disableForm(form);
2016-04-08 10:35:38 +02:00
ctx.register(
userNameField.value,
passwordField.value,
emailField.value)
.always(() => { this.enableForm(form); });
});
2016-04-08 10:35:38 +02:00
this.showView(target, source);
}
}
module.exports = RegistrationView;