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) {
|
buildAttributes(attrs) {
|
||||||
return { href: this.href(attrs),
|
return {
|
||||||
title: attrs.title ? I18n.t(attrs.title) : this.label(attrs) };
|
href: this.href(attrs),
|
||||||
|
title: attrs.title ? I18n.t(attrs.title) : this.label(attrs)
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
label(attrs) {
|
label(attrs) {
|
||||||
|
|
|
@ -29,6 +29,18 @@ function registerButton(name, builder) {
|
||||||
_builders[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 => {
|
registerButton('like', attrs => {
|
||||||
if (!attrs.showLike) { return; }
|
if (!attrs.showLike) { return; }
|
||||||
const className = attrs.liked ? 'toggle-like has-like fade-out' : 'toggle-like like';
|
const className = attrs.liked ? 'toggle-like has-like fade-out' : 'toggle-like like';
|
||||||
|
@ -181,6 +193,7 @@ registerButton('bookmark', attrs => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
id: attrs.bookmarked ? 'bookmark' : 'unbookmark',
|
||||||
action: 'toggleBookmark',
|
action: 'toggleBookmark',
|
||||||
title: attrs.bookmarked ? "bookmarks.created" : "bookmarks.not_bookmarked",
|
title: attrs.bookmarked ? "bookmarks.created" : "bookmarks.not_bookmarked",
|
||||||
className,
|
className,
|
||||||
|
@ -198,13 +211,13 @@ registerButton('admin', attrs => {
|
||||||
|
|
||||||
registerButton('delete', attrs => {
|
registerButton('delete', attrs => {
|
||||||
if (attrs.canRecoverTopic) {
|
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) {
|
} 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) {
|
} 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) {
|
} 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}`,
|
buildKey: attrs => `post-menu-${attrs.id}`,
|
||||||
|
|
||||||
attachButton(name, attrs) {
|
attachButton(name) {
|
||||||
const builder = _builders[name];
|
let buttonAtts = buildButton(name, this);
|
||||||
if (builder) {
|
if (buttonAtts) {
|
||||||
const buttonAtts = builder(attrs, this.state, this.siteSettings);
|
return this.attach(this.settings.buttonType, buttonAtts);
|
||||||
if (buttonAtts) {
|
|
||||||
return this.attach(this.settings.buttonType, buttonAtts);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue