szurubooru/public_html/js/Presenters/HomePresenter.js

59 lines
1.3 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(
2014-09-24 23:24:51 +02:00
_,
2014-09-07 19:49:11 +02:00
jQuery,
2014-09-24 23:24:51 +02:00
util,
promise,
api,
topNavigationPresenter,
messagePresenter) {
2014-09-07 19:49:11 +02:00
var $el = jQuery('#content');
2014-09-24 23:24:51 +02:00
var homeTemplate;
var postContentTemplate;
var post;
2014-09-07 19:49:11 +02:00
2014-09-17 22:37:49 +02:00
function init(args, loaded) {
2014-09-07 19:49:11 +02:00
topNavigationPresenter.select('home');
topNavigationPresenter.changeTitle('Home');
2014-09-24 23:24:51 +02:00
promise.waitAll(
util.promiseTemplate('home'),
util.promiseTemplate('post-content'),
api.get('/posts/featured'))
.then(function(
homeTemplateHtml,
postContentTemplateHtml,
response) {
homeTemplate = _.template(homeTemplateHtml);
postContentTemplate = _.template(postContentTemplateHtml);
post = response.json;
render();
loaded();
}).fail(function(response) {
messagePresenter.showError($el, response.json && response.json.error || response);
});
2014-09-07 19:49:11 +02:00
}
function render() {
2014-09-24 23:24:51 +02:00
$el.html(homeTemplate({
post: post,
postContentTemplate: postContentTemplate,
title: topNavigationPresenter.getBaseTitle(),
formatRelativeTime: util.formatRelativeTime,
}));
2014-09-08 22:02:28 +02:00
}
2014-09-07 19:49:11 +02:00
return {
init: init,
render: render,
};
};
2014-09-24 23:24:51 +02:00
App.DI.register('homePresenter', ['_', 'jQuery', 'util', 'promise', 'api', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.HomePresenter);