Disable "Start Discussion" button for restricted tags (#74)

Also, change the label when the button is disabled.
This commit is contained in:
Alexander Skvortsov 2020-04-24 16:29:16 -04:00 committed by GitHub
parent 649f71d25a
commit 80e32594e2

View File

@ -35,16 +35,21 @@ export default function() {
});
// If currently viewing a tag, restyle the 'new discussion' button to use
// the tag's color.
// the tag's color, and disable if the user isn't allowed to edit.
extend(IndexPage.prototype, 'sidebarItems', function(items) {
const tag = this.currentTag();
if (tag) {
const color = tag.color();
const canStartDiscussion = tag.canStartDiscussion();
if (color) {
items.get('newDiscussion').props.style = {backgroundColor: color};
}
items.get('newDiscussion').props.disabled = !canStartDiscussion;
items.get('newDiscussion').props.children = app.translator.trans(canStartDiscussion ? 'core.forum.index.start_discussion_button' : 'core.forum.index.cannot_start_discussion_button');
}
});