2014-10-22 10:42:15 +02:00
|
|
|
var App = App || {};
|
|
|
|
App.Presenters = App.Presenters || {};
|
|
|
|
|
|
|
|
App.Presenters.PostContentPresenter = function(
|
2014-10-26 12:39:55 +01:00
|
|
|
jQuery,
|
2014-10-22 10:42:15 +02:00
|
|
|
util,
|
2014-10-25 15:02:46 +02:00
|
|
|
promise,
|
|
|
|
presenterManager,
|
|
|
|
postNotesPresenter) {
|
2014-10-22 10:42:15 +02:00
|
|
|
|
|
|
|
var post;
|
|
|
|
var templates = {};
|
|
|
|
var $target;
|
|
|
|
|
|
|
|
function init(params, loaded) {
|
|
|
|
$target = params.$target;
|
|
|
|
post = params.post;
|
|
|
|
|
|
|
|
promise.wait(util.promiseTemplate('post-content'))
|
|
|
|
.then(function(postContentTemplate) {
|
|
|
|
templates.postContent = postContentTemplate;
|
|
|
|
render();
|
|
|
|
loaded();
|
|
|
|
}).fail(function() {
|
|
|
|
console.log(arguments);
|
|
|
|
loaded();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function render() {
|
|
|
|
$target.html(templates.postContent({post: post}));
|
2014-10-25 17:45:01 +02:00
|
|
|
|
|
|
|
if (post.contentType === 'image') {
|
|
|
|
loadPostNotes();
|
2014-10-26 12:39:55 +01:00
|
|
|
updatePostNotesSize();
|
2014-10-25 17:45:01 +02:00
|
|
|
}
|
2014-10-26 12:39:55 +01:00
|
|
|
|
|
|
|
jQuery(window).resize(updatePostNotesSize);
|
2014-10-25 17:45:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadPostNotes() {
|
|
|
|
presenterManager.initPresenters([
|
|
|
|
[postNotesPresenter, {post: post, notes: post.notes, $target: $target.find('.post-notes-target')}]],
|
|
|
|
function() {});
|
2014-10-22 10:42:15 +02:00
|
|
|
}
|
|
|
|
|
2014-10-26 12:39:55 +01:00
|
|
|
function updatePostNotesSize() {
|
|
|
|
$target.find('.post-notes-target').width($target.find('.image-wrapper').outerWidth());
|
|
|
|
$target.find('.post-notes-target').height($target.find('.image-wrapper').outerHeight());
|
|
|
|
}
|
|
|
|
|
2014-10-26 01:01:16 +02:00
|
|
|
function addNewPostNote() {
|
|
|
|
postNotesPresenter.addNewPostNote();
|
|
|
|
}
|
|
|
|
|
2014-10-22 10:42:15 +02:00
|
|
|
return {
|
|
|
|
init: init,
|
|
|
|
render: render,
|
2014-10-26 01:01:16 +02:00
|
|
|
addNewPostNote: addNewPostNote,
|
2014-10-22 10:42:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
App.DI.register('postContentPresenter', [
|
2014-10-26 12:39:55 +01:00
|
|
|
'jQuery',
|
2014-10-22 10:42:15 +02:00
|
|
|
'util',
|
2014-10-25 15:02:46 +02:00
|
|
|
'promise',
|
|
|
|
'presenterManager',
|
|
|
|
'postNotesPresenter'],
|
2014-10-22 10:42:15 +02:00
|
|
|
App.Presenters.PostContentPresenter);
|