2015-07-29 19:28:22 +08:00
|
|
|
import Component from 'flarum/Component';
|
2015-08-03 13:05:51 +08:00
|
|
|
import Button from 'flarum/components/Button';
|
|
|
|
import Switch from 'flarum/components/Switch';
|
|
|
|
import EditCustomCssModal from 'flarum/components/EditCustomCssModal';
|
Major refactor and improvements
- Reorganised all namespaces and class names for consistency and structure. Following PSR bylaws (Abstract prefix, Interface/Trait suffix).
- Move models into root of Core, because writing `use Flarum\Core\Discussion` is nice. Namespace the rest by type. (Namespacing by entity was too arbitrary.)
- Moved some non-domain stuff out of Core: Database, Formatter, Settings.
- Renamed config table and all references to "settings" for consistency.
- Remove Core class and add url()/isInstalled()/inDebugMode() as instance methods of Foundation\Application.
- Cleanup, docblocking, etc.
- Improvements to HTTP architecture
- API and forum/admin Actions are now actually all the same thing (simple PSR-7 Request handlers), renamed to Controllers.
- Upgrade to tobscure/json-api 0.2 branch.
- Where possible, moved generic functionality to tobscure/json-api (e.g. pagination links). I'm quite happy with the backend balance now re: #262
- Improvements to other architecture
- Use Illuminate's Auth\Access\Gate interface/implementation instead of our old Locked trait. We still use events to actually determine the permissions though. Our Policy classes are actually glorified event subscribers.
- Extract model validation into Core\Validator classes.
- Make post visibility permission stuff much more efficient and DRY.
- Renamed Flarum\Event classes for consistency. ref #246
- `Configure` prefix for events dedicated to configuring an object.
- `Get` prefix for events whose listeners should return something.
- `Prepare` prefix when a variable is passed by reference so it can be modified.
- `Scope` prefix when a query builder is passed.
- Miscellaneous improvements/bug-fixes. I'm easily distracted!
- Increase default height of post composer.
- Improve post stream redraw flickering in Safari by keying loading post placeholders with their IDs. ref #451
- Use a PHP JavaScript minification library for minifying TextFormatter's JavaScript, instead of ClosureCompilerService (can't rely on external service!)
- Use UrlGenerator properly in various places. closes #123
- Make Api\Client return Response object. closes #128
- Allow extensions to specify custom icon images.
- Allow external API/admin URLs to be optionally specified in config.php. If the value or "url" is an array, we look for the corresponding path inside. Otherwise, we append the path to the base URL, using the corresponding value in "paths" if present. closes #244
2015-10-08 11:58:02 +08:00
|
|
|
import saveSettings from 'flarum/utils/saveSettings';
|
2015-07-29 19:28:22 +08:00
|
|
|
|
|
|
|
export default class AppearancePage extends Component {
|
2015-10-13 14:25:56 +08:00
|
|
|
init() {
|
Major refactor and improvements
- Reorganised all namespaces and class names for consistency and structure. Following PSR bylaws (Abstract prefix, Interface/Trait suffix).
- Move models into root of Core, because writing `use Flarum\Core\Discussion` is nice. Namespace the rest by type. (Namespacing by entity was too arbitrary.)
- Moved some non-domain stuff out of Core: Database, Formatter, Settings.
- Renamed config table and all references to "settings" for consistency.
- Remove Core class and add url()/isInstalled()/inDebugMode() as instance methods of Foundation\Application.
- Cleanup, docblocking, etc.
- Improvements to HTTP architecture
- API and forum/admin Actions are now actually all the same thing (simple PSR-7 Request handlers), renamed to Controllers.
- Upgrade to tobscure/json-api 0.2 branch.
- Where possible, moved generic functionality to tobscure/json-api (e.g. pagination links). I'm quite happy with the backend balance now re: #262
- Improvements to other architecture
- Use Illuminate's Auth\Access\Gate interface/implementation instead of our old Locked trait. We still use events to actually determine the permissions though. Our Policy classes are actually glorified event subscribers.
- Extract model validation into Core\Validator classes.
- Make post visibility permission stuff much more efficient and DRY.
- Renamed Flarum\Event classes for consistency. ref #246
- `Configure` prefix for events dedicated to configuring an object.
- `Get` prefix for events whose listeners should return something.
- `Prepare` prefix when a variable is passed by reference so it can be modified.
- `Scope` prefix when a query builder is passed.
- Miscellaneous improvements/bug-fixes. I'm easily distracted!
- Increase default height of post composer.
- Improve post stream redraw flickering in Safari by keying loading post placeholders with their IDs. ref #451
- Use a PHP JavaScript minification library for minifying TextFormatter's JavaScript, instead of ClosureCompilerService (can't rely on external service!)
- Use UrlGenerator properly in various places. closes #123
- Make Api\Client return Response object. closes #128
- Allow extensions to specify custom icon images.
- Allow external API/admin URLs to be optionally specified in config.php. If the value or "url" is an array, we look for the corresponding path inside. Otherwise, we append the path to the base URL, using the corresponding value in "paths" if present. closes #244
2015-10-08 11:58:02 +08:00
|
|
|
this.primaryColor = m.prop(app.settings.theme_primary_color);
|
|
|
|
this.secondaryColor = m.prop(app.settings.theme_secondary_color);
|
|
|
|
this.darkMode = m.prop(app.settings.theme_dark_mode === '1');
|
|
|
|
this.coloredHeader = m.prop(app.settings.theme_colored_header === '1');
|
2015-08-03 13:05:51 +08:00
|
|
|
}
|
|
|
|
|
2015-07-29 19:28:22 +08:00
|
|
|
view() {
|
|
|
|
return (
|
2015-08-03 13:05:51 +08:00
|
|
|
<div className="AppearancePage">
|
|
|
|
<div className="container">
|
|
|
|
<form onsubmit={this.onsubmit.bind(this)}>
|
|
|
|
<fieldset className="AppearancePage-colors">
|
2015-10-05 18:06:41 +08:00
|
|
|
<legend>{app.trans('core.admin.appearance_colors_heading')}</legend>
|
2015-08-03 13:05:51 +08:00
|
|
|
<div className="helpText">
|
2015-10-05 18:06:41 +08:00
|
|
|
{app.trans('core.admin.appearance_colors_text')}
|
2015-08-03 13:05:51 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="AppearancePage-colors-input">
|
|
|
|
<input className="FormControl" placeholder="#aaaaaa" value={this.primaryColor()} onchange={m.withAttr('value', this.primaryColor)}/>
|
|
|
|
<input className="FormControl" placeholder="#aaaaaa" value={this.secondaryColor()} onchange={m.withAttr('value', this.secondaryColor)}/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{Switch.component({
|
|
|
|
state: this.darkMode(),
|
2015-10-05 18:06:41 +08:00
|
|
|
children: app.trans('core.admin.appearance_dark_mode_label'),
|
2015-08-03 13:05:51 +08:00
|
|
|
onchange: this.darkMode
|
|
|
|
})}
|
|
|
|
|
|
|
|
{Switch.component({
|
|
|
|
state: this.coloredHeader(),
|
2015-10-05 18:06:41 +08:00
|
|
|
children: app.trans('core.admin.appearance_colored_header_label'),
|
2015-08-03 13:05:51 +08:00
|
|
|
onchange: this.coloredHeader
|
|
|
|
})}
|
|
|
|
|
|
|
|
{Button.component({
|
|
|
|
className: 'Button Button--primary',
|
2015-09-15 09:57:31 +08:00
|
|
|
type: 'submit',
|
2015-10-05 18:06:41 +08:00
|
|
|
children: app.trans('core.admin.appearance_submit_button'),
|
2015-08-03 13:05:51 +08:00
|
|
|
loading: this.loading
|
|
|
|
})}
|
|
|
|
</fieldset>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<fieldset>
|
2015-10-05 18:06:41 +08:00
|
|
|
<legend>{app.trans('core.admin.appearance_custom_styles_heading')}</legend>
|
2015-08-03 13:05:51 +08:00
|
|
|
<div className="helpText">
|
2015-10-05 18:06:41 +08:00
|
|
|
{app.trans('core.admin.appearance_custom_styles_text')}
|
2015-08-03 13:05:51 +08:00
|
|
|
</div>
|
|
|
|
{Button.component({
|
|
|
|
className: 'Button',
|
2015-10-05 18:06:41 +08:00
|
|
|
children: app.trans('core.admin.appearance_edit_css_button'),
|
2015-08-03 13:05:51 +08:00
|
|
|
onclick: () => app.modal.show(new EditCustomCssModal())
|
|
|
|
})}
|
|
|
|
</fieldset>
|
|
|
|
</div>
|
|
|
|
</div>
|
2015-07-29 19:28:22 +08:00
|
|
|
);
|
|
|
|
}
|
2015-08-03 13:05:51 +08:00
|
|
|
|
|
|
|
onsubmit(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
2015-08-04 09:08:49 +08:00
|
|
|
const hex = /^#[0-9a-f]{3}([0-9a-f]{3})?$/i;
|
|
|
|
|
|
|
|
if (!hex.test(this.primaryColor()) || !hex.test(this.secondaryColor())) {
|
2015-10-05 18:06:41 +08:00
|
|
|
alert(app.trans('core.admin.appearance_enter_hex_message'));
|
2015-08-04 09:08:49 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-03 13:05:51 +08:00
|
|
|
this.loading = true;
|
|
|
|
|
Major refactor and improvements
- Reorganised all namespaces and class names for consistency and structure. Following PSR bylaws (Abstract prefix, Interface/Trait suffix).
- Move models into root of Core, because writing `use Flarum\Core\Discussion` is nice. Namespace the rest by type. (Namespacing by entity was too arbitrary.)
- Moved some non-domain stuff out of Core: Database, Formatter, Settings.
- Renamed config table and all references to "settings" for consistency.
- Remove Core class and add url()/isInstalled()/inDebugMode() as instance methods of Foundation\Application.
- Cleanup, docblocking, etc.
- Improvements to HTTP architecture
- API and forum/admin Actions are now actually all the same thing (simple PSR-7 Request handlers), renamed to Controllers.
- Upgrade to tobscure/json-api 0.2 branch.
- Where possible, moved generic functionality to tobscure/json-api (e.g. pagination links). I'm quite happy with the backend balance now re: #262
- Improvements to other architecture
- Use Illuminate's Auth\Access\Gate interface/implementation instead of our old Locked trait. We still use events to actually determine the permissions though. Our Policy classes are actually glorified event subscribers.
- Extract model validation into Core\Validator classes.
- Make post visibility permission stuff much more efficient and DRY.
- Renamed Flarum\Event classes for consistency. ref #246
- `Configure` prefix for events dedicated to configuring an object.
- `Get` prefix for events whose listeners should return something.
- `Prepare` prefix when a variable is passed by reference so it can be modified.
- `Scope` prefix when a query builder is passed.
- Miscellaneous improvements/bug-fixes. I'm easily distracted!
- Increase default height of post composer.
- Improve post stream redraw flickering in Safari by keying loading post placeholders with their IDs. ref #451
- Use a PHP JavaScript minification library for minifying TextFormatter's JavaScript, instead of ClosureCompilerService (can't rely on external service!)
- Use UrlGenerator properly in various places. closes #123
- Make Api\Client return Response object. closes #128
- Allow extensions to specify custom icon images.
- Allow external API/admin URLs to be optionally specified in config.php. If the value or "url" is an array, we look for the corresponding path inside. Otherwise, we append the path to the base URL, using the corresponding value in "paths" if present. closes #244
2015-10-08 11:58:02 +08:00
|
|
|
saveSettings({
|
2015-08-03 13:05:51 +08:00
|
|
|
theme_primary_color: this.primaryColor(),
|
|
|
|
theme_secondary_color: this.secondaryColor(),
|
|
|
|
theme_dark_mode: this.darkMode(),
|
|
|
|
theme_colored_header: this.coloredHeader()
|
|
|
|
}).then(() => window.location.reload());
|
|
|
|
}
|
2015-07-29 19:28:22 +08:00
|
|
|
}
|