mirror of
https://github.com/flarum/core.git
synced 2025-07-21 08:41:17 +02:00
Allow custom variables to be set on the client app
This commit is contained in:
@@ -8,8 +8,8 @@ const app = new App();
|
||||
|
||||
app.initializers.add('store', store);
|
||||
app.initializers.add('routes', routes);
|
||||
app.initializers.add('preload', preload, -100);
|
||||
|
||||
app.initializers.add('preload', preload, -100);
|
||||
app.initializers.add('boot', boot, -100);
|
||||
|
||||
export default app;
|
||||
|
@@ -2,6 +2,8 @@ import Component from 'flarum/Component';
|
||||
import FieldSet from 'flarum/components/FieldSet';
|
||||
import Select from 'flarum/components/Select';
|
||||
import Button from 'flarum/components/Button';
|
||||
import Alert from 'flarum/components/Alert';
|
||||
import saveConfig from 'flarum/utils/saveConfig';
|
||||
|
||||
export default class BasicsPage extends Component {
|
||||
constructor(...args) {
|
||||
@@ -19,11 +21,11 @@ export default class BasicsPage extends Component {
|
||||
];
|
||||
this.values = {};
|
||||
|
||||
const config = app.forum.attribute('config');
|
||||
const config = app.config;
|
||||
this.fields.forEach(key => this.values[key] = m.prop(config[key]));
|
||||
|
||||
this.localeOptions = {};
|
||||
const locales = app.forum.attribute('availableLocales');
|
||||
const locales = app.locales;
|
||||
for (const i in locales) {
|
||||
this.localeOptions[i] = `${locales[i]} (${i})`;
|
||||
}
|
||||
@@ -113,7 +115,7 @@ export default class BasicsPage extends Component {
|
||||
}
|
||||
|
||||
changed() {
|
||||
const config = app.forum.attribute('config');
|
||||
const config = app.config;
|
||||
|
||||
return this.fields.some(key => this.values[key]() !== config[key]);
|
||||
}
|
||||
@@ -124,14 +126,19 @@ export default class BasicsPage extends Component {
|
||||
if (this.loading) return;
|
||||
|
||||
this.loading = true;
|
||||
app.alerts.dismiss(this.successAlert);
|
||||
|
||||
const config = {};
|
||||
|
||||
this.fields.forEach(key => config[key] = this.values[key]());
|
||||
|
||||
app.forum.save({config}).finally(() => {
|
||||
this.loading = false;
|
||||
m.redraw();
|
||||
});
|
||||
saveConfig(config)
|
||||
.then(() => {
|
||||
app.alerts.show(this.successAlert = new Alert({type: 'success', children: 'Your changes were saved.'}));
|
||||
})
|
||||
.finally(() => {
|
||||
this.loading = false;
|
||||
m.redraw();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
14
framework/core/js/admin/src/utils/saveConfig.js
Normal file
14
framework/core/js/admin/src/utils/saveConfig.js
Normal file
@@ -0,0 +1,14 @@
|
||||
export default function saveConfig(config) {
|
||||
const oldConfig = JSON.parse(JSON.stringify(app.config));
|
||||
|
||||
Object.assign(app.config, config);
|
||||
|
||||
return app.request({
|
||||
method: 'POST',
|
||||
url: app.forum.attribute('adminUrl') + '/config',
|
||||
data: {config}
|
||||
}).catch(error => {
|
||||
app.config = oldConfig;
|
||||
throw error;
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user