Loading module/Application/Module.php +2 −1 Changes for module/Application/Module.php: 2 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ namespace Application; use Application\ORM\RouteEntitiesInjector; use Laminas\Mvc\Controller\AbstractActionController; use Laminas\Mvc\ModuleRouteListener; use Laminas\Mvc\MvcEvent; use Laminas\Stdlib\Glob; Loading Loading @@ -43,7 +44,7 @@ class Module $moduleRouteListener->attach($eventManager); /* Utilise un layout spécial si on est en AJAX. Valable pour TOUS les modules de l'application */ $eventManager->getSharedManager()->attach('Laminas\Mvc\Controller\AbstractActionController', 'dispatch', $eventManager->getSharedManager()->attach(AbstractActionController::class, MvcEvent::EVENT_DISPATCH, function (MvcEvent $e) { $request = $e->getRequest(); if ($request instanceof \Laminas\Http\Request && $request->isXmlHttpRequest()) { Loading module/Application/src/Controller/AbstractController.php +14 −0 Changes for module/Application/src/Controller/AbstractController.php: 14 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use Application\Form\Supprimer; use Application\Traits\TranslatorTrait; use Doctrine\ORM\EntityManager; use Laminas\Mvc\Controller\AbstractActionController; use Laminas\Mvc\MvcEvent; /** * Description of AbstractController Loading Loading @@ -52,4 +53,17 @@ abstract class AbstractController extends AbstractActionController { return \Application::$container->get(\Application\Constants::BDD); } public function onDispatch(MvcEvent $e) { $request = $e->getRequest(); if ($request->isXmlHttpRequest()) { $e->getTarget()->layout('layout/ajax.phtml'); } return parent::onDispatch($e); // TODO: Change the autogenerated stub } } No newline at end of file public/js/util.js +11 −4 Changes for public/js/util.js: 11 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ axios.interceptors.request.use(config => { }); axios.interceptors.response.use(response => { console.log(response); response.messages = response.data.messages; response.data = response.data.data; response.hasErrors = response.messages && response.messages.error && response.messages.error.length > 0 ? true : false; Loading Loading @@ -52,8 +53,15 @@ axios.interceptors.response.use(response => { } return response; }, (error) => { var text = $("<div>").html(error.response.data); text.find('i.fas').hide(); alertFlash(text.find('.alert').html(), 'error'); }); axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; /** Loading Loading @@ -89,10 +97,7 @@ function alertFlash(message, severity, duration) duration = 5000; } if ('error' == severity) { duration *= 10; } if (!severity) { severity = 'info'; duration *= 10000; } var alertClasses = { Loading Loading @@ -127,6 +132,7 @@ function alertFlash(message, severity, duration) $('body').append(alertDiv); alertDiv.slideToggle(500, function () { if ('error' != severity) { window.setTimeout(function () { alertDiv.slideToggle(500, function () Loading @@ -134,6 +140,7 @@ function alertFlash(message, severity, duration) $(this).removeClass(alertClass) }); }, duration); } }); } Loading Loading
module/Application/Module.php +2 −1 Changes for module/Application/Module.php: 2 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ namespace Application; use Application\ORM\RouteEntitiesInjector; use Laminas\Mvc\Controller\AbstractActionController; use Laminas\Mvc\ModuleRouteListener; use Laminas\Mvc\MvcEvent; use Laminas\Stdlib\Glob; Loading Loading @@ -43,7 +44,7 @@ class Module $moduleRouteListener->attach($eventManager); /* Utilise un layout spécial si on est en AJAX. Valable pour TOUS les modules de l'application */ $eventManager->getSharedManager()->attach('Laminas\Mvc\Controller\AbstractActionController', 'dispatch', $eventManager->getSharedManager()->attach(AbstractActionController::class, MvcEvent::EVENT_DISPATCH, function (MvcEvent $e) { $request = $e->getRequest(); if ($request instanceof \Laminas\Http\Request && $request->isXmlHttpRequest()) { Loading
module/Application/src/Controller/AbstractController.php +14 −0 Changes for module/Application/src/Controller/AbstractController.php: 14 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use Application\Form\Supprimer; use Application\Traits\TranslatorTrait; use Doctrine\ORM\EntityManager; use Laminas\Mvc\Controller\AbstractActionController; use Laminas\Mvc\MvcEvent; /** * Description of AbstractController Loading Loading @@ -52,4 +53,17 @@ abstract class AbstractController extends AbstractActionController { return \Application::$container->get(\Application\Constants::BDD); } public function onDispatch(MvcEvent $e) { $request = $e->getRequest(); if ($request->isXmlHttpRequest()) { $e->getTarget()->layout('layout/ajax.phtml'); } return parent::onDispatch($e); // TODO: Change the autogenerated stub } } No newline at end of file
public/js/util.js +11 −4 Changes for public/js/util.js: 11 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ axios.interceptors.request.use(config => { }); axios.interceptors.response.use(response => { console.log(response); response.messages = response.data.messages; response.data = response.data.data; response.hasErrors = response.messages && response.messages.error && response.messages.error.length > 0 ? true : false; Loading Loading @@ -52,8 +53,15 @@ axios.interceptors.response.use(response => { } return response; }, (error) => { var text = $("<div>").html(error.response.data); text.find('i.fas').hide(); alertFlash(text.find('.alert').html(), 'error'); }); axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; /** Loading Loading @@ -89,10 +97,7 @@ function alertFlash(message, severity, duration) duration = 5000; } if ('error' == severity) { duration *= 10; } if (!severity) { severity = 'info'; duration *= 10000; } var alertClasses = { Loading Loading @@ -127,6 +132,7 @@ function alertFlash(message, severity, duration) $('body').append(alertDiv); alertDiv.slideToggle(500, function () { if ('error' != severity) { window.setTimeout(function () { alertDiv.slideToggle(500, function () Loading @@ -134,6 +140,7 @@ function alertFlash(message, severity, duration) $(this).removeClass(alertClass) }); }, duration); } }); } Loading