2019-10-14 13:45:09 +00:00
|
|
|
import $ from 'jquery';
|
2020-04-10 21:54:53 +00:00
|
|
|
|
2021-12-09 07:38:07 +00:00
|
|
|
/* @ngInject */
|
2023-11-20 07:35:03 +00:00
|
|
|
export function onStartupAngular($rootScope, $state, cfpLoadingBar, $transitions, HttpRequestHelper) {
|
2021-12-09 07:38:07 +00:00
|
|
|
$rootScope.$state = $state;
|
|
|
|
|
|
|
|
// Workaround to prevent the loading bar from going backward
|
|
|
|
// https://github.com/chieffancypants/angular-loading-bar/issues/273
|
|
|
|
const originalSet = cfpLoadingBar.set;
|
|
|
|
cfpLoadingBar.set = function overrideSet(n) {
|
|
|
|
if (n > cfpLoadingBar.status()) {
|
|
|
|
originalSet.apply(cfpLoadingBar, arguments);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$transitions.onBefore({}, () => {
|
|
|
|
HttpRequestHelper.resetAgentHeaders();
|
|
|
|
});
|
|
|
|
|
2024-03-12 14:16:19 +00:00
|
|
|
// EE-6751: screens not loading when switching quickly between side menu options
|
|
|
|
// Known bug of @uirouter/angularjs
|
|
|
|
// Fix found at https://github.com/angular-ui/ui-router/issues/3652#issuecomment-574499009
|
|
|
|
// This hook is cleaning the internal viewConfigs list, removing leftover data unrelated to the current transition
|
|
|
|
$transitions.onStart({}, (transition) => {
|
|
|
|
const toList = transition.treeChanges().to.map((t) => t.state.name);
|
|
|
|
const toConfigs = transition.router.viewService._viewConfigs.filter((vc) => toList.includes(vc.viewDecl.$context.name));
|
|
|
|
transition.router.viewService._viewConfigs = toConfigs;
|
|
|
|
});
|
|
|
|
|
2021-12-09 07:38:07 +00:00
|
|
|
$(document).ajaxSend((event, jqXhr, jqOpts) => {
|
|
|
|
const type = jqOpts.type === 'POST' || jqOpts.type === 'PUT' || jqOpts.type === 'PATCH';
|
|
|
|
const hasNoContentType = jqOpts.contentType !== 'application/json' && jqOpts.headers && !jqOpts.headers['Content-Type'];
|
|
|
|
if (type && hasNoContentType) {
|
|
|
|
jqXhr.setRequestHeader('Content-Type', 'application/json');
|
|
|
|
}
|
2023-11-20 07:35:03 +00:00
|
|
|
const csrfCookie = window.cookieStore.get('_gorilla_csrf');
|
|
|
|
jqXhr.setRequestHeader('X-CSRF-Token', csrfCookie);
|
2021-12-09 07:38:07 +00:00
|
|
|
});
|
|
|
|
}
|