#4633 Ajax request for header

This commit is contained in:
Muammer Top 2021-10-06 12:58:20 +03:00
parent 40d9214926
commit 064247b2e2
2 changed files with 16 additions and 1 deletions

View File

@ -12,3 +12,14 @@ function crudAjax(params, url, type = 'GET', callback = () => {}, async = false,
...options
});
}
function getUserNavMenu(html, element) {
crudAjax({}, '/ajax/get-user-info', 'GET', function (callback) {
if (callback['userName']){
element.html(html);
$(element).find('.addBlock').html(callback['addBlockHtml']);
$(element).find('.username').html(callback['userName']);
$(element).find('.profile-img').attr('src', `${callback['profileImg']}`);
}
})
}

View File

@ -1,6 +1,7 @@
<?php namespace Visiosoft\ProfileModule\Http\Controller;
use Anomaly\Streams\Platform\Http\Controller\PublicController;
use Anomaly\Streams\Platform\Image\Command\MakeImageInstance;
use Visiosoft\AddblockExtension\Command\addBlock;
class CacheController extends PublicController
@ -8,11 +9,14 @@ class CacheController extends PublicController
public function getUserInfo()
{
$user = auth()->user();
$profile_img = $this->dispatch(
new MakeImageInstance($user->file ?: 'theme::images/no_profile.svg', 'img')
)->url();
$user = $user ? $user->first_name . ' ' . $user->last_name : $user;
$getAddBlockHtml = new addBlock('navigation/dropdown', []);
$addBlockHtml = $getAddBlockHtml->handle();
return ['userName' => $user, 'addBlockHtml' => $addBlockHtml];
return ['userName' => $user, 'profileImg' => $profile_img, 'addBlockHtml' => $addBlockHtml];
}
}