Extensibility for Post manage menu

This commit is contained in:
Robin Ward 2017-10-04 15:52:40 -04:00
parent 6d0bf287b5
commit 4aa30cba2e
1 changed files with 73 additions and 40 deletions

View File

@ -10,53 +10,86 @@ createWidget('post-admin-menu-button', jQuery.extend(ButtonClass, {
} }
})); }));
export default createWidget('post-admin-menu', { export function buildManageButtons(widget) {
tagName: 'div.post-admin-menu.popup-menu', let { attrs, currentUser } = widget;
html(attrs) { if (!currentUser) {
const contents = []; return [];
contents.push(h('h3', I18n.t('admin_title'))); }
if (!attrs.isWhisper && this.currentUser.staff) { let contents = [];
const buttonAtts = { action: 'togglePostType', icon: 'shield', className: 'toggle-post-type' }; if (!attrs.isWhisper && currentUser.staff) {
const buttonAtts = {
action: 'togglePostType',
icon: 'shield',
className: 'toggle-post-type'
};
if (attrs.isModeratorAction) { if (attrs.isModeratorAction) {
buttonAtts.label = 'post.controls.revert_to_regular'; buttonAtts.label = 'post.controls.revert_to_regular';
} else { } else {
buttonAtts.label = 'post.controls.convert_to_moderator'; buttonAtts.label = 'post.controls.convert_to_moderator';
} }
contents.push(this.attach('post-admin-menu-button', buttonAtts)); contents.push(buttonAtts);
} }
if (attrs.canManage) { if (attrs.canManage) {
contents.push(this.attach('post-admin-menu-button', { contents.push({
icon: 'cog', label: 'post.controls.rebake', action: 'rebakePost', className: 'rebuild-html' icon: 'cog',
})); label: 'post.controls.rebake',
action: 'rebakePost',
className: 'rebuild-html'
});
if (attrs.hidden) { if (attrs.hidden) {
contents.push(this.attach('post-admin-menu-button', { contents.push({
icon: 'eye', label: 'post.controls.unhide', action: 'unhidePost', className: 'unhide-post' icon: 'eye',
})); label: 'post.controls.unhide',
action: 'unhidePost',
className: 'unhide-post'
});
} }
} }
if (this.currentUser.admin) { if (currentUser.admin) {
contents.push(this.attach('post-admin-menu-button', { contents.push({
icon: 'user', label: 'post.controls.change_owner', action: 'changePostOwner', className: 'change-owner' icon: 'user',
})); label: 'post.controls.change_owner',
action: 'changePostOwner',
className: 'change-owner'
});
} }
// toggle Wiki button
if (attrs.wiki) { if (attrs.wiki) {
contents.push(this.attach('post-admin-menu-button', { contents.push({
action: 'toggleWiki', label: 'post.controls.unwiki', icon: 'pencil-square-o', className: 'wiki wikied' action: 'toggleWiki',
})); label: 'post.controls.unwiki',
icon: 'pencil-square-o',
className: 'wiki wikied'
});
} else { } else {
contents.push(this.attach('post-admin-menu-button', { contents.push({
action: 'toggleWiki', label: 'post.controls.wiki', icon: 'pencil-square-o', className: 'wiki' 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() {
const contents = [];
contents.push(h('h3', I18n.t('admin_title')));
buildManageButtons(this).forEach(b => {
contents.push(this.attach('post-admin-menu-button', b));
});
return contents; return contents;
}, },