client/posts: respect edit privileges in sidebar

This commit is contained in:
rr- 2016-07-26 19:58:26 +02:00
parent 0db70f7951
commit 865c4f3b79
5 changed files with 78 additions and 63 deletions

View file

@ -1,6 +1,7 @@
<div class='edit-sidebar'> <div class='edit-sidebar'>
<form autocomplete='off'> <form autocomplete='off'>
<div class='input'> <div class='input'>
<% if (ctx.canEditPostSafety) { %>
<section class='safety'> <section class='safety'>
<label>Safety</label> <label>Safety</label>
<%= ctx.makeRadio({ <%= ctx.makeRadio({
@ -22,14 +23,18 @@
class: 'safety-unsafe', class: 'safety-unsafe',
text: 'Unsafe'}) %> text: 'Unsafe'}) %>
</section> </section>
<% } %>
<% if (ctx.canEditPostTags) { %>
<section class='tags'> <section class='tags'>
<%= ctx.makeTextInput({ <%= ctx.makeTextInput({
text: 'Tags', text: 'Tags',
value: ctx.post.tags.join(' '), value: ctx.post.tags.join(' '),
readonly: !ctx.canEditPostTags}) %> }) %>
</section> </section>
<% } %>
<% if (ctx.canEditPostRelations) { %>
<section class='relations'> <section class='relations'>
<%= ctx.makeTextInput({ <%= ctx.makeTextInput({
text: 'Relations', text: 'Relations',
@ -37,29 +42,23 @@
placeholder: 'space-separated post IDs', placeholder: 'space-separated post IDs',
pattern: '^[0-9 ]*$', pattern: '^[0-9 ]*$',
value: ctx.post.relations.map(rel => rel.id).join(' '), value: ctx.post.relations.map(rel => rel.id).join(' '),
readonly: !ctx.canEditPostRelations}) %> }) %>
</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) { %>
<%= ctx.makeCheckbox({
text: 'Don\'t show me as uploader',
name: 'anonymous'}) %>
<% } %>
<% if (ctx.post.type === 'video') { %>
<!-- TODO: bind state --> <!-- TODO: bind state -->
<%= ctx.makeCheckbox({ <%= ctx.makeCheckbox({
text: 'Loop video', text: 'Loop video',
name: 'loop', name: 'loop',
readonly: !ctx.canEditPostFlags}) %> }) %>
<% } %>
</section> </section>
<% } %> <% } %>
</div> </div>
<div class='messages'></div> <div class='messages'></div>
<div class='buttons'> <div class='buttons'>

View file

@ -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;
if (e.detail.tags !== undefined) {
post.tags = e.detail.tags; post.tags = e.detail.tags;
}
if (e.detail.safety !== undefined) {
post.safety = e.detail.safety; post.safety = e.detail.safety;
}
if (e.detail.relations !== undefined) {
post.relations = e.detail.relations; post.relations = e.detail.relations;
}
post.save() post.save()
.then(() => { .then(() => {
misc.disableExitConfirmation(); misc.disableExitConfirmation();

View file

@ -34,22 +34,30 @@ class PostEditSidebarControl extends events.EventTarget {
this._formNode.addEventListener('submit', e => this._evtSubmit(e)); this._formNode.addEventListener('submit', e => this._evtSubmit(e));
} }
if (this._tagInputNode) {
this._tagControl = new TagInputControl(this._tagInputNode); this._tagControl = new TagInputControl(this._tagInputNode);
} }
}
_evtSubmit(e) { _evtSubmit(e) {
e.preventDefault(); e.preventDefault();
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,
}, },
})); }));
} }

View file

@ -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,

View file

@ -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'});