2014-08-31 23:22:56 +02:00
|
|
|
var App = App || {};
|
|
|
|
App.Presenters = App.Presenters || {};
|
|
|
|
|
2014-09-02 09:36:42 +02:00
|
|
|
App.Presenters.TopNavigationPresenter = function(util, jQuery, appState) {
|
2014-08-31 23:22:56 +02:00
|
|
|
|
|
|
|
var selectedElement = null;
|
2014-09-02 09:36:42 +02:00
|
|
|
var template;
|
|
|
|
|
|
|
|
util.loadTemplate('top-navigation').then(function(html) {
|
|
|
|
template = _.template(html);
|
|
|
|
render();
|
|
|
|
});
|
2014-08-31 23:22:56 +02:00
|
|
|
var $el = jQuery('#top-navigation');
|
|
|
|
|
|
|
|
var eventHandlers = {
|
|
|
|
loginStateChanged: function() {
|
|
|
|
render();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
appState.startObserving('loggedIn', 'top-navigation', eventHandlers.loginStateChanged);
|
|
|
|
|
|
|
|
function select(newSelectedElement) {
|
|
|
|
selectedElement = newSelectedElement;
|
|
|
|
$el.find('li').removeClass('active');
|
|
|
|
$el.find('li.' + selectedElement).addClass('active');
|
|
|
|
};
|
|
|
|
|
|
|
|
function render() {
|
|
|
|
$el.html(template({loggedIn: appState.get('loggedIn')}));
|
|
|
|
$el.find('li.' + selectedElement).addClass('active');
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
render: render,
|
|
|
|
select: select,
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
App.DI.register('topNavigationPresenter', App.Presenters.TopNavigationPresenter);
|