szurubooru/client/js/views/registration_view.js

46 lines
1.4 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-03-28 00:19:44 +02:00
render(options) {
this.showView(this.template());
2016-04-07 19:03:49 +02:00
const form = this.contentHolder.querySelector('form');
const userNameField = this.contentHolder.querySelector('#user-name');
const passwordField = this.contentHolder.querySelector('#user-password');
const emailField = this.contentHolder.querySelector('#user-email');
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);
options
.register(
userNameField.value,
passwordField.value,
emailField.value)
.then(() => {
2016-04-06 15:11:20 +02:00
this.enableForm(form);
})
.catch(errorMessage => {
2016-04-06 15:11:20 +02:00
this.enableForm(form);
2016-04-07 19:03:49 +02:00
events.notify(events.Error, errorMessage);
});
});
}
}
module.exports = RegistrationView;