mirror of
https://github.com/flarum/framework.git
synced 2024-12-05 09:03:36 +08:00
Make discussion actions public; use existing reply composer if it's already set up
This commit is contained in:
parent
49749a65a3
commit
a1c21797fc
|
@ -7,16 +7,21 @@ import Separator from 'flarum/components/separator';
|
||||||
import ItemList from 'flarum/utils/item-list';
|
import ItemList from 'flarum/utils/item-list';
|
||||||
|
|
||||||
export default function(app) {
|
export default function(app) {
|
||||||
function replyAction() {
|
Discussion.prototype.replyAction = function(goToLast, forceRefresh) {
|
||||||
if (app.session.user() && this.canReply()) {
|
if (app.session.user() && this.canReply()) {
|
||||||
if (app.current.discussion && app.current.discussion().id() === this.id()) {
|
if (goToLast && app.current.discussion && app.current.discussion().id() === this.id()) {
|
||||||
app.current.streamContent.goToLast();
|
app.current.streamContent.goToLast();
|
||||||
}
|
}
|
||||||
app.composer.load(new ComposerReply({
|
var component = app.composer.component;
|
||||||
|
if (!(component instanceof ComposerReply) || component.props.discussion !== this || component.props.user !== app.session.user() || forceRefresh) {
|
||||||
|
component = new ComposerReply({
|
||||||
user: app.session.user(),
|
user: app.session.user(),
|
||||||
discussion: this
|
discussion: this
|
||||||
}));
|
});
|
||||||
app.composer.show();
|
app.composer.load(component);
|
||||||
|
}
|
||||||
|
app.composer.show(goToLast);
|
||||||
|
return component;
|
||||||
} else if (!app.session.user()) {
|
} else if (!app.session.user()) {
|
||||||
app.modal.show(new LoginModal({
|
app.modal.show(new LoginModal({
|
||||||
message: 'You must be logged in to do that.',
|
message: 'You must be logged in to do that.',
|
||||||
|
@ -25,7 +30,7 @@ export default function(app) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteAction() {
|
Discussion.prototype.deleteAction = function() {
|
||||||
if (confirm('Are you sure you want to delete this discussion?')) {
|
if (confirm('Are you sure you want to delete this discussion?')) {
|
||||||
this.delete();
|
this.delete();
|
||||||
if (app.cache.discussionList) {
|
if (app.cache.discussionList) {
|
||||||
|
@ -37,7 +42,7 @@ export default function(app) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function renameAction() {
|
Discussion.prototype.renameAction = function() {
|
||||||
var currentTitle = this.title();
|
var currentTitle = this.title();
|
||||||
var title = prompt('Enter a new title for this discussion:', currentTitle);
|
var title = prompt('Enter a new title for this discussion:', currentTitle);
|
||||||
if (title && title !== currentTitle) {
|
if (title && title !== currentTitle) {
|
||||||
|
@ -55,7 +60,7 @@ export default function(app) {
|
||||||
|
|
||||||
if (context instanceof DiscussionPage) {
|
if (context instanceof DiscussionPage) {
|
||||||
items.add('reply', !app.session.user() || this.canReply()
|
items.add('reply', !app.session.user() || this.canReply()
|
||||||
? ActionButton.component({ icon: 'reply', label: app.session.user() ? 'Reply' : 'Log In to Reply', onclick: replyAction.bind(this) })
|
? ActionButton.component({ icon: 'reply', label: app.session.user() ? 'Reply' : 'Log In to Reply', onclick: this.replyAction.bind(this, true) })
|
||||||
: ActionButton.component({ icon: 'reply', label: 'Can\'t Reply', className: 'disabled', title: 'You don\'t have permission to reply to this discussion.' })
|
: ActionButton.component({ icon: 'reply', label: 'Can\'t Reply', className: 'disabled', title: 'You don\'t have permission to reply to this discussion.' })
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -63,11 +68,11 @@ export default function(app) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.canEdit()) {
|
if (this.canEdit()) {
|
||||||
items.add('rename', ActionButton.component({ icon: 'pencil', label: 'Rename', onclick: renameAction.bind(this) }));
|
items.add('rename', ActionButton.component({ icon: 'pencil', label: 'Rename', onclick: this.renameAction.bind(this) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.canDelete()) {
|
if (this.canDelete()) {
|
||||||
items.add('delete', ActionButton.component({ icon: 'times', label: 'Delete', onclick: deleteAction.bind(this) }));
|
items.add('delete', ActionButton.component({ icon: 'times', label: 'Delete', onclick: this.deleteAction.bind(this) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user