szurubooru/public_html/js/Presenters/HomePresenter.js

81 lines
1.8 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(
jQuery,
2014-09-24 23:24:51 +02:00
util,
promise,
api,
2014-09-30 22:09:43 +02:00
auth,
2014-10-22 10:42:15 +02:00
presenterManager,
postContentPresenter,
2014-09-24 23:24:51 +02:00
topNavigationPresenter,
messagePresenter) {
2014-09-07 19:49:11 +02:00
var $el = jQuery('#content');
2014-10-05 10:41:12 +02:00
var templates = {};
2014-09-25 11:45:46 +02:00
var globals;
2014-10-05 10:41:12 +02:00
var post;
2014-09-07 19:49:11 +02:00
function init(params, loaded) {
2014-09-07 19:49:11 +02:00
topNavigationPresenter.select('home');
topNavigationPresenter.changeTitle('Home');
2014-09-24 23:24:51 +02:00
2014-10-02 00:30:25 +02:00
promise.wait(
2014-09-24 23:24:51 +02:00
util.promiseTemplate('home'),
2014-09-25 11:45:46 +02:00
api.get('/globals'),
2014-09-24 23:24:51 +02:00
api.get('/posts/featured'))
.then(function(
2014-10-05 10:41:12 +02:00
homeTemplate,
2014-09-25 11:45:46 +02:00
globalsResponse,
featuredPostResponse) {
2014-10-05 10:41:12 +02:00
templates.home = homeTemplate;
2014-09-24 23:24:51 +02:00
2014-09-25 11:45:46 +02:00
globals = globalsResponse.json;
post = featuredPostResponse.json.id ? featuredPostResponse.json : null;
2014-09-24 23:24:51 +02:00
render();
loaded();
2014-10-22 10:42:15 +02:00
presenterManager.initPresenters([
[postContentPresenter, {post: post, $target: $el.find('#post-content-target')}]],
function() {});
2014-09-24 23:24:51 +02:00
}).fail(function(response) {
messagePresenter.showError($el, response.json && response.json.error || response);
loaded();
2014-09-24 23:24:51 +02:00
});
2014-09-07 19:49:11 +02:00
}
function render() {
2014-10-05 10:41:12 +02:00
$el.html(templates.home({
2014-09-24 23:24:51 +02:00
post: post,
2014-09-25 11:45:46 +02:00
globals: globals,
2014-09-24 23:24:51 +02:00
title: topNavigationPresenter.getBaseTitle(),
2014-09-30 22:09:43 +02:00
canViewUsers: auth.hasPrivilege(auth.privileges.viewUsers),
canViewPosts: auth.hasPrivilege(auth.privileges.viewPosts),
2014-09-24 23:24:51 +02:00
formatRelativeTime: util.formatRelativeTime,
2014-09-25 11:45:46 +02:00
formatFileSize: util.formatFileSize,
version: jQuery('head').attr('data-version'),
buildTime: jQuery('head').attr('data-build-time'),
2014-09-24 23:24:51 +02:00
}));
2014-09-08 22:02:28 +02:00
}
2014-09-07 19:49:11 +02:00
return {
init: init,
render: render,
};
};
2014-10-22 10:42:15 +02:00
App.DI.register('homePresenter', [
'jQuery',
'util',
'promise',
'api',
'auth',
'presenterManager',
'postContentPresenter',
'topNavigationPresenter',
'messagePresenter'],
App.Presenters.HomePresenter);