client/posts: add post featuring
This commit is contained in:
parent
3b800b9731
commit
179cf57cb9
5 changed files with 60 additions and 0 deletions
|
@ -316,6 +316,10 @@ $safety-unsafe = #F3985F
|
||||||
flex-grow: 1
|
flex-grow: 1
|
||||||
display: inline-block
|
display: inline-block
|
||||||
|
|
||||||
|
.management
|
||||||
|
li
|
||||||
|
margin: 0
|
||||||
|
|
||||||
label
|
label
|
||||||
margin-bottom: 0.3em
|
margin-bottom: 0.3em
|
||||||
display: block
|
display: block
|
||||||
|
|
|
@ -70,6 +70,16 @@
|
||||||
</section>
|
</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>
|
<div class='messages'></div>
|
||||||
|
|
||||||
<input type='submit' value='Submit' class='submit'/>
|
<input type='submit' value='Submit' class='submit'/>
|
||||||
|
|
|
@ -59,6 +59,8 @@ class PostController {
|
||||||
'change', e => this._evtPostChange(e));
|
'change', e => this._evtPostChange(e));
|
||||||
this._view.sidebarControl.addEventListener(
|
this._view.sidebarControl.addEventListener(
|
||||||
'submit', e => this._evtPostEdit(e));
|
'submit', e => this._evtPostEdit(e));
|
||||||
|
this._view.sidebarControl.addEventListener(
|
||||||
|
'feature', e => this._evtPostFeature(e));
|
||||||
}
|
}
|
||||||
if (this._view.commentFormControl) {
|
if (this._view.commentFormControl) {
|
||||||
this._view.commentFormControl.addEventListener(
|
this._view.commentFormControl.addEventListener(
|
||||||
|
@ -100,6 +102,19 @@ class PostController {
|
||||||
settings.save(browsingSettings);
|
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) {
|
_evtPostEdit(e) {
|
||||||
this._view.sidebarControl.disableForm();
|
this._view.sidebarControl.disableForm();
|
||||||
this._view.sidebarControl.clearMessages();
|
this._view.sidebarControl.clearMessages();
|
||||||
|
|
|
@ -42,6 +42,9 @@ class PostEditSidebarControl extends events.EventTarget {
|
||||||
new ExpanderControl(
|
new ExpanderControl(
|
||||||
'Content',
|
'Content',
|
||||||
this._hostNode.querySelectorAll('.post-content, .post-thumbnail'));
|
this._hostNode.querySelectorAll('.post-content, .post-thumbnail'));
|
||||||
|
new ExpanderControl(
|
||||||
|
'Management',
|
||||||
|
this._hostNode.querySelectorAll('.management'));
|
||||||
|
|
||||||
if (this._formNode) {
|
if (this._formNode) {
|
||||||
this._formNode.addEventListener('submit', e => this._evtSubmit(e));
|
this._formNode.addEventListener('submit', e => this._evtSubmit(e));
|
||||||
|
@ -81,6 +84,11 @@ class PostEditSidebarControl extends events.EventTarget {
|
||||||
this._post.hasCustomThumbnail ? 'block' : 'none';
|
this._post.hasCustomThumbnail ? 'block' : 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this._featureLinkNode) {
|
||||||
|
this._featureLinkNode.addEventListener(
|
||||||
|
'click', e => this._evtFeatureClick(e));
|
||||||
|
}
|
||||||
|
|
||||||
this._post.addEventListener(
|
this._post.addEventListener(
|
||||||
'changeContent', e => this._evtPostContentChange(e));
|
'changeContent', e => this._evtPostContentChange(e));
|
||||||
|
|
||||||
|
@ -113,6 +121,16 @@ class PostEditSidebarControl extends events.EventTarget {
|
||||||
this._thumbnailRemovalLinkNode.style.display = 'none';
|
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) {
|
_evtSubmit(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.dispatchEvent(new CustomEvent('submit', {
|
this.dispatchEvent(new CustomEvent('submit', {
|
||||||
|
@ -185,6 +203,10 @@ class PostEditSidebarControl extends events.EventTarget {
|
||||||
return this._formNode.querySelector('.post-thumbnail a');
|
return this._formNode.querySelector('.post-thumbnail a');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get _featureLinkNode() {
|
||||||
|
return this._formNode.querySelector('.management .feature');
|
||||||
|
}
|
||||||
|
|
||||||
enableForm() {
|
enableForm() {
|
||||||
views.enableForm(this._formNode);
|
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) {
|
setScore(score) {
|
||||||
return api.put('/post/' + this._id + '/score', {score: score})
|
return api.put('/post/' + this._id + '/score', {score: score})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|
Loading…
Reference in a new issue