client/posts: respect edit privileges in sidebar
This commit is contained in:
parent
0db70f7951
commit
865c4f3b79
5 changed files with 78 additions and 63 deletions
|
@ -1,65 +1,64 @@
|
||||||
<div class='edit-sidebar'>
|
<div class='edit-sidebar'>
|
||||||
<form autocomplete='off'>
|
<form autocomplete='off'>
|
||||||
<div class='input'>
|
<div class='input'>
|
||||||
<section class='safety'>
|
<% if (ctx.canEditPostSafety) { %>
|
||||||
<label>Safety</label>
|
<section class='safety'>
|
||||||
<%= ctx.makeRadio({
|
<label>Safety</label>
|
||||||
name: 'safety',
|
<%= ctx.makeRadio({
|
||||||
class: 'safety-safe',
|
name: 'safety',
|
||||||
value: 'safe',
|
class: 'safety-safe',
|
||||||
selectedValue: ctx.post.safety,
|
value: 'safe',
|
||||||
text: 'Safe'}) %>
|
selectedValue: ctx.post.safety,
|
||||||
<%= ctx.makeRadio({
|
text: 'Safe'}) %>
|
||||||
name: 'safety',
|
<%= ctx.makeRadio({
|
||||||
class: 'safety-sketchy',
|
name: 'safety',
|
||||||
value: 'sketchy',
|
class: 'safety-sketchy',
|
||||||
selectedValue: ctx.post.safety,
|
value: 'sketchy',
|
||||||
text: 'Sketchy'}) %>
|
selectedValue: ctx.post.safety,
|
||||||
<%= ctx.makeRadio({
|
text: 'Sketchy'}) %>
|
||||||
name: 'safety',
|
<%= ctx.makeRadio({
|
||||||
value: 'unsafe',
|
name: 'safety',
|
||||||
selectedValue: ctx.post.safety,
|
value: 'unsafe',
|
||||||
class: 'safety-unsafe',
|
selectedValue: ctx.post.safety,
|
||||||
text: 'Unsafe'}) %>
|
class: 'safety-unsafe',
|
||||||
</section>
|
text: 'Unsafe'}) %>
|
||||||
|
</section>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
<section class='tags'>
|
<% if (ctx.canEditPostTags) { %>
|
||||||
<%= ctx.makeTextInput({
|
<section class='tags'>
|
||||||
text: 'Tags',
|
<%= ctx.makeTextInput({
|
||||||
value: ctx.post.tags.join(' '),
|
text: 'Tags',
|
||||||
readonly: !ctx.canEditPostTags}) %>
|
value: ctx.post.tags.join(' '),
|
||||||
</section>
|
}) %>
|
||||||
|
</section>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
<section class='relations'>
|
<% if (ctx.canEditPostRelations) { %>
|
||||||
<%= ctx.makeTextInput({
|
<section class='relations'>
|
||||||
text: 'Relations',
|
<%= ctx.makeTextInput({
|
||||||
name: 'relations',
|
text: 'Relations',
|
||||||
placeholder: 'space-separated post IDs',
|
name: 'relations',
|
||||||
pattern: '^[0-9 ]*$',
|
placeholder: 'space-separated post IDs',
|
||||||
value: ctx.post.relations.map(rel => rel.id).join(' '),
|
pattern: '^[0-9 ]*$',
|
||||||
readonly: !ctx.canEditPostRelations}) %>
|
value: ctx.post.relations.map(rel => rel.id).join(' '),
|
||||||
</section>
|
}) %>
|
||||||
|
</section>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
<% if ((ctx.editingNewPost && ctx.canCreateAnonymousPosts) || ctx.post.type === 'video') { %>
|
<% if (ctx.canEditPostFlags && ctx.post.type === 'video') { %>
|
||||||
<section class='flags'>
|
<section class='flags'>
|
||||||
<label>Miscellaneous</label>
|
<label>Miscellaneous</label>
|
||||||
|
|
||||||
<% if (ctx.editingNewPost && ctx.canCreateAnonymousPosts) { %>
|
<!-- TODO: bind state -->
|
||||||
<%= ctx.makeCheckbox({
|
<%= ctx.makeCheckbox({
|
||||||
text: 'Don\'t show me as uploader',
|
text: 'Loop video',
|
||||||
name: 'anonymous'}) %>
|
name: 'loop',
|
||||||
<% } %>
|
}) %>
|
||||||
|
|
||||||
<% if (ctx.post.type === 'video') { %>
|
|
||||||
<!-- TODO: bind state -->
|
|
||||||
<%= ctx.makeCheckbox({
|
|
||||||
text: 'Loop video',
|
|
||||||
name: 'loop',
|
|
||||||
readonly: !ctx.canEditPostFlags}) %>
|
|
||||||
<% } %>
|
|
||||||
</section>
|
</section>
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class='messages'></div>
|
<div class='messages'></div>
|
||||||
|
|
||||||
<div class='buttons'>
|
<div class='buttons'>
|
||||||
|
|
|
@ -100,9 +100,15 @@ class PostController {
|
||||||
_evtPostEdit(e) {
|
_evtPostEdit(e) {
|
||||||
// TODO: disable form
|
// TODO: disable form
|
||||||
const post = e.detail.post;
|
const post = e.detail.post;
|
||||||
post.tags = e.detail.tags;
|
if (e.detail.tags !== undefined) {
|
||||||
post.safety = e.detail.safety;
|
post.tags = e.detail.tags;
|
||||||
post.relations = e.detail.relations;
|
}
|
||||||
|
if (e.detail.safety !== undefined) {
|
||||||
|
post.safety = e.detail.safety;
|
||||||
|
}
|
||||||
|
if (e.detail.relations !== undefined) {
|
||||||
|
post.relations = e.detail.relations;
|
||||||
|
}
|
||||||
post.save()
|
post.save()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
misc.disableExitConfirmation();
|
misc.disableExitConfirmation();
|
||||||
|
|
|
@ -34,7 +34,9 @@ class PostEditSidebarControl extends events.EventTarget {
|
||||||
this._formNode.addEventListener('submit', e => this._evtSubmit(e));
|
this._formNode.addEventListener('submit', e => this._evtSubmit(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
this._tagControl = new TagInputControl(this._tagInputNode);
|
if (this._tagInputNode) {
|
||||||
|
this._tagControl = new TagInputControl(this._tagInputNode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_evtSubmit(e) {
|
_evtSubmit(e) {
|
||||||
|
@ -42,14 +44,20 @@ class PostEditSidebarControl extends events.EventTarget {
|
||||||
this.dispatchEvent(new CustomEvent('submit', {
|
this.dispatchEvent(new CustomEvent('submit', {
|
||||||
detail: {
|
detail: {
|
||||||
post: this._post,
|
post: this._post,
|
||||||
safety:
|
|
||||||
|
safety: this._safetyButtonNodes.legnth ?
|
||||||
Array.from(this._safetyButtonNodes)
|
Array.from(this._safetyButtonNodes)
|
||||||
.filter(node => node.checked)[0]
|
.filter(node => node.checked)[0]
|
||||||
.value.toLowerCase(),
|
.value.toLowerCase() :
|
||||||
tags:
|
undefined,
|
||||||
misc.splitByWhitespace(this._tagInputNode.value),
|
|
||||||
relations:
|
tags: this._tagInputNode ?
|
||||||
misc.splitByWhitespace(this._relationsInputNode.value),
|
misc.splitByWhitespace(this._tagInputNode.value) :
|
||||||
|
undefined,
|
||||||
|
|
||||||
|
relations: this._relationsInputNode ?
|
||||||
|
misc.splitByWhitespace(this._relationsInputNode.value) :
|
||||||
|
undefined,
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,10 +212,10 @@ class Post extends events.EventTarget {
|
||||||
_canvasHeight: response.canvasHeight,
|
_canvasHeight: response.canvasHeight,
|
||||||
_fileSize: response.fileSize,
|
_fileSize: response.fileSize,
|
||||||
|
|
||||||
_tags: response.tags,
|
_tags: response.tags || [],
|
||||||
_notes: response.notes,
|
_notes: response.notes || [],
|
||||||
_comments: CommentList.fromResponse(response.comments || []),
|
_comments: CommentList.fromResponse(response.comments || []),
|
||||||
_relations: response.relations,
|
_relations: response.relations || [],
|
||||||
|
|
||||||
_score: response.score,
|
_score: response.score,
|
||||||
_favoriteCount: response.favoriteCount,
|
_favoriteCount: response.favoriteCount,
|
||||||
|
|
|
@ -59,6 +59,7 @@ function makeRadio(options) {
|
||||||
value: options.value,
|
value: options.value,
|
||||||
type: 'radio',
|
type: 'radio',
|
||||||
checked: options.selectedValue === options.value,
|
checked: options.selectedValue === options.value,
|
||||||
|
disabled: options.readonly,
|
||||||
required: options.required,
|
required: options.required,
|
||||||
}) +
|
}) +
|
||||||
_makeLabel(options, {class: 'radio'});
|
_makeLabel(options, {class: 'radio'});
|
||||||
|
@ -75,6 +76,7 @@ function makeCheckbox(options) {
|
||||||
type: 'checkbox',
|
type: 'checkbox',
|
||||||
checked: options.checked !== undefined ?
|
checked: options.checked !== undefined ?
|
||||||
options.checked : false,
|
options.checked : false,
|
||||||
|
disabled: options.readonly,
|
||||||
required: options.required,
|
required: options.required,
|
||||||
}) +
|
}) +
|
||||||
_makeLabel(options, {class: 'checkbox'});
|
_makeLabel(options, {class: 'checkbox'});
|
||||||
|
|
Loading…
Reference in a new issue