1
0
mirror of https://github.com/flarum/core.git synced 2025-08-11 10:55:47 +02:00

update: forum/utils/DiscussionControls

- replyAction has not yet been tested.
This commit is contained in:
Alexander Skvortsov
2020-08-08 12:10:45 -04:00
committed by Franz Liedke
parent 60c3f23667
commit 63e07b2044

View File

@@ -55,19 +55,23 @@ export default {
items.add(
'reply',
!app.session.user || discussion.canReply()
? Button.component({
icon: 'fas fa-reply',
children: app.translator.trans(
? Button.component(
{
icon: 'fas fa-reply',
onclick: this.replyAction.bind(discussion, true, false),
},
app.translator.trans(
app.session.user ? 'core.forum.discussion_controls.reply_button' : 'core.forum.discussion_controls.log_in_to_reply_button'
),
onclick: this.replyAction.bind(discussion, true, false),
})
: Button.component({
icon: 'fas fa-reply',
children: app.translator.trans('core.forum.discussion_controls.cannot_reply_button'),
className: 'disabled',
title: app.translator.trans('core.forum.discussion_controls.cannot_reply_text'),
})
)
)
: Button.component(
{
icon: 'fas fa-reply',
className: 'disabled',
title: app.translator.trans('core.forum.discussion_controls.cannot_reply_text'),
},
app.translator.trans('core.forum.discussion_controls.cannot_reply_button')
)
);
}
@@ -89,11 +93,13 @@ export default {
if (discussion.canRename()) {
items.add(
'rename',
Button.component({
icon: 'fas fa-pencil-alt',
children: app.translator.trans('core.forum.discussion_controls.rename_button'),
onclick: this.renameAction.bind(discussion),
})
Button.component(
{
icon: 'fas fa-pencil-alt',
onclick: this.renameAction.bind(discussion),
},
app.translator.trans('core.forum.discussion_controls.rename_button')
)
);
}
@@ -116,33 +122,39 @@ export default {
if (discussion.canHide()) {
items.add(
'hide',
Button.component({
icon: 'far fa-trash-alt',
children: app.translator.trans('core.forum.discussion_controls.delete_button'),
onclick: this.hideAction.bind(discussion),
})
Button.component(
{
icon: 'far fa-trash-alt',
onclick: this.hideAction.bind(discussion),
},
app.translator.trans('core.forum.discussion_controls.delete_button')
)
);
}
} else {
if (discussion.canHide()) {
items.add(
'restore',
Button.component({
icon: 'fas fa-reply',
children: app.translator.trans('core.forum.discussion_controls.restore_button'),
onclick: this.restoreAction.bind(discussion),
})
Button.component(
{
icon: 'fas fa-reply',
onclick: this.restoreAction.bind(discussion),
},
app.translator.trans('core.forum.discussion_controls.restore_button')
)
);
}
if (discussion.canDelete()) {
items.add(
'delete',
Button.component({
icon: 'fas fa-times',
children: app.translator.trans('core.forum.discussion_controls.delete_forever_button'),
onclick: this.deleteAction.bind(discussion),
})
Button.component(
{
icon: 'fas fa-times',
onclick: this.deleteAction.bind(discussion),
},
app.translator.trans('core.forum.discussion_controls.delete_forever_button')
)
);
}
}
@@ -163,33 +175,31 @@ export default {
* @return {Promise}
*/
replyAction(goToLast, forceRefresh) {
const deferred = m.deferred();
return new Promise((resolve, reject) => {
if (app.session.user) {
if (this.canReply()) {
if (!app.composer.composingReplyTo(this) || forceRefresh) {
app.composer.load(ReplyComposer, {
user: app.session.user,
discussion: this,
});
}
app.composer.show();
if (app.session.user) {
if (this.canReply()) {
if (!app.composer.composingReplyTo(this) || forceRefresh) {
app.composer.load(ReplyComposer, {
user: app.session.user,
discussion: this,
});
if (goToLast && app.viewingDiscussion(this) && !app.composer.isFullScreen()) {
app.current.get('stream').goToNumber('reply');
}
return resolve(app.composer);
} else {
return reject();
}
app.composer.show();
if (goToLast && app.viewingDiscussion(this) && !app.composer.isFullScreen()) {
app.current.get('stream').goToNumber('reply');
}
deferred.resolve(app.composer);
} else {
deferred.reject();
}
} else {
deferred.reject();
app.modal.show(LogInModal);
}
return deferred.promise;
return reject();
});
},
/**