2014-08-31 23:22:56 +02:00
|
|
|
var App = App || {};
|
|
|
|
App.Presenters = App.Presenters || {};
|
|
|
|
|
2014-09-04 19:06:12 +02:00
|
|
|
App.Presenters.TopNavigationPresenter = function(
|
2014-09-08 22:02:28 +02:00
|
|
|
_,
|
2014-09-04 19:06:12 +02:00
|
|
|
jQuery,
|
|
|
|
util,
|
|
|
|
promise,
|
2014-09-05 13:50:19 +02:00
|
|
|
auth) {
|
2014-08-31 23:22:56 +02:00
|
|
|
|
|
|
|
var selectedElement = null;
|
2014-09-02 23:07:50 +02:00
|
|
|
var $el = jQuery('#top-navigation');
|
2014-09-02 09:36:42 +02:00
|
|
|
var template;
|
|
|
|
|
2014-09-02 23:07:50 +02:00
|
|
|
function init() {
|
2014-09-04 18:06:25 +02:00
|
|
|
promise.wait(util.promiseTemplate('top-navigation')).then(function(html) {
|
2014-09-03 09:10:26 +02:00
|
|
|
template = _.template(html);
|
|
|
|
render();
|
2014-09-05 13:50:19 +02:00
|
|
|
auth.startObservingLoginChanges('top-navigation', loginStateChanged);
|
2014-09-03 09:10:26 +02:00
|
|
|
});
|
2014-09-02 23:07:50 +02:00
|
|
|
}
|
2014-08-31 23:22:56 +02:00
|
|
|
|
|
|
|
function select(newSelectedElement) {
|
|
|
|
selectedElement = newSelectedElement;
|
|
|
|
$el.find('li').removeClass('active');
|
|
|
|
$el.find('li.' + selectedElement).addClass('active');
|
2014-09-08 22:02:28 +02:00
|
|
|
}
|
2014-08-31 23:22:56 +02:00
|
|
|
|
2014-09-02 23:07:50 +02:00
|
|
|
function loginStateChanged() {
|
|
|
|
render();
|
|
|
|
}
|
|
|
|
|
2014-08-31 23:22:56 +02:00
|
|
|
function render() {
|
2014-09-03 09:10:26 +02:00
|
|
|
$el.html(template({
|
2014-09-05 13:50:19 +02:00
|
|
|
loggedIn: auth.isLoggedIn(),
|
|
|
|
user: auth.getCurrentUser(),
|
2014-09-07 19:49:11 +02:00
|
|
|
canListUsers: auth.hasPrivilege(auth.privileges.listUsers),
|
|
|
|
canListPosts: auth.hasPrivilege(auth.privileges.listSafePosts) ||
|
|
|
|
auth.hasPrivilege(auth.privileges.listSketchyPosts) ||
|
|
|
|
auth.hasPrivilege(auth.privileges.listUnsafePosts),
|
|
|
|
canListTags: auth.hasPrivilege(auth.privileges.listTags),
|
|
|
|
canUploadPosts: auth.hasPrivilege(auth.privileges.uploadPosts),
|
2014-09-03 09:10:26 +02:00
|
|
|
}));
|
2014-08-31 23:22:56 +02:00
|
|
|
$el.find('li.' + selectedElement).addClass('active');
|
2014-09-08 22:02:28 +02:00
|
|
|
}
|
2014-08-31 23:22:56 +02:00
|
|
|
|
|
|
|
return {
|
2014-09-03 09:10:26 +02:00
|
|
|
init: init,
|
2014-08-31 23:22:56 +02:00
|
|
|
render: render,
|
|
|
|
select: select,
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-09-04 19:02:40 +02:00
|
|
|
App.DI.registerSingleton('topNavigationPresenter', App.Presenters.TopNavigationPresenter);
|