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;
|
2014-09-25 11:45:46 +02:00
|
|
|
var globals;
|
2014-09-24 23:24:51 +02:00
|
|
|
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');
|
2014-09-11 13:59:12 +02:00
|
|
|
topNavigationPresenter.changeTitle('Home');
|
2014-09-24 23:24:51 +02:00
|
|
|
|
|
|
|
promise.waitAll(
|
|
|
|
util.promiseTemplate('home'),
|
|
|
|
util.promiseTemplate('post-content'),
|
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(
|
|
|
|
homeTemplateHtml,
|
|
|
|
postContentTemplateHtml,
|
2014-09-25 11:45:46 +02:00
|
|
|
globalsResponse,
|
|
|
|
featuredPostResponse) {
|
2014-09-24 23:24:51 +02:00
|
|
|
homeTemplate = _.template(homeTemplateHtml);
|
|
|
|
postContentTemplate = _.template(postContentTemplateHtml);
|
|
|
|
|
2014-09-25 11:45:46 +02:00
|
|
|
globals = globalsResponse.json;
|
|
|
|
post = featuredPostResponse.json;
|
2014-09-24 23:24:51 +02:00
|
|
|
render();
|
|
|
|
loaded();
|
|
|
|
|
|
|
|
}).fail(function(response) {
|
|
|
|
messagePresenter.showError($el, response.json && response.json.error || response);
|
2014-09-27 10:31:12 +02:00
|
|
|
loaded();
|
2014-09-24 23:24:51 +02:00
|
|
|
});
|
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,
|
2014-09-25 11:45:46 +02:00
|
|
|
globals: globals,
|
2014-09-24 23:24:51 +02:00
|
|
|
title: topNavigationPresenter.getBaseTitle(),
|
|
|
|
formatRelativeTime: util.formatRelativeTime,
|
2014-09-25 11:45:46 +02:00
|
|
|
formatFileSize: util.formatFileSize,
|
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-09-24 23:24:51 +02:00
|
|
|
App.DI.register('homePresenter', ['_', 'jQuery', 'util', 'promise', 'api', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.HomePresenter);
|