Allow more extensibility for the post menu buttons
This commit is contained in:
parent
051b49efdb
commit
6d0bf287b5
|
@ -31,8 +31,10 @@ export default createWidget('link', {
|
|||
},
|
||||
|
||||
buildAttributes(attrs) {
|
||||
return { href: this.href(attrs),
|
||||
title: attrs.title ? I18n.t(attrs.title) : this.label(attrs) };
|
||||
return {
|
||||
href: this.href(attrs),
|
||||
title: attrs.title ? I18n.t(attrs.title) : this.label(attrs)
|
||||
};
|
||||
},
|
||||
|
||||
label(attrs) {
|
||||
|
|
|
@ -29,6 +29,18 @@ function registerButton(name, builder) {
|
|||
_builders[name] = builder;
|
||||
}
|
||||
|
||||
export function buildButton(name, widget) {
|
||||
let { attrs, state, siteSettings } = widget;
|
||||
let builder = _builders[name];
|
||||
if (builder) {
|
||||
let button = builder(attrs, state, siteSettings);
|
||||
if (button && !button.id) {
|
||||
button.id = name;
|
||||
}
|
||||
return button;
|
||||
}
|
||||
}
|
||||
|
||||
registerButton('like', attrs => {
|
||||
if (!attrs.showLike) { return; }
|
||||
const className = attrs.liked ? 'toggle-like has-like fade-out' : 'toggle-like like';
|
||||
|
@ -181,6 +193,7 @@ registerButton('bookmark', attrs => {
|
|||
}
|
||||
|
||||
return {
|
||||
id: attrs.bookmarked ? 'bookmark' : 'unbookmark',
|
||||
action: 'toggleBookmark',
|
||||
title: attrs.bookmarked ? "bookmarks.created" : "bookmarks.not_bookmarked",
|
||||
className,
|
||||
|
@ -198,13 +211,13 @@ registerButton('admin', attrs => {
|
|||
|
||||
registerButton('delete', attrs => {
|
||||
if (attrs.canRecoverTopic) {
|
||||
return { action: 'recoverPost', title: 'topic.actions.recover', icon: 'undo', className: 'recover' };
|
||||
return { id: 'recover_topic', action: 'recoverPost', title: 'topic.actions.recover', icon: 'undo', className: 'recover' };
|
||||
} else if (attrs.canDeleteTopic) {
|
||||
return { action: 'deletePost', title: 'topic.actions.delete', icon: 'trash-o', className: 'delete' };
|
||||
return { id: 'delete_topic', action: 'deletePost', title: 'topic.actions.delete', icon: 'trash-o', className: 'delete' };
|
||||
} else if (attrs.canRecover) {
|
||||
return { action: 'recoverPost', title: 'post.controls.undelete', icon: 'undo', className: 'recover' };
|
||||
return { id: 'recover', action: 'recoverPost', title: 'post.controls.undelete', icon: 'undo', className: 'recover' };
|
||||
} else if (attrs.canDelete) {
|
||||
return { action: 'deletePost', title: 'post.controls.delete', icon: 'trash-o', className: 'delete' };
|
||||
return { action: 'delete', title: 'post.controls.delete', icon: 'trash-o', className: 'delete' };
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -229,13 +242,10 @@ export default createWidget('post-menu', {
|
|||
|
||||
buildKey: attrs => `post-menu-${attrs.id}`,
|
||||
|
||||
attachButton(name, attrs) {
|
||||
const builder = _builders[name];
|
||||
if (builder) {
|
||||
const buttonAtts = builder(attrs, this.state, this.siteSettings);
|
||||
if (buttonAtts) {
|
||||
return this.attach(this.settings.buttonType, buttonAtts);
|
||||
}
|
||||
attachButton(name) {
|
||||
let buttonAtts = buildButton(name, this);
|
||||
if (buttonAtts) {
|
||||
return this.attach(this.settings.buttonType, buttonAtts);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue