szurubooru/public_html/js/Presenters/PostPresenter.js

58 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-09-18 17:39:51 +02:00
var App = App || {};
App.Presenters = App.Presenters || {};
App.Presenters.PostPresenter = function(
_,
jQuery,
util,
promise,
api,
topNavigationPresenter,
messagePresenter) {
var $el = jQuery('#content');
var $messages = $el;
var template;
var post;
var postNameOrId;
function init(args, loaded) {
postNameOrId = args.postNameOrId;
topNavigationPresenter.select('posts');
promise.waitAll(
util.promiseTemplate('post'),
api.get('/posts/' + postNameOrId))
.then(function(
templatehtml,
response) {
$messages = $el.find('.messages');
template = _.template(templatehtml);
post = response.json;
topNavigationPresenter.changeTitle('@' + post.id);
render();
loaded();
}).fail(function(response) {
$el.empty();
messagePresenter.showError($messages, response.json && response.json.error || response);
});
}
function render() {
$el.html(template({
post: post,
formatRelativeTime: util.formatRelativeTime,
}));
}
return {
init: init,
render: render
};
};
App.DI.register('postPresenter', ['_', 'jQuery', 'util', 'promise', 'api', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.PostPresenter);