szurubooru/public_html/js/Presenters/HomePresenter.js

92 lines
2.7 KiB
JavaScript
Raw Normal View History

2014-09-07 19:49:11 +02:00
var App = App || {};
App.Presenters = App.Presenters || {};
App.Presenters.HomePresenter = function(
2015-06-28 10:07:11 +02:00
jQuery,
util,
promise,
api,
auth,
presenterManager,
postContentPresenter,
topNavigationPresenter,
messagePresenter) {
2014-09-07 19:49:11 +02:00
2015-06-28 10:07:11 +02:00
var $el = jQuery('#content');
var templates = {};
var globals;
var post;
var user;
2014-09-07 19:49:11 +02:00
2015-06-28 10:07:11 +02:00
function init(params, loaded) {
topNavigationPresenter.select('home');
topNavigationPresenter.changeTitle('Home');
2014-09-24 23:24:51 +02:00
2015-06-28 10:07:11 +02:00
promise.wait(
util.promiseTemplate('home'),
api.get('/globals'),
api.get('/posts/featured'))
.then(function(
homeTemplate,
globalsResponse,
featuredPostResponse) {
templates.home = homeTemplate;
2014-09-24 23:24:51 +02:00
2015-06-28 10:07:11 +02:00
globals = globalsResponse.json;
post = featuredPostResponse.json.post;
user = featuredPostResponse.json.user;
render();
loaded();
2014-09-24 23:24:51 +02:00
2015-06-28 10:07:11 +02:00
if ($el.find('#post-content-target').length > 0) {
presenterManager.initPresenters([
[postContentPresenter, {post: post, $target: $el.find('#post-content-target')}]],
function() {
var $wrapper = $el.find('.object-wrapper');
$wrapper.css({
maxWidth: $wrapper.attr('data-width') + 'px',
width: 'auto',
margin: '0 auto'});
postContentPresenter.updatePostNotesSize();
});
}
2014-10-22 10:42:15 +02:00
2015-06-28 10:07:11 +02:00
}).fail(function(response) {
messagePresenter.showError($el, response.json && response.json.error || response);
loaded();
});
}
2014-09-07 19:49:11 +02:00
2015-06-28 10:07:11 +02:00
function render() {
$el.html(templates.home({
post: post,
user: user,
globals: globals,
title: topNavigationPresenter.getBaseTitle(),
canViewUsers: auth.hasPrivilege(auth.privileges.viewUsers),
canViewPosts: auth.hasPrivilege(auth.privileges.viewPosts),
util: util,
version: jQuery('head').attr('data-version'),
buildTime: jQuery('head').attr('data-build-time'),
}));
}
2014-09-07 19:49:11 +02:00
2015-06-28 10:07:11 +02:00
return {
init: init,
render: render,
};
2014-09-07 19:49:11 +02:00
};
2014-10-22 10:42:15 +02:00
App.DI.register('homePresenter', [
2015-06-28 10:07:11 +02:00
'jQuery',
'util',
'promise',
'api',
'auth',
'presenterManager',
'postContentPresenter',
'topNavigationPresenter',
'messagePresenter'],
App.Presenters.HomePresenter);