diff --git a/client/html/post_edit_sidebar.tpl b/client/html/post_edit_sidebar.tpl index cf28ed3..54a3388 100644 --- a/client/html/post_edit_sidebar.tpl +++ b/client/html/post_edit_sidebar.tpl @@ -1,65 +1,64 @@
-
- - <%= 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'}) %> -
+ <% if (ctx.canEditPostSafety) { %> +
+ + <%= 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'}) %> +
+ <% } %> -
- <%= ctx.makeTextInput({ - text: 'Tags', - value: ctx.post.tags.join(' '), - readonly: !ctx.canEditPostTags}) %> -
+ <% if (ctx.canEditPostTags) { %> +
+ <%= ctx.makeTextInput({ + text: 'Tags', + value: ctx.post.tags.join(' '), + }) %> +
+ <% } %> -
- <%= 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}) %> -
+ <% if (ctx.canEditPostRelations) { %> +
+ <%= ctx.makeTextInput({ + text: 'Relations', + name: 'relations', + placeholder: 'space-separated post IDs', + pattern: '^[0-9 ]*$', + value: ctx.post.relations.map(rel => rel.id).join(' '), + }) %> +
+ <% } %> - <% if ((ctx.editingNewPost && ctx.canCreateAnonymousPosts) || ctx.post.type === 'video') { %> + <% if (ctx.canEditPostFlags && ctx.post.type === 'video') { %>
- <% if (ctx.editingNewPost && ctx.canCreateAnonymousPosts) { %> - <%= ctx.makeCheckbox({ - text: 'Don\'t show me as uploader', - name: 'anonymous'}) %> - <% } %> - - <% if (ctx.post.type === 'video') { %> - - <%= ctx.makeCheckbox({ - text: 'Loop video', - name: 'loop', - readonly: !ctx.canEditPostFlags}) %> - <% } %> + + <%= ctx.makeCheckbox({ + text: 'Loop video', + name: 'loop', + }) %>
<% } %>
+
diff --git a/client/js/controllers/post_controller.js b/client/js/controllers/post_controller.js index 397390e..c2ba12a 100644 --- a/client/js/controllers/post_controller.js +++ b/client/js/controllers/post_controller.js @@ -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(); diff --git a/client/js/controls/post_edit_sidebar_control.js b/client/js/controls/post_edit_sidebar_control.js index fa1e776..b6817e1 100644 --- a/client/js/controls/post_edit_sidebar_control.js +++ b/client/js/controls/post_edit_sidebar_control.js @@ -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, }, })); } diff --git a/client/js/models/post.js b/client/js/models/post.js index fad9f0c..e269eec 100644 --- a/client/js/models/post.js +++ b/client/js/models/post.js @@ -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, diff --git a/client/js/util/views.js b/client/js/util/views.js index 1be6173..2f1f4d7 100644 --- a/client/js/util/views.js +++ b/client/js/util/views.js @@ -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'});