import Modal from '../../common/components/Modal'; import Button from '../../common/components/Button'; import Badge from '../../common/components/Badge'; import Group from '../../common/models/Group'; import ItemList from '../../common/utils/ItemList'; /** * The `EditGroupModal` component shows a modal dialog which allows the user * to create or edit a group. */ export default class EditGroupModal extends Modal { init() { 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() || app.translator.trans('core.admin.edit_group.title'), ]; } content() { return (
{this.fields().toArray()}
); } fields() { const items = new ItemList(); items.add( 'name',
, 30 ); items.add( 'color',
, 20 ); items.add( 'icon',
{app.translator.trans('core.admin.edit_group.icon_text', { a: })}
, 10 ); items.add( 'submit',
{Button.component({ type: 'submit', className: 'Button Button--primary EditGroupModal-save', loading: this.loading, children: app.translator.trans('core.admin.edit_group.submit_button'), })} {this.group.exists && this.group.id() !== Group.ADMINISTRATOR_ID ? ( ) : ( '' )}
, -10 ); return items; } submitData() { return { nameSingular: this.nameSingular(), namePlural: this.namePlural(), color: this.color(), icon: this.icon(), }; } onsubmit(e) { e.preventDefault(); this.loading = true; this.group .save(this.submitData(), { errorHandler: this.onerror.bind(this) }) .then(this.hide.bind(this)) .catch(() => { this.loading = false; m.redraw(); }); } deleteGroup() { if (confirm(app.translator.trans('core.admin.edit_group.delete_confirmation'))) { this.group.delete().then(() => m.redraw()); this.hide(); } } }