new: [layout:sidebar] Save sidebar expanded state in user setting

pull/72/head
Sami Mokaddem 2021-10-08 16:56:08 +02:00
parent 4d85d70799
commit 7fbf83bf49
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 18 additions and 2 deletions

View File

@ -16,6 +16,8 @@
use Cake\Core\Configure;
$cakeDescription = 'Cerebrate';
$sidebarOpen = $loggedUser->user_settings_by_name['ui.sidebar.expanded']->value;
?>
<!DOCTYPE html>
<html>
@ -72,7 +74,7 @@ $cakeDescription = 'Cerebrate';
<header class="navbar top-navbar navbar-dark">
<?= $this->element('layouts/header') ?>
</header>
<nav id="app-sidebar" class="collapse d-sm-block sidebar">
<nav id="app-sidebar" class="collapse d-sm-block sidebar <?= !empty($sidebarOpen) ? 'expanded' : '' ?>">
<?= $this->element('layouts/sidebar') ?>
</nav>
<main role="main" class="content">

View File

@ -162,4 +162,18 @@ $(document).ready(() => {
$('#globalSearch')
.keydown(debouncedGlobalSearch)
.keydown(focusSearchResults);
})
$('.lock-sidebar a.btn-lock-sidebar').click(() => {
const $sidebar = $('.sidebar')
let expanded = $sidebar.hasClass('expanded');
if (expanded) {
$sidebar.removeClass('expanded')
} else {
$sidebar.addClass('expanded')
}
const settingName = 'ui.sidebar.expanded';
const url = `/user-settings/setSetting/${settingName}`
AJAXApi.quickFetchAndPostForm(url, {
value: expanded ? 0 : 1
}, { provideFeedback: false})
})