2016-03-19 20:37:04 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const config = require('../config.js');
|
2016-04-07 17:03:49 +00:00
|
|
|
const events = require('../events.js');
|
2016-03-19 20:37:04 +00:00
|
|
|
const BaseView = require('./base_view.js');
|
|
|
|
|
|
|
|
class RegistrationView extends BaseView {
|
2016-03-29 10:32:51 +00:00
|
|
|
constructor() {
|
|
|
|
super();
|
2016-03-19 20:37:04 +00:00
|
|
|
this.template = this.getTemplate('user-registration-template');
|
|
|
|
}
|
|
|
|
|
2016-03-27 22:19:44 +00:00
|
|
|
render(options) {
|
2016-03-19 20:37:04 +00:00
|
|
|
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);
|
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-03-31 20:33:49 +00:00
|
|
|
this.clearMessages();
|
2016-04-06 13:11:20 +00:00
|
|
|
this.disableForm(form);
|
2016-03-28 20:33:20 +00:00
|
|
|
options
|
|
|
|
.register(
|
|
|
|
userNameField.value,
|
|
|
|
passwordField.value,
|
|
|
|
emailField.value)
|
|
|
|
.then(() => {
|
2016-04-06 13:11:20 +00:00
|
|
|
this.enableForm(form);
|
2016-03-28 20:33:20 +00:00
|
|
|
})
|
|
|
|
.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);
|
2016-03-28 20:33:20 +00:00
|
|
|
});
|
2016-03-19 20:37:04 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = RegistrationView;
|