gallery.accords-library.com/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 17:03:49 +00: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-27 22:19:44 +00:00
render(options) {
this.showView(this.template());
2016-04-07 17:03:49 +00: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 18:38:45 +00:00
userNameField.setAttribute('pattern', config.userNameRegex);
passwordField.setAttribute('pattern', config.passwordRegex);
form.addEventListener('submit', e => {
e.preventDefault();
2016-03-31 20:33:49 +00:00
this.clearMessages();
2016-04-06 13:11:20 +00:00
this.disableForm(form);
options
.register(
userNameField.value,
passwordField.value,
emailField.value)
.then(() => {
2016-04-06 13:11:20 +00:00
this.enableForm(form);
})
.catch(errorMessage => {
2016-04-06 13:11:20 +00:00
this.enableForm(form);
2016-04-07 17:03:49 +00:00
events.notify(events.Error, errorMessage);
});
});
}
}
module.exports = RegistrationView;