2015-07-31 20:16:47 +09:30
|
|
|
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 {
|
2015-10-13 16:55:56 +10:30
|
|
|
init() {
|
2015-07-31 20:16:47 +09:30
|
|
|
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()}
|
|
|
|
}) : '',
|
|
|
|
' ',
|
2015-10-05 19:06:41 +09:00
|
|
|
this.namePlural() || app.trans('core.admin.edit_group_title')
|
2015-07-31 20:16:47 +09:30
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
content() {
|
|
|
|
return (
|
|
|
|
<div className="Modal-body">
|
|
|
|
<div className="Form">
|
|
|
|
<div className="Form-group">
|
2015-10-05 19:06:41 +09:00
|
|
|
<label>{app.trans('core.admin.edit_group_name_label')}</label>
|
2015-07-31 20:16:47 +09:30
|
|
|
<div className="EditGroupModal-name-input">
|
|
|
|
<input className="FormControl" placeholder="Singular (e.g. Mod)" value={this.nameSingular()} oninput={m.withAttr('value', this.nameSingular)}/>
|
|
|
|
<input className="FormControl" placeholder="Plural (e.g. Mods)" value={this.namePlural()} oninput={m.withAttr('value', this.namePlural)}/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="Form-group">
|
2015-10-05 19:06:41 +09:00
|
|
|
<label>{app.trans('core.admin.edit_group_color_label')}</label>
|
2015-07-31 20:16:47 +09:30
|
|
|
<input className="FormControl" placeholder="#aaaaaa" value={this.color()} oninput={m.withAttr('value', this.color)}/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="Form-group">
|
2015-10-05 19:06:41 +09:00
|
|
|
<label>{app.trans('core.admin.edit_group_icon_label')}</label>
|
2015-07-31 20:16:47 +09:30
|
|
|
<div className="helpText">
|
2015-10-05 19:06:41 +09:00
|
|
|
{app.trans('core.admin.edit_group_icon_text', {a: <a href="http://fortawesome.github.io/Font-Awesome/icons/" tabindex="-1"/>}, {em: <em/>}, {code: <code/>})}
|
2015-07-31 20:16:47 +09:30
|
|
|
</div>
|
|
|
|
<input className="FormControl" placeholder="bolt" value={this.icon()} oninput={m.withAttr('value', this.icon)}/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="Form-group">
|
|
|
|
{Button.component({
|
|
|
|
type: 'submit',
|
|
|
|
className: 'Button Button--primary EditGroupModal-save',
|
2015-08-02 17:25:05 +09:30
|
|
|
loading: this.loading,
|
2015-10-05 19:06:41 +09:00
|
|
|
children: app.trans('core.admin.edit_group_submit_button')
|
2015-07-31 20:16:47 +09:30
|
|
|
})}
|
|
|
|
{this.group.exists && this.group.id() !== Group.ADMINISTRATOR_ID ? (
|
|
|
|
<button type="button" className="Button EditGroupModal-delete" onclick={this.delete.bind(this)}>
|
2015-10-05 19:06:41 +09:00
|
|
|
{app.trans('core.admin.edit_group_delete_button')}
|
2015-07-31 20:16:47 +09:30
|
|
|
</button>
|
|
|
|
) : ''}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
onsubmit(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
2015-08-02 17:25:05 +09:30
|
|
|
this.loading = true;
|
2015-07-31 20:16:47 +09:30
|
|
|
|
|
|
|
this.group.save({
|
|
|
|
nameSingular: this.nameSingular(),
|
|
|
|
namePlural: this.namePlural(),
|
|
|
|
color: this.color(),
|
|
|
|
icon: this.icon()
|
|
|
|
}).then(
|
|
|
|
() => this.hide(),
|
|
|
|
() => {
|
2015-08-02 17:25:05 +09:30
|
|
|
this.loading = false;
|
2015-07-31 20:16:47 +09:30
|
|
|
m.redraw();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete() {
|
2015-10-05 19:06:41 +09:00
|
|
|
if (confirm(app.trans('core.admin.edit_group_delete_confirmation'))) {
|
2015-07-31 20:16:47 +09:30
|
|
|
this.group.delete().then(() => m.redraw());
|
|
|
|
this.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|