refactor: move persona settings to dedicated user page
parent
c7b32667bc
commit
3847f603db
@ -1,3 +1,10 @@
|
||||
{
|
||||
"mobile-menu-side": "Switch which side each mobile menu is on"
|
||||
"settings.title": "Theme settings",
|
||||
"settings.intro": "You can customise your theme settings here. Settings are stored on a per-device basis, so you are able to have different settings on different devices (phone, tablet, desktop, etc.)",
|
||||
"settings.mobile-menu-side": "Switch which side each mobile menu is on",
|
||||
"settings.autoHidingNavbar": "Automatically hide the navbar on scroll",
|
||||
"settings.autoHidingNavbar-xs": "Very small screens (e.g. phones in portrait mode)",
|
||||
"settings.autoHidingNavbar-sm": "Smaller screens (e.g. phones, some tablets)",
|
||||
"settings.autoHidingNavbar-md": "Medium sized screens (e.g. tablets in landscape mode)",
|
||||
"settings.autoHidingNavbar-lg": "Larger screens (e.g. desktop computers)"
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
const accountHelpers = require.main.require('./src/controllers/accounts/helpers');
|
||||
const helpers = require.main.require('./src/controllers/helpers');
|
||||
|
||||
const Controllers = module.exports;
|
||||
|
||||
Controllers.renderAdminPage = (req, res) => {
|
||||
res.render('admin/plugins/persona', {});
|
||||
};
|
||||
|
||||
Controllers.renderThemeSettings = async (req, res, next) => {
|
||||
const userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query);
|
||||
if (!userData) {
|
||||
return next();
|
||||
}
|
||||
|
||||
userData.title = '[[persona:settings.title]]';
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: `/user/${userData.userslug}` }, { text: '[[persona:settings.title]]' }]);
|
||||
|
||||
res.render('account/theme', userData);
|
||||
};
|
@ -0,0 +1,53 @@
|
||||
'use strict';
|
||||
|
||||
define('forum/account/theme', ['forum/account/header', 'storage', 'settings', 'alerts'], function (header, Storage, settings, alerts) {
|
||||
const Theme = {};
|
||||
|
||||
Theme.init = () => {
|
||||
header.init();
|
||||
Theme.setupForm();
|
||||
};
|
||||
|
||||
Theme.setupForm = () => {
|
||||
const saveEl = document.getElementById('save');
|
||||
const formEl = document.getElementById('theme-settings');
|
||||
const [sidebarSwapped, autohideNavbarEnvs] = [
|
||||
!!Storage.getItem('persona:menus:legacy-layout'),
|
||||
Storage.getItem('persona:navbar:autohide'),
|
||||
];
|
||||
|
||||
document.getElementById('persona:menus:legacy-layout').checked = sidebarSwapped;
|
||||
try {
|
||||
const parsed = JSON.parse(autohideNavbarEnvs);
|
||||
parsed.forEach((env) => {
|
||||
const optionEl = document.getElementById('persona:navbar:autohide').querySelector(`option[value="${env}"]`);
|
||||
optionEl.selected = true;
|
||||
});
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
|
||||
if (saveEl) {
|
||||
saveEl.addEventListener('click', () => {
|
||||
const themeSettings = settings.helper.serializeForm($(formEl));
|
||||
Object.keys(themeSettings).forEach((key) => {
|
||||
if (key === 'persona:menus:legacy-layout') {
|
||||
if (themeSettings[key] === 'on') {
|
||||
Storage.setItem('persona:menus:legacy-layout', 'true');
|
||||
} else {
|
||||
Storage.removeItem('persona:menus:legacy-layout');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Storage.setItem(key, themeSettings[key]);
|
||||
});
|
||||
|
||||
alerts.success('[[success:settings-saved]]');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return Theme;
|
||||
});
|
@ -0,0 +1,27 @@
|
||||
<div class="account">
|
||||
<!-- IMPORT partials/account/header.tpl -->
|
||||
|
||||
<p>[[persona:settings.intro]]</p>
|
||||
|
||||
<hr />
|
||||
|
||||
<form id="theme-settings" role="form">
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" id="persona:menus:legacy-layout" name="persona:menus:legacy-layout"> <strong>[[persona:settings.mobile-menu-side]]</strong>
|
||||
</label>
|
||||
</div><br />
|
||||
|
||||
<div class="form-group">
|
||||
<label for="persona:navbar:autohide">[[persona:settings.autoHidingNavbar]]</label>
|
||||
<select multiple class="form-control" name="persona:navbar:autohide" id="persona:navbar:autohide">
|
||||
<option value="xs">[[persona:settings.autoHidingNavbar-xs]]</option>
|
||||
<option value="sm">[[persona:settings.autoHidingNavbar-sm]]</option>
|
||||
<option value="md">[[persona:settings.autoHidingNavbar-md]]</option>
|
||||
<option value="lg">[[persona:settings.autoHidingNavbar-lg]]</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<button id="save" type="button" class="btn btn-primary">[[global:save_changes]]</button>
|
||||
</form>
|
||||
</div>
|
Loading…
Reference in New Issue