szurubooru/static/js/views/registration_view.js

44 lines
1.4 KiB
JavaScript
Raw Normal View History

'use strict';
const config = require('../config.js');
const BaseView = require('./base_view.js');
class RegistrationView extends BaseView {
constructor() {
super();
this.template = this.getTemplate('user-registration-template');
}
2016-03-28 00:19:44 +02:00
render(options) {
this.showView(this.template());
const form = document.querySelector('#content-holder form');
this.decorateValidator(form);
const userNameField = document.getElementById('user-name');
const passwordField = document.getElementById('user-password');
const emailField = document.getElementById('user-email');
userNameField.setAttribute('pattern', config.service.userNameRegex);
passwordField.setAttribute('pattern', config.service.passwordRegex);
form.addEventListener('submit', e => {
e.preventDefault();
2016-03-31 22:33:49 +02:00
this.clearMessages();
form.setAttribute('disabled', true);
options
.register(
userNameField.value,
passwordField.value,
emailField.value)
.then(() => {
form.setAttribute('disabled', false);
})
.catch(errorMessage => {
form.setAttribute('disabled', false);
2016-03-31 22:33:49 +02:00
this.notifyError(errorMessage);
});
});
}
}
module.exports = RegistrationView;