client/auth: fix not hiding anonymity checkbox

This commit is contained in:
rr- 2016-08-23 21:50:22 +02:00
parent e90b8972c7
commit 34022d8fc8
3 changed files with 26 additions and 14 deletions

View file

@ -30,11 +30,13 @@
<% } %>
</div>
<div class='anonymous'>
<%= ctx.makeCheckbox({
text: 'Upload anonymously',
name: 'anonymous',
checked: ctx.uploadable.anonymous,
}) %>
</div>
<% if (ctx.canUploadAnonymously) { %>
<div class='anonymous'>
<%= ctx.makeCheckbox({
text: 'Upload anonymously',
name: 'anonymous',
checked: ctx.uploadable.anonymous,
}) %>
</div>
<% } %>
</li>

View file

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

View file

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