From 34022d8fc85a6c5f5811b2a8adbd5e81e32067f4 Mon Sep 17 00:00:00 2001 From: rr- Date: Tue, 23 Aug 2016 21:50:22 +0200 Subject: [PATCH] client/auth: fix not hiding anonymity checkbox --- client/html/post_upload_row.tpl | 16 ++++++++------- .../js/controllers/post_upload_controller.js | 4 +++- client/js/views/post_upload_view.js | 20 +++++++++++++------ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/client/html/post_upload_row.tpl b/client/html/post_upload_row.tpl index b12a9d0f..e3361079 100644 --- a/client/html/post_upload_row.tpl +++ b/client/html/post_upload_row.tpl @@ -30,11 +30,13 @@ <% } %> -
- <%= ctx.makeCheckbox({ - text: 'Upload anonymously', - name: 'anonymous', - checked: ctx.uploadable.anonymous, - }) %> -
+ <% if (ctx.canUploadAnonymously) { %> +
+ <%= ctx.makeCheckbox({ + text: 'Upload anonymously', + name: 'anonymous', + checked: ctx.uploadable.anonymous, + }) %> +
+ <% } %> diff --git a/client/js/controllers/post_upload_controller.js b/client/js/controllers/post_upload_controller.js index ae4f4974..c9da651d 100644 --- a/client/js/controllers/post_upload_controller.js +++ b/client/js/controllers/post_upload_controller.js @@ -18,7 +18,9 @@ class PostUploadController { topNavigation.activate('upload'); topNavigation.setTitle('Upload'); - this._view = new PostUploadView(); + this._view = new PostUploadView({ + canUploadAnonymously: api.hasPrivilege('posts:create:anonymous'), + }); this._view.addEventListener('change', e => this._evtChange(e)); this._view.addEventListener('submit', e => this._evtSubmit(e)); } diff --git a/client/js/views/post_upload_view.js b/client/js/views/post_upload_view.js index 26a43296..7e53840f 100644 --- a/client/js/views/post_upload_view.js +++ b/client/js/views/post_upload_view.js @@ -108,9 +108,9 @@ class Url extends Uploadable { } class PostUploadView extends events.EventTarget { - constructor() { + constructor(ctx) { super(); - + this._ctx = ctx; this._hostNode = document.getElementById('content-holder'); views.replaceContent(this._hostNode, template()); views.syncScrollPosition(); @@ -227,21 +227,29 @@ class PostUploadView extends events.EventTarget { } _createRowNode(uploadable) { - const rowNode = rowTemplate({uploadable: uploadable}); + const rowNode = rowTemplate(Object.assign( + {}, this._ctx, {uploadable: uploadable})); this._listNode.appendChild(rowNode); + for (let radioboxNode of rowNode.querySelectorAll('.safety input')) { radioboxNode.addEventListener( 'change', e => this._evtSafetyRadioboxChange(e, uploadable)); } - rowNode.querySelector('.anonymous input').addEventListener( - 'change', e => this._evtAnonymityCheckboxChange(e, uploadable)); + + const anonymousCheckboxNode = rowNode.querySelector('.anonymous input'); + if (anonymousCheckboxNode) { + anonymousCheckboxNode.addEventListener( + 'change', e => this._evtAnonymityCheckboxChange(e, uploadable)); + } + rowNode.querySelector('a.remove').addEventListener( 'click', e => this._evtRemoveClick(e, uploadable)); uploadable.rowNode = rowNode; } _updateRowNode(uploadable) { - const rowNode = rowTemplate({uploadable: uploadable}); + const rowNode = rowTemplate(Object.assign( + {}, this._ctx, {uploadable: uploadable})); views.replaceContent( uploadable.rowNode.querySelector('.thumbnail'), rowNode.querySelector('.thumbnail').childNodes);