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