client/views: extract empty view
...so that UsersController doesn't mess with DOM.
This commit is contained in:
parent
8e525b48a6
commit
5053598a13
4 changed files with 27 additions and 17 deletions
|
@ -9,11 +9,13 @@ const views = require('../util/views.js');
|
|||
const topNavController = require('../controllers/top_nav_controller.js');
|
||||
const RegistrationView = require('../views/registration_view.js');
|
||||
const UserView = require('../views/user_view.js');
|
||||
const EmptyView = require('../views/empty_view.js');
|
||||
|
||||
class UsersController {
|
||||
constructor() {
|
||||
this.registrationView = new RegistrationView();
|
||||
this.userView = new UserView();
|
||||
this.emptyView = new EmptyView();
|
||||
}
|
||||
|
||||
registerRoutes() {
|
||||
|
@ -59,7 +61,7 @@ class UsersController {
|
|||
this.user = response.user;
|
||||
next();
|
||||
}).catch(response => {
|
||||
views.emptyView(document.getElementById('content-holder'));
|
||||
this.emptyView.render();
|
||||
events.notify(events.Error, response.description);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -84,12 +84,6 @@ function enableForm(form) {
|
|||
}
|
||||
}
|
||||
|
||||
function emptyView(target) {
|
||||
const ret = showView(target, htmlToDom('<div class="messages"></div>'));
|
||||
listenToMessages(target);
|
||||
return ret;
|
||||
}
|
||||
|
||||
function showView(target, source) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let observer = new MutationObserver(mutations => {
|
||||
|
@ -116,7 +110,6 @@ module.exports = {
|
|||
htmlToDom: htmlToDom,
|
||||
getTemplate: getTemplate,
|
||||
showView: showView,
|
||||
emptyView: emptyView,
|
||||
enableForm: enableForm,
|
||||
disableForm: disableForm,
|
||||
listenToMessages: listenToMessages,
|
||||
|
|
18
client/js/views/empty_view.js
Normal file
18
client/js/views/empty_view.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
'use strict';
|
||||
|
||||
const views = require('../util/views.js');
|
||||
|
||||
class EmptyView {
|
||||
constructor() {
|
||||
this.template = views.htmlToDom('<div class="messages"></div>');
|
||||
}
|
||||
|
||||
render(ctx) {
|
||||
const target = document.getElementById('content-holder');
|
||||
const source = this.template;
|
||||
views.listenToMessages(target);
|
||||
views.showView(target, source);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EmptyView;
|
|
@ -19,17 +19,14 @@ class HelpView {
|
|||
const source = this.template();
|
||||
|
||||
ctx.section = ctx.section || 'about';
|
||||
if (!(ctx.section in this.sectionTemplates)) {
|
||||
views.emptyView(target);
|
||||
return;
|
||||
if (ctx.section in this.sectionTemplates) {
|
||||
views.showView(
|
||||
source.querySelector('.content'),
|
||||
this.sectionTemplates[ctx.section]({
|
||||
name: config.name,
|
||||
}));
|
||||
}
|
||||
|
||||
views.showView(
|
||||
source.querySelector('.content'),
|
||||
this.sectionTemplates[ctx.section]({
|
||||
name: config.name,
|
||||
}));
|
||||
|
||||
const allItemsSelector = '[data-name]';
|
||||
for (let item of source.querySelectorAll(allItemsSelector)) {
|
||||
if (item.getAttribute('data-name') === ctx.section) {
|
||||
|
|
Loading…
Reference in a new issue