diff --git a/framework/core/js/admin/src/app.js b/framework/core/js/admin/src/app.js index a479ada87..16c8a9a59 100644 --- a/framework/core/js/admin/src/app.js +++ b/framework/core/js/admin/src/app.js @@ -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; diff --git a/framework/core/js/admin/src/components/BasicsPage.js b/framework/core/js/admin/src/components/BasicsPage.js index a3d8f2f69..9279ee089 100644 --- a/framework/core/js/admin/src/components/BasicsPage.js +++ b/framework/core/js/admin/src/components/BasicsPage.js @@ -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(); + }); } } diff --git a/framework/core/js/admin/src/utils/saveConfig.js b/framework/core/js/admin/src/utils/saveConfig.js new file mode 100644 index 000000000..b17787ab1 --- /dev/null +++ b/framework/core/js/admin/src/utils/saveConfig.js @@ -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; + }); +} diff --git a/framework/core/src/Admin/Actions/ClientAction.php b/framework/core/src/Admin/Actions/ClientAction.php index fa72b8d67..c384f01d8 100644 --- a/framework/core/src/Admin/Actions/ClientAction.php +++ b/framework/core/src/Admin/Actions/ClientAction.php @@ -1,6 +1,8 @@ setVariable('config', $this->settings->all()); + $view->setVariable('locales', app('flarum.localeManager')->getLocales()); + $view->setVariable('permissions', Permission::map()); + + return $view; + } } diff --git a/framework/core/src/Api/Serializers/ForumSerializer.php b/framework/core/src/Api/Serializers/ForumSerializer.php index d4915bf33..7210e4c83 100644 --- a/framework/core/src/Api/Serializers/ForumSerializer.php +++ b/framework/core/src/Api/Serializers/ForumSerializer.php @@ -1,7 +1,6 @@ actor->isAdmin()) { - $attributes['config'] = app('Flarum\Core\Settings\SettingsRepository')->all(); - $attributes['availableLocales'] = app('flarum.localeManager')->getLocales(); - $attributes['permissions'] = Permission::map(); } return $attributes; diff --git a/framework/core/src/Support/ClientView.php b/framework/core/src/Support/ClientView.php index b70db7f0b..2af78d9c1 100644 --- a/framework/core/src/Support/ClientView.php +++ b/framework/core/src/Support/ClientView.php @@ -26,13 +26,6 @@ class ClientView implements Renderable */ protected $title; - /** - * An API response that should be preloaded into the page. - * - * @var null|array|object - */ - protected $document; - /** * The SEO content of the page, displayed in