diff options
| author | rr- | 2016-06-14 10:31:48 +0200 |
|---|---|---|
| committer | rr- | 2016-06-18 10:35:20 +0200 |
| commit | 54e3099c5696e0b4fc7b05fb5ecc41ab4726628b (patch) | |
| tree | 29127e1c3d3d3d9bebfccefdf148da7305e2d5b3 /client/js/controllers/top_navigation_controller.js | |
| parent | c74f06da35af3c35d565a3c96e3d048f7a1ec011 (diff) | |
client/general: refactor control flow
- Controller lifetime is bound to route lifetime
- View lifetime is bound to controller lifetime
- Control lifetime is bound to view lifetime
- Enhanced event dispatching
- Enhanced responsiveness in some places
- Views communicate user input to controllers via new event system
Diffstat (limited to 'client/js/controllers/top_navigation_controller.js')
| -rw-r--r-- | client/js/controllers/top_navigation_controller.js | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/client/js/controllers/top_navigation_controller.js b/client/js/controllers/top_navigation_controller.js index 6b0d47f..85fa76c 100644 --- a/client/js/controllers/top_navigation_controller.js +++ b/client/js/controllers/top_navigation_controller.js @@ -1,70 +1,68 @@ 'use strict'; const api = require('../api.js'); -const events = require('../events.js'); +const topNavigation = require('../models/top_navigation.js'); const TopNavigationView = require('../views/top_navigation_view.js'); -const TopNavigation = require('../models/top_navigation.js'); class TopNavigationController { constructor() { this._topNavigationView = new TopNavigationView(); - TopNavigation.addEventListener( + topNavigation.addEventListener( 'activate', e => this._evtActivate(e)); - events.listen( - events.Authentication, - () => { - this._render(); - return true; - }); + api.addEventListener('login', e => this._evtAuthChange(e)); + api.addEventListener('logout', e => this._evtAuthChange(e)); this._render(); } + _evtAuthChange(e) { + this._render(); + } + _evtActivate(e) { this._topNavigationView.activate(e.key); } _updateNavigationFromPrivileges() { - TopNavigation.get('account').url = '/user/' + api.userName; - TopNavigation.get('account').imageUrl = + topNavigation.get('account').url = '/user/' + api.userName; + topNavigation.get('account').imageUrl = api.user ? api.user.avatarUrl : null; - TopNavigation.showAll(); + topNavigation.showAll(); if (!api.hasPrivilege('posts:list')) { - TopNavigation.hide('posts'); + topNavigation.hide('posts'); } if (!api.hasPrivilege('posts:create')) { - TopNavigation.hide('upload'); + topNavigation.hide('upload'); } if (!api.hasPrivilege('comments:list')) { - TopNavigation.hide('comments'); + topNavigation.hide('comments'); } if (!api.hasPrivilege('tags:list')) { - TopNavigation.hide('tags'); + topNavigation.hide('tags'); } if (!api.hasPrivilege('users:list')) { - TopNavigation.hide('users'); + topNavigation.hide('users'); } if (api.isLoggedIn()) { - TopNavigation.hide('register'); - TopNavigation.hide('login'); + topNavigation.hide('register'); + topNavigation.hide('login'); } else { - TopNavigation.hide('account'); - TopNavigation.hide('logout'); + topNavigation.hide('account'); + topNavigation.hide('logout'); } } _render() { this._updateNavigationFromPrivileges(); - console.log(TopNavigation.getAll()); this._topNavigationView.render({ - items: TopNavigation.getAll(), + items: topNavigation.getAll(), }); this._topNavigationView.activate( - TopNavigation.activeItem ? TopNavigation.activeItem.key : ''); - }; + topNavigation.activeItem ? topNavigation.activeItem.key : ''); + } } module.exports = new TopNavigationController(); |