client/posts: add post featuring
This commit is contained in:
parent
3b800b9731
commit
179cf57cb9
|
@ -316,6 +316,10 @@ $safety-unsafe = #F3985F
|
|||
flex-grow: 1
|
||||
display: inline-block
|
||||
|
||||
.management
|
||||
li
|
||||
margin: 0
|
||||
|
||||
label
|
||||
margin-bottom: 0.3em
|
||||
display: block
|
||||
|
|
|
@ -70,6 +70,16 @@
|
|||
</section>
|
||||
<% } %>
|
||||
|
||||
<% if (ctx.canFeaturePosts) { %>
|
||||
<section class='management'>
|
||||
<ul>
|
||||
<% if (ctx.canFeaturePosts) { %>
|
||||
<li><a class='feature'>Feature this post on main page</a></li>
|
||||
<% } %>
|
||||
</ul>
|
||||
</section>
|
||||
<% } %>
|
||||
|
||||
<div class='messages'></div>
|
||||
|
||||
<input type='submit' value='Submit' class='submit'/>
|
||||
|
|
|
@ -59,6 +59,8 @@ class PostController {
|
|||
'change', e => this._evtPostChange(e));
|
||||
this._view.sidebarControl.addEventListener(
|
||||
'submit', e => this._evtPostEdit(e));
|
||||
this._view.sidebarControl.addEventListener(
|
||||
'feature', e => this._evtPostFeature(e));
|
||||
}
|
||||
if (this._view.commentFormControl) {
|
||||
this._view.commentFormControl.addEventListener(
|
||||
|
@ -100,6 +102,19 @@ class PostController {
|
|||
settings.save(browsingSettings);
|
||||
}
|
||||
|
||||
_evtPostFeature(e) {
|
||||
this._view.sidebarControl.disableForm();
|
||||
this._view.sidebarControl.clearMessages();
|
||||
e.detail.post.feature()
|
||||
.then(() => {
|
||||
this._view.sidebarControl.showSuccess('Post featured.');
|
||||
this._view.sidebarControl.enableForm();
|
||||
}, errorMessage => {
|
||||
this._view.sidebarControl.showError(errorMessage);
|
||||
this._view.sidebarControl.enableForm();
|
||||
});
|
||||
}
|
||||
|
||||
_evtPostEdit(e) {
|
||||
this._view.sidebarControl.disableForm();
|
||||
this._view.sidebarControl.clearMessages();
|
||||
|
|
|
@ -42,6 +42,9 @@ class PostEditSidebarControl extends events.EventTarget {
|
|||
new ExpanderControl(
|
||||
'Content',
|
||||
this._hostNode.querySelectorAll('.post-content, .post-thumbnail'));
|
||||
new ExpanderControl(
|
||||
'Management',
|
||||
this._hostNode.querySelectorAll('.management'));
|
||||
|
||||
if (this._formNode) {
|
||||
this._formNode.addEventListener('submit', e => this._evtSubmit(e));
|
||||
|
@ -81,6 +84,11 @@ class PostEditSidebarControl extends events.EventTarget {
|
|||
this._post.hasCustomThumbnail ? 'block' : 'none';
|
||||
}
|
||||
|
||||
if (this._featureLinkNode) {
|
||||
this._featureLinkNode.addEventListener(
|
||||
'click', e => this._evtFeatureClick(e));
|
||||
}
|
||||
|
||||
this._post.addEventListener(
|
||||
'changeContent', e => this._evtPostContentChange(e));
|
||||
|
||||
|
@ -113,6 +121,16 @@ class PostEditSidebarControl extends events.EventTarget {
|
|||
this._thumbnailRemovalLinkNode.style.display = 'none';
|
||||
}
|
||||
|
||||
_evtFeatureClick(e) {
|
||||
if (confirm('Are you sure you want to feature this post?')) {
|
||||
this.dispatchEvent(new CustomEvent('feature', {
|
||||
detail: {
|
||||
post: this._post,
|
||||
},
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
_evtSubmit(e) {
|
||||
e.preventDefault();
|
||||
this.dispatchEvent(new CustomEvent('submit', {
|
||||
|
@ -185,6 +203,10 @@ class PostEditSidebarControl extends events.EventTarget {
|
|||
return this._formNode.querySelector('.post-thumbnail a');
|
||||
}
|
||||
|
||||
get _featureLinkNode() {
|
||||
return this._formNode.querySelector('.management .feature');
|
||||
}
|
||||
|
||||
enableForm() {
|
||||
views.enableForm(this._formNode);
|
||||
}
|
||||
|
|
|
@ -128,6 +128,15 @@ class Post extends events.EventTarget {
|
|||
});
|
||||
}
|
||||
|
||||
feature() {
|
||||
return api.post('/featured-post', {id: this._id})
|
||||
.then(response => {
|
||||
return Promise.resolve();
|
||||
}, response => {
|
||||
return Promise.reject(response.description);
|
||||
});
|
||||
}
|
||||
|
||||
setScore(score) {
|
||||
return api.put('/post/' + this._id + '/score', {score: score})
|
||||
.then(response => {
|
||||
|
|
Loading…
Reference in New Issue