Added post featuring

This commit is contained in:
Marcin Kurczewski
2014-09-24 23:24:51 +02:00
parent 0038df26d8
commit 97ca08cf44
24 changed files with 402 additions and 22 deletions

View File

@ -25,6 +25,7 @@ App.Presenters.PostPresenter = function(
topNavigationPresenter.select('posts');
privileges.canDeletePosts = auth.hasPrivilege(auth.privileges.deletePosts);
privileges.canFeaturePosts = auth.hasPrivilege(auth.privileges.featurePosts);
promise.waitAll(
util.promiseTemplate('post'),
@ -34,7 +35,6 @@ App.Presenters.PostPresenter = function(
postTemplateHtml,
postContentTemplateHtml,
response) {
$messages = $el.find('.messages');
postTemplate = _.template(postTemplateHtml);
postContentTemplate = _.template(postContentTemplateHtml);
@ -45,7 +45,7 @@ App.Presenters.PostPresenter = function(
}).fail(function(response) {
$el.empty();
messagePresenter.showError($messages, response.json && response.json.error || response);
showGenericError(response);
});
}
@ -57,23 +57,45 @@ App.Presenters.PostPresenter = function(
postContentTemplate: postContentTemplate,
privileges: privileges,
}));
$messages = $el.find('.messages');
$el.find('.delete').click(deleteButtonClicked);
$el.find('.feature').click(featureButtonClicked);
}
function deleteButtonClicked(e) {
e.preventDefault();
messagePresenter.hideMessages($messages);
if (window.confirm('Do you really want to delete this post?')) {
deletePost();
}
}
function deletePost() {
api.delete('/posts/' + post.id).then(function(response) {
router.navigate('#/posts');
}).fail(function(response) {
messagePresenter.showError($messages, response.json && response.json.error || response);
});
api.delete('/posts/' + post.id)
.then(function(response) {
router.navigate('#/posts');
}).fail(showGenericError);
}
function featureButtonClicked(e) {
e.preventDefault();
messagePresenter.hideMessages($messages);
if (window.confirm('Do you want to feature this post on fron page?')) {
featurePost();
}
}
function featurePost() {
api.post('/posts/' + post.id + '/feature')
.then(function(response) {
router.navigate('#/home');
})
.fail(showGenericError);
}
function showGenericError(response) {
messagePresenter.showError($messages, response.json && response.json.error || response);
}
return {