mirror of
https://github.com/flarum/core.git
synced 2025-08-08 09:26:34 +02:00
Use SettingsModal component
This commit is contained in:
@@ -1,17 +1,6 @@
|
|||||||
import Modal from 'flarum/components/Modal';
|
import SettingsModal from 'flarum/components/SettingsModal';
|
||||||
import Button from 'flarum/components/Button';
|
|
||||||
import saveConfig from 'flarum/utils/saveConfig';
|
|
||||||
|
|
||||||
export default class TagSettingsModal extends Modal {
|
|
||||||
constructor(...args) {
|
|
||||||
super(...args);
|
|
||||||
|
|
||||||
this.minPrimaryTags = m.prop(app.config['tags.min_primary_tags'] || 0);
|
|
||||||
this.maxPrimaryTags = m.prop(app.config['tags.max_primary_tags'] || 0);
|
|
||||||
this.minSecondaryTags = m.prop(app.config['tags.min_secondary_tags'] || 0);
|
|
||||||
this.maxSecondaryTags = m.prop(app.config['tags.max_secondary_tags'] || 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
export default class TagSettingsModal extends SettingsModal {
|
||||||
setMinTags(minTags, maxTags, value) {
|
setMinTags(minTags, maxTags, value) {
|
||||||
minTags(value);
|
minTags(value);
|
||||||
maxTags(Math.max(value, maxTags()));
|
maxTags(Math.max(value, maxTags()));
|
||||||
@@ -25,83 +14,51 @@ export default class TagSettingsModal extends Modal {
|
|||||||
return 'Tag Settings';
|
return 'Tag Settings';
|
||||||
}
|
}
|
||||||
|
|
||||||
content() {
|
form() {
|
||||||
return (
|
const minPrimaryTags = this.setting('tags.min_primary_tags', 0);
|
||||||
<div className="Modal-body">
|
const maxPrimaryTags = this.setting('tags.max_primary_tags', 0);
|
||||||
<div className="Form">
|
|
||||||
<div className="Form-group">
|
|
||||||
<label>Required Number of Primary Tags</label>
|
|
||||||
<div className="helpText">
|
|
||||||
Enter the minimum and maximum number of primary tags that may be applied to a discussion.
|
|
||||||
</div>
|
|
||||||
<div className="TagSettingsModal-rangeInput">
|
|
||||||
<input className="FormControl"
|
|
||||||
type="number"
|
|
||||||
min="0"
|
|
||||||
value={this.minPrimaryTags()}
|
|
||||||
oninput={m.withAttr('value', this.setMinTags.bind(this, this.minPrimaryTags, this.maxPrimaryTags))}
|
|
||||||
/>
|
|
||||||
{' to '}
|
|
||||||
<input className="FormControl"
|
|
||||||
type="number"
|
|
||||||
min={this.minPrimaryTags()}
|
|
||||||
value={this.maxPrimaryTags()}
|
|
||||||
oninput={m.withAttr('value', this.maxPrimaryTags)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="Form-group">
|
const minSecondaryTags = this.setting('tags.min_secondary_tags', 0);
|
||||||
<label>Required Number of Secondary Tags</label>
|
const maxSecondaryTags = this.setting('tags.max_secondary_tags', 0);
|
||||||
<div className="helpText">
|
|
||||||
Enter the minimum and maximum number of secondary tags that may be applied to a discussion.
|
|
||||||
</div>
|
|
||||||
<div className="TagSettingsModal-rangeInput">
|
|
||||||
<input className="FormControl"
|
|
||||||
type="number"
|
|
||||||
min="0"
|
|
||||||
value={this.minSecondaryTags()}
|
|
||||||
oninput={m.withAttr('value', this.setMinTags.bind(this, this.minSecondaryTags, this.maxSecondaryTags))}
|
|
||||||
/>
|
|
||||||
{' to '}
|
|
||||||
<input className="FormControl"
|
|
||||||
type="number"
|
|
||||||
min={this.minSecondaryTags()}
|
|
||||||
value={this.maxSecondaryTags()}
|
|
||||||
oninput={m.withAttr('value', this.maxSecondaryTags)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="Form-group">
|
return [
|
||||||
{Button.component({
|
<div className="Form-group">
|
||||||
type: 'submit',
|
<label>Required Number of Primary Tags</label>
|
||||||
className: 'Button Button--primary TagSettingsModal-save',
|
<div className="helpText">
|
||||||
loading: this.loading,
|
Enter the minimum and maximum number of primary tags that may be applied to a discussion.
|
||||||
children: 'Save Changes'
|
</div>
|
||||||
})}
|
<div className="TagSettingsModal-rangeInput">
|
||||||
</div>
|
<input className="FormControl"
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
value={minPrimaryTags()}
|
||||||
|
oninput={m.withAttr('value', this.setMinTags.bind(this, minPrimaryTags, maxPrimaryTags))} />
|
||||||
|
{' to '}
|
||||||
|
<input className="FormControl"
|
||||||
|
type="number"
|
||||||
|
min={minPrimaryTags()}
|
||||||
|
bidi={maxPrimaryTags} />
|
||||||
|
</div>
|
||||||
|
</div>,
|
||||||
|
|
||||||
|
<div className="Form-group">
|
||||||
|
<label>Required Number of Secondary Tags</label>
|
||||||
|
<div className="helpText">
|
||||||
|
Enter the minimum and maximum number of secondary tags that may be applied to a discussion.
|
||||||
|
</div>
|
||||||
|
<div className="TagSettingsModal-rangeInput">
|
||||||
|
<input className="FormControl"
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
value={minSecondaryTags()}
|
||||||
|
oninput={m.withAttr('value', this.setMinTags.bind(this, minSecondaryTags, maxSecondaryTags))} />
|
||||||
|
{' to '}
|
||||||
|
<input className="FormControl"
|
||||||
|
type="number"
|
||||||
|
min={minSecondaryTags()}
|
||||||
|
bidi={maxSecondaryTags} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
];
|
||||||
}
|
|
||||||
|
|
||||||
onsubmit(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
this.loading = true;
|
|
||||||
|
|
||||||
saveConfig({
|
|
||||||
'tags.min_primary_tags': this.minPrimaryTags(),
|
|
||||||
'tags.max_primary_tags': this.maxPrimaryTags(),
|
|
||||||
'tags.min_secondary_tags': this.minSecondaryTags(),
|
|
||||||
'tags.max_secondary_tags': this.maxSecondaryTags()
|
|
||||||
}).then(
|
|
||||||
() => this.hide(),
|
|
||||||
() => {
|
|
||||||
this.loading = false;
|
|
||||||
m.redraw();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user