import Modal from 'flarum/components/Modal'; import Button from 'flarum/components/Button'; export default class FlagPostModal extends Modal { init() { super.init(); this.success = false; this.reason = m.prop(''); this.reasonDetail = m.prop(''); } className() { return 'FlagPostModal Modal--medium'; } title() { return app.translator.trans('flarum-flags.forum.flag_post.title'); } content() { if (this.success) { return (

{app.translator.trans('flarum-flags.forum.flag_post.confirmation_message')}

); } const guidelinesUrl = app.forum.attribute('guidelinesUrl'); return (
); } onsubmit(e) { e.preventDefault(); this.loading = true; app.store.createRecord('flags').save({ reason: this.reason() === 'other' ? null : this.reason(), reasonDetail: this.reasonDetail(), relationships: { user: app.session.user, post: this.props.post } }, {errorHandler: this.onerror.bind(this)}) .then(() => this.success = true) .catch(() => {}) .then(this.loaded.bind(this)); } onerror(error) { if (error.status === 422) { error.alert.props.children = app.translator.trans('flarum-flags.forum.flag_post.reason-needed'); } super.onerror(error); } }