import Modal from 'flarum/components/Modal'; import Button from 'flarum/components/Button'; import Badge from 'flarum/components/Badge'; import Group from 'flarum/models/Group'; /** * The `EditGroupModal` component shows a modal dialog which allows the user * to create or edit a group. */ export default class EditGroupModal extends Modal { constructor(...args) { super(...args); this.group = this.props.group || app.store.createRecord('groups'); this.nameSingular = m.prop(this.group.nameSingular() || ''); this.namePlural = m.prop(this.group.namePlural() || ''); this.icon = m.prop(this.group.icon() || ''); this.color = m.prop(this.group.color() || ''); } className() { return 'EditGroupModal Modal--small'; } title() { return [ this.color() || this.icon() ? Badge.component({ icon: this.icon(), style: {backgroundColor: this.color()} }) : '', ' ', this.namePlural() || 'Create Group' ]; } content() { return (
Enter the name of any FontAwesome icon class, without the fa- prefix.
{Button.component({ type: 'submit', className: 'Button Button--primary EditGroupModal-save', loading: this.loading, children: 'Save Changes' })} {this.group.exists && this.group.id() !== Group.ADMINISTRATOR_ID ? ( ) : ''}
); } onsubmit(e) { e.preventDefault(); this.loading = true; this.group.save({ nameSingular: this.nameSingular(), namePlural: this.namePlural(), color: this.color(), icon: this.icon() }).then( () => this.hide(), () => { this.loading = false; m.redraw(); } ); } delete() { if (confirm('Are you sure you want to delete this group? The group members will NOT be deleted.')) { this.group.delete().then(() => m.redraw()); this.hide(); } } }