797ace982f
Done so far Basic backend skeleton - technology choices - database migration outline - basic self hosting facade - basic REST outline - proof of concept for auth and privileges Basic frontend skeleton - technology choices - pretty robust frontend compilation - top navigation - proof of concept for registration form
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
// fix iterating over NodeList in Chrome and Opera
|
|
NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
|
|
|
|
class BaseView {
|
|
constructor(handlebars) {
|
|
this.handlebars = handlebars;
|
|
this.contentHolder = document.getElementById('content-holder');
|
|
}
|
|
|
|
getTemplate(templatePath) {
|
|
const templateElement = document.getElementById(templatePath);
|
|
if (!templateElement) {
|
|
console.log('Missing template: ' + templatePath);
|
|
return null;
|
|
}
|
|
const templateText = templateElement.innerHTML;
|
|
return this.handlebars.compile(templateText);
|
|
}
|
|
|
|
decorateValidator(form) {
|
|
// postpone showing form fields validity until user actually tries
|
|
// to submit it (seeing red/green form w/o doing anything breaks POLA)
|
|
const submitButton
|
|
= document.querySelector('#content-holder .buttons input');
|
|
submitButton.addEventListener('click', (e) => {
|
|
form.classList.add('show-validation');
|
|
});
|
|
}
|
|
|
|
showView(html) {
|
|
this.contentHolder.innerHTML = html;
|
|
}
|
|
}
|
|
|
|
module.exports = BaseView;
|