1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Epesi\Core\Layout; |
4
|
|
|
|
5
|
|
|
use atk4\ui\jQuery; |
6
|
|
|
use Illuminate\Support\Arr; |
7
|
|
|
use Epesi\Core\System\Modules\ModuleView; |
8
|
|
|
use atk4\core\SessionTrait; |
9
|
|
|
use atk4\ui\Menu; |
10
|
|
|
|
11
|
|
|
class LayoutView extends \atk4\ui\Layout |
12
|
|
|
{ |
13
|
|
|
use SessionTrait; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var View\NavMenu |
17
|
|
|
*/ |
18
|
|
|
public $menuLeft; // vertical menu |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var \atk4\ui\Menu |
22
|
|
|
*/ |
23
|
|
|
public $menuTop; // horizontal menu |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var \atk4\ui\Menu |
27
|
|
|
*/ |
28
|
|
|
public $menuRight; // vertical pull-down |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var View\ActionBar |
32
|
|
|
*/ |
33
|
|
|
public $actionBar; |
34
|
|
|
public $locationBar; |
35
|
|
|
|
36
|
|
|
public $burger = true; // burger menu item |
37
|
|
|
|
38
|
|
|
/* |
39
|
|
|
* Whether or not left Menu is visible on Page load. |
40
|
|
|
*/ |
41
|
|
|
public $isMenuLeftVisible = true; |
42
|
|
|
|
43
|
|
|
public $defaultTemplate = 'layout/admin.html'; |
44
|
|
|
|
45
|
|
|
protected $location; |
46
|
|
|
|
47
|
|
|
protected function init(): void |
48
|
|
|
{ |
49
|
|
|
parent::init(); |
50
|
|
|
|
51
|
|
|
$this->initMenuTop(); |
52
|
|
|
$this->initActionBar(); |
53
|
|
|
|
54
|
|
|
// if (request()->pjax()) return; |
55
|
|
|
|
56
|
|
|
$this->initMenuLeft(); |
57
|
|
|
$this->initMenuRight(); |
58
|
|
|
|
59
|
|
|
$this->template->trySet('version', $this->getApp()->version); |
60
|
|
|
|
61
|
|
|
// $this->js(true, null, 'body')->niceScroll(); |
62
|
|
|
|
63
|
|
|
// $this->js(true, null, new jsExpression('window'))->on('pageshow', new jsFunction(['event'], [ |
64
|
|
|
// new jsExpression(' |
65
|
|
|
// if (event.originalEvent.persisted) { |
66
|
|
|
// window.location.reload(); |
67
|
|
|
// }')])); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return static |
72
|
|
|
*/ |
73
|
|
|
public function setLocation(array $crumbs) |
74
|
|
|
{ |
75
|
|
|
$this->location = $crumbs; |
76
|
|
|
|
77
|
|
|
$crumb = \atk4\ui\Breadcrumb::addTo($this->locationBar); |
78
|
|
|
|
79
|
|
|
$title = []; |
80
|
|
|
foreach ($crumbs as $level) { |
81
|
|
|
$label = $level['label'] ?? $level; |
82
|
|
|
$link = $level['link'] ?? null; |
83
|
|
|
|
84
|
|
|
$crumb->addCrumb($label, $link); |
85
|
|
|
|
86
|
|
|
$title[] = $label; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$crumb->popTitle(); |
90
|
|
|
|
91
|
|
|
$this->getApp()->title = implode(' > ', Arr::prepend($title, config('epesi.ui.title', 'EPESI'))); |
92
|
|
|
|
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getLocation() |
97
|
|
|
{ |
98
|
|
|
return $this->location; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
protected function initMenuTop() |
102
|
|
|
{ |
103
|
|
|
if ($this->menuTop) return; |
104
|
|
|
|
105
|
|
|
$this->menuTop = Menu::addTo($this, ['atk-topMenu fixed horizontal', 'element' => 'header'], ['TopMenu']); |
106
|
|
|
|
107
|
|
|
// company logo |
108
|
|
|
// see \Epesi\Core\Controller::logo |
109
|
|
|
\atk4\ui\View::addTo($this->menuTop, ['class' => ['epesi-logo'], 'style' => ['width' => '167px']])->add([\atk4\ui\Image::class, url('logo')])->setStyle(['max-height' => '32px']); |
|
|
|
|
110
|
|
|
|
111
|
|
|
if ($this->burger) { |
112
|
|
|
$this->burger = $this->menuTop->addItem(['class' => ['icon atk-leftMenuTrigger']]); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
// home icon redirects to /home path |
116
|
|
|
// see \Epesi\Core\Controller::home |
117
|
|
|
$this->menuTop->addItem(['class' => ['icon epesi-home']], url('home'))->add([\atk4\ui\Icon::class, 'home']); |
118
|
|
|
|
119
|
|
|
// location bar |
120
|
|
|
$this->locationBar = $this->menuTop->add([\atk4\ui\View::class, ['ui' => 'epesi-location']]); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
protected function initMenuRight() |
124
|
|
|
{ |
125
|
|
|
if ($this->menuRight) return; |
126
|
|
|
|
127
|
|
|
$this->menuRight = $this->menuTop->add(new View\RightMenu(['ui' => false]), 'RightMenu')->addClass('right menu')->removeClass('item'); |
|
|
|
|
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
protected function initMenuLeft() |
131
|
|
|
{ |
132
|
|
|
if ($this->menuLeft) return; |
133
|
|
|
|
134
|
|
|
$this->menuLeft = View\NavMenu::addTo($this, 'left vertical labeled sidebar', ['LeftMenu']); |
|
|
|
|
135
|
|
|
|
136
|
|
|
if ($this->burger) { |
137
|
|
|
$this->isMenuLeftVisible = $this->learn('menu', $this->isMenuLeftVisible); |
138
|
|
|
|
139
|
|
|
$this->burger->add([\atk4\ui\Icon::class, 'content'])->on('click', [ |
140
|
|
|
(new jQuery('.ui.left.sidebar'))->toggleClass('visible'), |
|
|
|
|
141
|
|
|
(new jQuery('.epesi-logo'))->toggleClass('expanded'), |
142
|
|
|
(new jQuery('body'))->toggleClass('atk-leftMenu-visible'), |
143
|
|
|
\atk4\ui\JsCallback::addTo($this->burger)->set(function($jsCallback, $visible) { |
|
|
|
|
144
|
|
|
$this->memorize('menu', filter_var($visible, FILTER_VALIDATE_BOOLEAN)); |
145
|
|
|
}, [$this->menuLeft->js(true)->hasClass('visible')]) |
146
|
|
|
]); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
protected function initActionBar() |
151
|
|
|
{ |
152
|
|
|
if (!$this->actionBar) { |
153
|
|
|
$this->actionBar = View\ActionBar::addTo($this, [], ['ActionBar']); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
return $this; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function renderView(): void |
160
|
|
|
{ |
161
|
|
|
if ($this->menuLeft && $this->isMenuLeftVisible) { |
162
|
|
|
$this->menuLeft->addClass('visible'); |
163
|
|
|
} |
164
|
|
|
parent::renderView(); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|