diff --git a/app/assets/javascripts/discourse/widgets/post-admin-menu.js.es6 b/app/assets/javascripts/discourse/widgets/post-admin-menu.js.es6 index dabbdc421b3..1532e5a70cf 100644 --- a/app/assets/javascripts/discourse/widgets/post-admin-menu.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post-admin-menu.js.es6 @@ -10,52 +10,85 @@ createWidget('post-admin-menu-button', jQuery.extend(ButtonClass, { } })); +export function buildManageButtons(widget) { + let { attrs, currentUser } = widget; + + if (!currentUser) { + return []; + } + + let contents = []; + if (!attrs.isWhisper && currentUser.staff) { + const buttonAtts = { + action: 'togglePostType', + icon: 'shield', + className: 'toggle-post-type' + }; + + if (attrs.isModeratorAction) { + buttonAtts.label = 'post.controls.revert_to_regular'; + } else { + buttonAtts.label = 'post.controls.convert_to_moderator'; + } + contents.push(buttonAtts); + } + + if (attrs.canManage) { + contents.push({ + icon: 'cog', + label: 'post.controls.rebake', + action: 'rebakePost', + className: 'rebuild-html' + }); + + if (attrs.hidden) { + contents.push({ + icon: 'eye', + label: 'post.controls.unhide', + action: 'unhidePost', + className: 'unhide-post' + }); + } + } + + if (currentUser.admin) { + contents.push({ + icon: 'user', + label: 'post.controls.change_owner', + action: 'changePostOwner', + className: 'change-owner' + }); + } + + if (attrs.wiki) { + contents.push({ + action: 'toggleWiki', + label: 'post.controls.unwiki', + icon: 'pencil-square-o', + className: 'wiki wikied' + }); + } else { + contents.push({ + action: 'toggleWiki', + label: 'post.controls.wiki', + icon: 'pencil-square-o', + className: 'wiki' + }); + } + + return contents; +} + export default createWidget('post-admin-menu', { tagName: 'div.post-admin-menu.popup-menu', - html(attrs) { + html() { const contents = []; contents.push(h('h3', I18n.t('admin_title'))); - if (!attrs.isWhisper && this.currentUser.staff) { - const buttonAtts = { action: 'togglePostType', icon: 'shield', className: 'toggle-post-type' }; - - if (attrs.isModeratorAction) { - buttonAtts.label = 'post.controls.revert_to_regular'; - } else { - buttonAtts.label = 'post.controls.convert_to_moderator'; - } - contents.push(this.attach('post-admin-menu-button', buttonAtts)); - } - - if (attrs.canManage) { - contents.push(this.attach('post-admin-menu-button', { - icon: 'cog', label: 'post.controls.rebake', action: 'rebakePost', className: 'rebuild-html' - })); - - if (attrs.hidden) { - contents.push(this.attach('post-admin-menu-button', { - icon: 'eye', label: 'post.controls.unhide', action: 'unhidePost', className: 'unhide-post' - })); - } - } - - if (this.currentUser.admin) { - contents.push(this.attach('post-admin-menu-button', { - icon: 'user', label: 'post.controls.change_owner', action: 'changePostOwner', className: 'change-owner' - })); - } - - // toggle Wiki button - if (attrs.wiki) { - contents.push(this.attach('post-admin-menu-button', { - action: 'toggleWiki', label: 'post.controls.unwiki', icon: 'pencil-square-o', className: 'wiki wikied' - })); - } else { - contents.push(this.attach('post-admin-menu-button', { - action: 'toggleWiki', label: 'post.controls.wiki', icon: 'pencil-square-o', className: 'wiki' - })); - } + buildManageButtons(this).forEach(b => { + contents.push(this.attach('post-admin-menu-button', b)); + }); return contents; },