Extracted post content presenter
This commit is contained in:
parent
82d59b57e6
commit
527356bba2
6 changed files with 67 additions and 11 deletions
|
@ -120,6 +120,7 @@
|
|||
|
||||
<script type="text/javascript" src="/js/Presenters/PostListPresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/PostUploadPresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/PostContentPresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/PostEditPresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/PostPresenter.js"></script>
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ App.Presenters.HomePresenter = function(
|
|||
promise,
|
||||
api,
|
||||
auth,
|
||||
presenterManager,
|
||||
postContentPresenter,
|
||||
topNavigationPresenter,
|
||||
messagePresenter) {
|
||||
|
||||
|
@ -21,22 +23,23 @@ App.Presenters.HomePresenter = function(
|
|||
|
||||
promise.wait(
|
||||
util.promiseTemplate('home'),
|
||||
util.promiseTemplate('post-content'),
|
||||
api.get('/globals'),
|
||||
api.get('/posts/featured'))
|
||||
.then(function(
|
||||
homeTemplate,
|
||||
postContentTemplate,
|
||||
globalsResponse,
|
||||
featuredPostResponse) {
|
||||
templates.home = homeTemplate;
|
||||
templates.postContent = postContentTemplate;
|
||||
|
||||
globals = globalsResponse.json;
|
||||
post = featuredPostResponse.json.id ? featuredPostResponse.json : null;
|
||||
render();
|
||||
loaded();
|
||||
|
||||
presenterManager.initPresenters([
|
||||
[postContentPresenter, {post: post, $target: $el.find('#post-content-target')}]],
|
||||
function() {});
|
||||
|
||||
}).fail(function(response) {
|
||||
messagePresenter.showError($el, response.json && response.json.error || response);
|
||||
loaded();
|
||||
|
@ -46,7 +49,6 @@ App.Presenters.HomePresenter = function(
|
|||
function render() {
|
||||
$el.html(templates.home({
|
||||
post: post,
|
||||
postContentTemplate: templates.postContent,
|
||||
globals: globals,
|
||||
title: topNavigationPresenter.getBaseTitle(),
|
||||
canViewUsers: auth.hasPrivilege(auth.privileges.viewUsers),
|
||||
|
@ -65,4 +67,14 @@ App.Presenters.HomePresenter = function(
|
|||
|
||||
};
|
||||
|
||||
App.DI.register('homePresenter', ['jQuery', 'util', 'promise', 'api', 'auth', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.HomePresenter);
|
||||
App.DI.register('homePresenter', [
|
||||
'jQuery',
|
||||
'util',
|
||||
'promise',
|
||||
'api',
|
||||
'auth',
|
||||
'presenterManager',
|
||||
'postContentPresenter',
|
||||
'topNavigationPresenter',
|
||||
'messagePresenter'],
|
||||
App.Presenters.HomePresenter);
|
||||
|
|
41
public_html/js/Presenters/PostContentPresenter.js
Normal file
41
public_html/js/Presenters/PostContentPresenter.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
var App = App || {};
|
||||
App.Presenters = App.Presenters || {};
|
||||
|
||||
App.Presenters.PostContentPresenter = function(
|
||||
util,
|
||||
promise) {
|
||||
|
||||
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}));
|
||||
}
|
||||
|
||||
return {
|
||||
init: init,
|
||||
render: render,
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
App.DI.register('postContentPresenter', [
|
||||
'util',
|
||||
'promise'],
|
||||
App.Presenters.PostContentPresenter);
|
|
@ -13,6 +13,7 @@ App.Presenters.PostPresenter = function(
|
|||
presenterManager,
|
||||
postsAroundCalculator,
|
||||
postEditPresenter,
|
||||
postContentPresenter,
|
||||
postCommentListPresenter,
|
||||
topNavigationPresenter,
|
||||
messagePresenter) {
|
||||
|
@ -38,14 +39,11 @@ App.Presenters.PostPresenter = function(
|
|||
|
||||
promise.wait(
|
||||
util.promiseTemplate('post'),
|
||||
util.promiseTemplate('post-content'),
|
||||
util.promiseTemplate('history'))
|
||||
.then(function(
|
||||
postTemplate,
|
||||
postContentTemplate,
|
||||
historyTemplate) {
|
||||
templates.post = postTemplate;
|
||||
templates.postContent = postContentTemplate;
|
||||
templates.history = historyTemplate;
|
||||
|
||||
reinit(params, loaded);
|
||||
|
@ -69,6 +67,7 @@ App.Presenters.PostPresenter = function(
|
|||
loaded();
|
||||
|
||||
presenterManager.initPresenters([
|
||||
[postContentPresenter, {post: post, $target: $el.find('#post-content-target')}],
|
||||
[postEditPresenter, {post: post, $target: $el.find('#post-edit-target'), updateCallback: postEdited}],
|
||||
[postCommentListPresenter, {post: post, $target: $el.find('#post-comments-target')}]],
|
||||
function() {});
|
||||
|
@ -165,7 +164,6 @@ App.Presenters.PostPresenter = function(
|
|||
formatRelativeTime: util.formatRelativeTime,
|
||||
formatFileSize: util.formatFileSize,
|
||||
|
||||
postContentTemplate: templates.postContent,
|
||||
historyTemplate: templates.history,
|
||||
|
||||
hasFav: _.any(post.favorites, function(favUser) { return favUser.id === auth.getCurrentUser().id; }),
|
||||
|
@ -326,6 +324,7 @@ App.DI.register('postPresenter', [
|
|||
'presenterManager',
|
||||
'postsAroundCalculator',
|
||||
'postEditPresenter',
|
||||
'postContentPresenter',
|
||||
'postCommentListPresenter',
|
||||
'topNavigationPresenter',
|
||||
'messagePresenter'],
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
|
||||
<% if (post && typeof(post) !== 'undefined') { %>
|
||||
<div class="post">
|
||||
<%= postContentTemplate({post: post}) %>
|
||||
<div id="post-content-target">
|
||||
</div>
|
||||
|
||||
<div class="post-footer">
|
||||
|
||||
<span class="left">
|
||||
|
|
|
@ -255,7 +255,8 @@
|
|||
<div id="post-edit-target">
|
||||
</div>
|
||||
|
||||
<%= postContentTemplate({post: post}) %>
|
||||
<div id="post-content-target">
|
||||
</div>
|
||||
|
||||
<% if (privileges.canViewHistory) { %>
|
||||
<div class="post-history-wrapper">
|
||||
|
|
Loading…
Reference in a new issue