mirror of
https://github.com/flarum/core.git
synced 2025-07-26 19:20:21 +02:00
committed by
GitHub
parent
ecf174d62f
commit
b26a9af51f
@@ -1,11 +1,13 @@
|
|||||||
import Modal from 'flarum/components/Modal';
|
import Modal from 'flarum/components/Modal';
|
||||||
import Button from 'flarum/components/Button';
|
import Button from 'flarum/components/Button';
|
||||||
|
|
||||||
export default class SuspendUserModal extends Modal {
|
import withAttr from 'flarum/utils/withAttr';
|
||||||
init() {
|
|
||||||
super.init();
|
|
||||||
|
|
||||||
let until = this.props.user.suspendedUntil();
|
export default class SuspendUserModal extends Modal {
|
||||||
|
oninit(vnode) {
|
||||||
|
super.oninit(vnode);
|
||||||
|
|
||||||
|
let until = this.attrs.user.suspendedUntil();
|
||||||
let status = null;
|
let status = null;
|
||||||
|
|
||||||
if (new Date() > until) until = null;
|
if (new Date() > until) until = null;
|
||||||
@@ -15,8 +17,8 @@ export default class SuspendUserModal extends Modal {
|
|||||||
else status = 'limited';
|
else status = 'limited';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.status = m.prop(status);
|
this.status = m.stream(status);
|
||||||
this.daysRemaining = m.prop(status === 'limited' && -dayjs().diff(until, 'days') + 1);
|
this.daysRemaining = m.stream(status === 'limited' && -dayjs().diff(until, 'days') + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
className() {
|
className() {
|
||||||
@@ -24,7 +26,7 @@ export default class SuspendUserModal extends Modal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
title() {
|
title() {
|
||||||
return app.translator.trans('flarum-suspend.forum.suspend_user.title', {user: this.props.user});
|
return app.translator.trans('flarum-suspend.forum.suspend_user.title', {user: this.attrs.user});
|
||||||
}
|
}
|
||||||
|
|
||||||
content() {
|
content() {
|
||||||
@@ -35,21 +37,21 @@ export default class SuspendUserModal extends Modal {
|
|||||||
<label>{app.translator.trans('flarum-suspend.forum.suspend_user.status_heading')}</label>
|
<label>{app.translator.trans('flarum-suspend.forum.suspend_user.status_heading')}</label>
|
||||||
<div>
|
<div>
|
||||||
<label className="checkbox">
|
<label className="checkbox">
|
||||||
<input type="radio" name="status" checked={!this.status()} value="" onclick={m.withAttr('value', this.status)}/>
|
<input type="radio" name="status" checked={!this.status()} value="" onclick={withAttr('value', this.status)}/>
|
||||||
{app.translator.trans('flarum-suspend.forum.suspend_user.not_suspended_label')}
|
{app.translator.trans('flarum-suspend.forum.suspend_user.not_suspended_label')}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label className="checkbox">
|
<label className="checkbox">
|
||||||
<input type="radio" name="status" checked={this.status() === 'indefinitely'} value='indefinitely' onclick={m.withAttr('value', this.status)}/>
|
<input type="radio" name="status" checked={this.status() === 'indefinitely'} value='indefinitely' onclick={withAttr('value', this.status)}/>
|
||||||
{app.translator.trans('flarum-suspend.forum.suspend_user.indefinitely_label')}
|
{app.translator.trans('flarum-suspend.forum.suspend_user.indefinitely_label')}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label className="checkbox SuspendUserModal-days">
|
<label className="checkbox SuspendUserModal-days">
|
||||||
<input type="radio" name="status" checked={this.status() === 'limited'} value='limited' onclick={e => {
|
<input type="radio" name="status" checked={this.status() === 'limited'} value='limited' onclick={e => {
|
||||||
this.status(e.target.value);
|
this.status(e.target.value);
|
||||||
m.redraw(true);
|
m.redraw.sync();
|
||||||
this.$('.SuspendUserModal-days-input input').select();
|
this.$('.SuspendUserModal-days-input input').select();
|
||||||
m.redraw.strategy('none');
|
e.redraw = false;
|
||||||
}}/>
|
}}/>
|
||||||
{app.translator.trans('flarum-suspend.forum.suspend_user.limited_time_label')}
|
{app.translator.trans('flarum-suspend.forum.suspend_user.limited_time_label')}
|
||||||
{this.status() === 'limited' ? (
|
{this.status() === 'limited' ? (
|
||||||
@@ -57,7 +59,7 @@ export default class SuspendUserModal extends Modal {
|
|||||||
<input type="number"
|
<input type="number"
|
||||||
min="0"
|
min="0"
|
||||||
value={this.daysRemaining()}
|
value={this.daysRemaining()}
|
||||||
oninput={m.withAttr('value', this.daysRemaining)}
|
oninput={withAttr('value', this.daysRemaining)}
|
||||||
className="FormControl"/>
|
className="FormControl"/>
|
||||||
{app.translator.trans('flarum-suspend.forum.suspend_user.limited_time_days_text')}
|
{app.translator.trans('flarum-suspend.forum.suspend_user.limited_time_days_text')}
|
||||||
</div>
|
</div>
|
||||||
@@ -95,7 +97,7 @@ export default class SuspendUserModal extends Modal {
|
|||||||
// no default
|
// no default
|
||||||
}
|
}
|
||||||
|
|
||||||
this.props.user.save({suspendedUntil}).then(
|
this.attrs.user.save({suspendedUntil}).then(
|
||||||
() => this.hide(),
|
() => this.hide(),
|
||||||
this.loaded.bind(this)
|
this.loaded.bind(this)
|
||||||
);
|
);
|
||||||
|
@@ -6,11 +6,11 @@ export default class UserSuspendedNotification extends Notification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
href() {
|
href() {
|
||||||
return app.route.user(this.props.notification.subject());
|
return app.route.user(this.attrs.notification.subject());
|
||||||
}
|
}
|
||||||
|
|
||||||
content() {
|
content() {
|
||||||
const notification = this.props.notification;
|
const notification = this.attrs.notification;
|
||||||
const suspendedUntil = notification.content();
|
const suspendedUntil = notification.content();
|
||||||
const timeReadable = dayjs(suspendedUntil.date).from(notification.createdAt(), true);
|
const timeReadable = dayjs(suspendedUntil.date).from(notification.createdAt(), true);
|
||||||
|
|
||||||
|
@@ -6,11 +6,11 @@ export default class UserUnsuspendedNotification extends Notification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
href() {
|
href() {
|
||||||
return app.route.user(this.props.notification.subject());
|
return app.route.user(this.attrs.notification.subject());
|
||||||
}
|
}
|
||||||
|
|
||||||
content() {
|
content() {
|
||||||
const notification = this.props.notification;
|
const notification = this.attrs.notification;
|
||||||
|
|
||||||
return app.translator.trans('flarum-suspend.forum.notifications.user_unsuspended_text', {
|
return app.translator.trans('flarum-suspend.forum.notifications.user_unsuspended_text', {
|
||||||
user: notification.fromUser(),
|
user: notification.fromUser(),
|
||||||
|
@@ -20,10 +20,9 @@ app.initializers.add('flarum-suspend', () => {
|
|||||||
extend(UserControls, 'moderationControls', (items, user) => {
|
extend(UserControls, 'moderationControls', (items, user) => {
|
||||||
if (user.canSuspend()) {
|
if (user.canSuspend()) {
|
||||||
items.add('suspend', Button.component({
|
items.add('suspend', Button.component({
|
||||||
children: app.translator.trans('flarum-suspend.forum.user_controls.suspend_button'),
|
|
||||||
icon: 'fas fa-ban',
|
icon: 'fas fa-ban',
|
||||||
onclick: () => app.modal.show(SuspendUserModal, {user})
|
onclick: () => app.modal.show(SuspendUserModal, {user})
|
||||||
}));
|
}, app.translator.trans('flarum-suspend.forum.user_controls.suspend_button')));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user