mirror of
https://github.com/flarum/core.git
synced 2025-08-08 09:26:34 +02:00
update: forum/components/EditPostComponent
This commit is contained in:
committed by
Franz Liedke
parent
31b2ab1b2b
commit
d1a1277f88
@@ -14,38 +14,32 @@ function minimizeComposerIfFullScreen(e) {
|
|||||||
* post. It sets the initial content to the content of the post that is being
|
* post. It sets the initial content to the content of the post that is being
|
||||||
* edited, and adds a header control to indicate which post is being edited.
|
* edited, and adds a header control to indicate which post is being edited.
|
||||||
*
|
*
|
||||||
* ### Props
|
* ### Attrs
|
||||||
*
|
*
|
||||||
* - All of the props for ComposerBody
|
* - All of the attrs for ComposerBody
|
||||||
* - `post`
|
* - `post`
|
||||||
*/
|
*/
|
||||||
export default class EditPostComposer extends ComposerBody {
|
export default class EditPostComposer extends ComposerBody {
|
||||||
static initProps(props) {
|
initAttrs(attrs) {
|
||||||
super.initProps(props);
|
super.initAttrs(attrs);
|
||||||
|
|
||||||
props.submitLabel = props.submitLabel || app.translator.trans('core.forum.composer_edit.submit_button');
|
attrs.submitLabel = attrs.submitLabel || app.translator.trans('core.forum.composer_edit.submit_button');
|
||||||
props.confirmExit = props.confirmExit || app.translator.trans('core.forum.composer_edit.discard_confirmation');
|
attrs.confirmExit = attrs.confirmExit || app.translator.trans('core.forum.composer_edit.discard_confirmation');
|
||||||
props.originalContent = props.originalContent || props.post.content();
|
attrs.originalContent = attrs.originalContent || attrs.post.content();
|
||||||
props.user = props.user || props.post.user();
|
attrs.user = attrs.user || attrs.post.user();
|
||||||
|
|
||||||
props.post.editedContent = props.originalContent;
|
attrs.post.editedContent = attrs.originalContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
headerItems() {
|
headerItems() {
|
||||||
const items = super.headerItems();
|
const items = super.headerItems();
|
||||||
const post = this.props.post;
|
const post = this.attrs.post;
|
||||||
|
|
||||||
const routeAndMinimize = function (element, isInitialized) {
|
|
||||||
if (isInitialized) return;
|
|
||||||
$(element).on('click', minimizeComposerIfFullScreen);
|
|
||||||
m.route.apply(this, arguments);
|
|
||||||
};
|
|
||||||
|
|
||||||
items.add(
|
items.add(
|
||||||
'title',
|
'title',
|
||||||
<h3>
|
<h3>
|
||||||
{icon('fas fa-pencil-alt')}{' '}
|
{icon('fas fa-pencil-alt')}{' '}
|
||||||
<a href={app.route.discussion(post.discussion(), post.number())} config={routeAndMinimize}>
|
<a route={app.route.discussion(post.discussion(), post.number())} onclick={minimizeComposerIfFullScreen}>
|
||||||
{app.translator.trans('core.forum.composer_edit.post_link', { number: post.number(), discussion: post.discussion().title() })}
|
{app.translator.trans('core.forum.composer_edit.post_link', { number: post.number(), discussion: post.discussion().title() })}
|
||||||
</a>
|
</a>
|
||||||
</h3>
|
</h3>
|
||||||
@@ -60,7 +54,7 @@ export default class EditPostComposer extends ComposerBody {
|
|||||||
jumpToPreview(e) {
|
jumpToPreview(e) {
|
||||||
minimizeComposerIfFullScreen(e);
|
minimizeComposerIfFullScreen(e);
|
||||||
|
|
||||||
m.route(app.route.post(this.props.post));
|
m.route.set(app.route.post(this.attrs.post));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,13 +69,13 @@ export default class EditPostComposer extends ComposerBody {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onsubmit() {
|
onsubmit() {
|
||||||
const discussion = this.props.post.discussion();
|
const discussion = this.attrs.post.discussion();
|
||||||
|
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
const data = this.data();
|
const data = this.data();
|
||||||
|
|
||||||
this.props.post.save(data).then((post) => {
|
this.attrs.post.save(data).then((post) => {
|
||||||
// If we're currently viewing the discussion which this edit was made
|
// If we're currently viewing the discussion which this edit was made
|
||||||
// in, then we can scroll to the post.
|
// in, then we can scroll to the post.
|
||||||
if (app.viewingDiscussion(discussion)) {
|
if (app.viewingDiscussion(discussion)) {
|
||||||
@@ -91,17 +85,18 @@ export default class EditPostComposer extends ComposerBody {
|
|||||||
// their edit has been made, containing a button which will
|
// their edit has been made, containing a button which will
|
||||||
// transition to their edited post when clicked.
|
// transition to their edited post when clicked.
|
||||||
let alert;
|
let alert;
|
||||||
const viewButton = Button.component({
|
const viewButton = Button.component(
|
||||||
className: 'Button Button--link',
|
{
|
||||||
children: app.translator.trans('core.forum.composer_edit.view_button'),
|
className: 'Button Button--link',
|
||||||
onclick: () => {
|
onclick: () => {
|
||||||
m.route(app.route.post(post));
|
m.route(app.route.post(post));
|
||||||
app.alerts.dismiss(alert);
|
app.alerts.dismiss(alert);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
app.translator.trans('core.forum.composer_edit.view_button')
|
||||||
alert = app.alerts.show({
|
);
|
||||||
|
alert = app.alerts.show(app.translator.trans('core.forum.composer_edit.edited_message'), {
|
||||||
type: 'success',
|
type: 'success',
|
||||||
children: app.translator.trans('core.forum.composer_edit.edited_message'),
|
|
||||||
controls: [viewButton],
|
controls: [viewButton],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user