mirror of
https://github.com/flarum/core.git
synced 2025-08-03 06:57:54 +02:00
committed by
GitHub
parent
94c4b37799
commit
df74cc4a96
@@ -7,14 +7,14 @@ import PostControls from 'flarum/utils/PostControls';
|
|||||||
import humanTime from 'flarum/utils/humanTime';
|
import humanTime from 'flarum/utils/humanTime';
|
||||||
|
|
||||||
export default function() {
|
export default function() {
|
||||||
extend(Post.prototype, 'attrs', function(attrs) {
|
extend(Post.prototype, 'elementAttrs', function(attrs) {
|
||||||
if (this.props.post.flags().length) {
|
if (this.attrs.post.flags().length) {
|
||||||
attrs.className += ' Post--flagged';
|
attrs.className += ' Post--flagged';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Post.prototype.dismissFlag = function(data) {
|
Post.prototype.dismissFlag = function(body) {
|
||||||
const post = this.props.post;
|
const post = this.attrs.post;
|
||||||
|
|
||||||
delete post.data.relationships.flags;
|
delete post.data.relationships.flags;
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ export default function() {
|
|||||||
if (next) {
|
if (next) {
|
||||||
const nextPost = next.post();
|
const nextPost = next.post();
|
||||||
app.flags.index = nextPost;
|
app.flags.index = nextPost;
|
||||||
m.route(app.route.post(nextPost));
|
m.route.set(app.route.post(nextPost));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,21 +45,21 @@ export default function() {
|
|||||||
return app.request({
|
return app.request({
|
||||||
url: app.forum.attribute('apiUrl') + post.apiEndpoint() + '/flags',
|
url: app.forum.attribute('apiUrl') + post.apiEndpoint() + '/flags',
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
data
|
body
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Post.prototype.flagActionItems = function() {
|
Post.prototype.flagActionItems = function() {
|
||||||
const items = new ItemList();
|
const items = new ItemList();
|
||||||
|
|
||||||
const controls = PostControls.destructiveControls(this.props.post);
|
const controls = PostControls.destructiveControls(this.attrs.post);
|
||||||
|
|
||||||
Object.keys(controls.items).forEach(k => {
|
Object.keys(controls.items).forEach(k => {
|
||||||
const props = controls.get(k).props;
|
const attrs = controls.get(k).attrs;
|
||||||
|
|
||||||
props.className = 'Button';
|
attrs.className = 'Button';
|
||||||
|
|
||||||
extend(props, 'onclick', () => this.dismissFlag());
|
extend(attrs, 'onclick', () => this.dismissFlag());
|
||||||
});
|
});
|
||||||
|
|
||||||
items.add('controls', (
|
items.add('controls', (
|
||||||
@@ -78,7 +78,7 @@ export default function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extend(Post.prototype, 'content', function(vdom) {
|
extend(Post.prototype, 'content', function(vdom) {
|
||||||
const post = this.props.post;
|
const post = this.attrs.post;
|
||||||
const flags = post.flags();
|
const flags = post.flags();
|
||||||
|
|
||||||
if (!flags.length) return;
|
if (!flags.length) return;
|
||||||
|
@@ -6,8 +6,9 @@ import icon from 'flarum/helpers/icon';
|
|||||||
import humanTime from 'flarum/helpers/humanTime';
|
import humanTime from 'flarum/helpers/humanTime';
|
||||||
|
|
||||||
export default class FlagList extends Component {
|
export default class FlagList extends Component {
|
||||||
init() {
|
oninit(vnode) {
|
||||||
this.state = this.props.state;
|
super.oninit(vnode);
|
||||||
|
this.state = this.attrs.state;
|
||||||
}
|
}
|
||||||
|
|
||||||
view() {
|
view() {
|
||||||
@@ -26,10 +27,9 @@ export default class FlagList extends Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<li>
|
<li>
|
||||||
<a href={app.route.post(post)} className="Notification Flag" config={function(element, isInitialized) {
|
<a route={app.route.post(post)} className="Notification Flag" onclick={e => {
|
||||||
m.route.apply(this, arguments);
|
app.flags.index = post;
|
||||||
|
e.redraw = false;
|
||||||
if (!isInitialized) $(element).on('click', () => app.flags.index = post);
|
|
||||||
}}>
|
}}>
|
||||||
{avatar(post.user())}
|
{avatar(post.user())}
|
||||||
{icon('fas fa-flag', {className: 'Notification-icon'})}
|
{icon('fas fa-flag', {className: 'Notification-icon'})}
|
||||||
|
@@ -1,14 +1,16 @@
|
|||||||
import Modal from 'flarum/components/Modal';
|
import Modal from 'flarum/components/Modal';
|
||||||
import Button from 'flarum/components/Button';
|
import Button from 'flarum/components/Button';
|
||||||
|
|
||||||
|
import withAttr from 'flarum/utils/withAttr';
|
||||||
|
|
||||||
export default class FlagPostModal extends Modal {
|
export default class FlagPostModal extends Modal {
|
||||||
init() {
|
oninit(vnode) {
|
||||||
super.init();
|
super.oninit(vnode);
|
||||||
|
|
||||||
this.success = false;
|
this.success = false;
|
||||||
|
|
||||||
this.reason = m.prop('');
|
this.reason = m.stream('');
|
||||||
this.reasonDetail = m.prop('');
|
this.reasonDetail = m.stream('');
|
||||||
}
|
}
|
||||||
|
|
||||||
className() {
|
className() {
|
||||||
@@ -43,39 +45,39 @@ export default class FlagPostModal extends Modal {
|
|||||||
<div className="Form-group">
|
<div className="Form-group">
|
||||||
<div>
|
<div>
|
||||||
<label className="checkbox">
|
<label className="checkbox">
|
||||||
<input type="radio" name="reason" checked={this.reason() === 'off_topic'} value="off_topic" onclick={m.withAttr('value', this.reason)}/>
|
<input type="radio" name="reason" checked={this.reason() === 'off_topic'} value="off_topic" onclick={withAttr('value', this.reason)}/>
|
||||||
<strong>{app.translator.trans('flarum-flags.forum.flag_post.reason_off_topic_label')}</strong>
|
<strong>{app.translator.trans('flarum-flags.forum.flag_post.reason_off_topic_label')}</strong>
|
||||||
{app.translator.trans('flarum-flags.forum.flag_post.reason_off_topic_text')}
|
{app.translator.trans('flarum-flags.forum.flag_post.reason_off_topic_text')}
|
||||||
{this.reason() === 'off_topic' ? (
|
{this.reason() === 'off_topic' ? (
|
||||||
<textarea className="FormControl" placeholder={app.translator.trans('flarum-flags.forum.flag_post.reason_details_placeholder')} value={this.reasonDetail()} oninput={m.withAttr('value', this.reasonDetail)}></textarea>
|
<textarea className="FormControl" placeholder={app.translator.trans('flarum-flags.forum.flag_post.reason_details_placeholder')} value={this.reasonDetail()} oninput={withAttr('value', this.reasonDetail)}></textarea>
|
||||||
) : ''}
|
) : ''}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label className="checkbox">
|
<label className="checkbox">
|
||||||
<input type="radio" name="reason" checked={this.reason() === 'inappropriate'} value="inappropriate" onclick={m.withAttr('value', this.reason)}/>
|
<input type="radio" name="reason" checked={this.reason() === 'inappropriate'} value="inappropriate" onclick={withAttr('value', this.reason)}/>
|
||||||
<strong>{app.translator.trans('flarum-flags.forum.flag_post.reason_inappropriate_label')}</strong>
|
<strong>{app.translator.trans('flarum-flags.forum.flag_post.reason_inappropriate_label')}</strong>
|
||||||
{app.translator.trans('flarum-flags.forum.flag_post.reason_inappropriate_text', {
|
{app.translator.trans('flarum-flags.forum.flag_post.reason_inappropriate_text', {
|
||||||
a: guidelinesUrl ? <a href={guidelinesUrl} target="_blank"/> : undefined
|
a: guidelinesUrl ? <a href={guidelinesUrl} target="_blank"/> : undefined
|
||||||
})}
|
})}
|
||||||
{this.reason() === 'inappropriate' ? (
|
{this.reason() === 'inappropriate' ? (
|
||||||
<textarea className="FormControl" placeholder={app.translator.trans('flarum-flags.forum.flag_post.reason_details_placeholder')} value={this.reasonDetail()} oninput={m.withAttr('value', this.reasonDetail)}></textarea>
|
<textarea className="FormControl" placeholder={app.translator.trans('flarum-flags.forum.flag_post.reason_details_placeholder')} value={this.reasonDetail()} oninput={withAttr('value', this.reasonDetail)}></textarea>
|
||||||
) : ''}
|
) : ''}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label className="checkbox">
|
<label className="checkbox">
|
||||||
<input type="radio" name="reason" checked={this.reason() === 'spam'} value="spam" onclick={m.withAttr('value', this.reason)}/>
|
<input type="radio" name="reason" checked={this.reason() === 'spam'} value="spam" onclick={withAttr('value', this.reason)}/>
|
||||||
<strong>{app.translator.trans('flarum-flags.forum.flag_post.reason_spam_label')}</strong>
|
<strong>{app.translator.trans('flarum-flags.forum.flag_post.reason_spam_label')}</strong>
|
||||||
{app.translator.trans('flarum-flags.forum.flag_post.reason_spam_text')}
|
{app.translator.trans('flarum-flags.forum.flag_post.reason_spam_text')}
|
||||||
{this.reason() === 'spam' ? (
|
{this.reason() === 'spam' ? (
|
||||||
<textarea className="FormControl" placeholder={app.translator.trans('flarum-flags.forum.flag_post.reason_details_placeholder')} value={this.reasonDetail()} oninput={m.withAttr('value', this.reasonDetail)}></textarea>
|
<textarea className="FormControl" placeholder={app.translator.trans('flarum-flags.forum.flag_post.reason_details_placeholder')} value={this.reasonDetail()} oninput={withAttr('value', this.reasonDetail)}></textarea>
|
||||||
) : ''}
|
) : ''}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label className="checkbox">
|
<label className="checkbox">
|
||||||
<input type="radio" name="reason" checked={this.reason() === 'other'} value="other" onclick={m.withAttr('value', this.reason)}/>
|
<input type="radio" name="reason" checked={this.reason() === 'other'} value="other" onclick={withAttr('value', this.reason)}/>
|
||||||
<strong>{app.translator.trans('flarum-flags.forum.flag_post.reason_other_label')}</strong>
|
<strong>{app.translator.trans('flarum-flags.forum.flag_post.reason_other_label')}</strong>
|
||||||
{this.reason() === 'other' ? (
|
{this.reason() === 'other' ? (
|
||||||
<textarea className="FormControl" value={this.reasonDetail()} oninput={m.withAttr('value', this.reasonDetail)}></textarea>
|
<textarea className="FormControl" value={this.reasonDetail()} oninput={withAttr('value', this.reasonDetail)}></textarea>
|
||||||
) : ''}
|
) : ''}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
@@ -105,7 +107,7 @@ export default class FlagPostModal extends Modal {
|
|||||||
reasonDetail: this.reasonDetail(),
|
reasonDetail: this.reasonDetail(),
|
||||||
relationships: {
|
relationships: {
|
||||||
user: app.session.user,
|
user: app.session.user,
|
||||||
post: this.props.post
|
post: this.attrs.post
|
||||||
}
|
}
|
||||||
}, {errorHandler: this.onerror.bind(this)})
|
}, {errorHandler: this.onerror.bind(this)})
|
||||||
.then(() => this.success = true)
|
.then(() => this.success = true)
|
||||||
|
@@ -3,23 +3,23 @@ import NotificationsDropdown from 'flarum/components/NotificationsDropdown';
|
|||||||
import FlagList from './FlagList';
|
import FlagList from './FlagList';
|
||||||
|
|
||||||
export default class FlagsDropdown extends NotificationsDropdown {
|
export default class FlagsDropdown extends NotificationsDropdown {
|
||||||
static initProps(props) {
|
static initAttrs(attrs) {
|
||||||
props.label = props.label || app.translator.trans('flarum-flags.forum.flagged_posts.tooltip');
|
attrs.label = attrs.label || app.translator.trans('flarum-flags.forum.flagged_posts.tooltip');
|
||||||
props.icon = props.icon || 'fas fa-flag';
|
attrs.icon = attrs.icon || 'fas fa-flag';
|
||||||
|
|
||||||
super.initProps(props);
|
super.initAttrs(attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
getMenu() {
|
getMenu() {
|
||||||
return (
|
return (
|
||||||
<div className={'Dropdown-menu ' + this.props.menuClassName} onclick={this.menuClick.bind(this)}>
|
<div className={'Dropdown-menu ' + this.attrs.menuClassName} onclick={this.menuClick.bind(this)}>
|
||||||
{this.showing ? FlagList.component({ state: this.props.state }) : ''}
|
{this.showing ? FlagList.component({ state: this.attrs.state }) : ''}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
goToRoute() {
|
goToRoute() {
|
||||||
m.route(app.route('flags'));
|
m.route.set(app.route('flags'));
|
||||||
}
|
}
|
||||||
|
|
||||||
getUnreadCount() {
|
getUnreadCount() {
|
||||||
|
@@ -7,8 +7,8 @@ import FlagList from './FlagList';
|
|||||||
* used on mobile devices where the flags dropdown is within the drawer.
|
* used on mobile devices where the flags dropdown is within the drawer.
|
||||||
*/
|
*/
|
||||||
export default class FlagsPage extends Page {
|
export default class FlagsPage extends Page {
|
||||||
init() {
|
oninit(vnode) {
|
||||||
super.init();
|
super.oninit(vnode);
|
||||||
|
|
||||||
app.history.push('flags');
|
app.history.push('flags');
|
||||||
|
|
||||||
|
@@ -14,7 +14,7 @@ app.initializers.add('flarum-flags', () => {
|
|||||||
|
|
||||||
app.store.models.flags = Flag;
|
app.store.models.flags = Flag;
|
||||||
|
|
||||||
app.routes.flags = { path: '/flags', component: <FlagsPage /> };
|
app.routes.flags = { path: '/flags', component: FlagsPage };
|
||||||
|
|
||||||
app.flags = new FlagListState(app);
|
app.flags = new FlagListState(app);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user