Extract Functions.handleRedirectAndReload() into a module
This removes the dependency on Functions in navigation.js. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
parent
b3e40101ee
commit
1cd484e1bc
@ -7,6 +7,7 @@ import { ajaxRemoveMessage, ajaxShowMessage } from './ajax-message.js';
|
||||
import { escapeHtml } from './functions/escape.js';
|
||||
import getImageTag from './functions/getImageTag.js';
|
||||
import { ignorePhpErrors } from './functions/ignorePhpErrors.js';
|
||||
import handleRedirectAndReload from './functions/handleRedirectAndReload.js';
|
||||
|
||||
/**
|
||||
* This object handles ajax requests for pages. It also
|
||||
@ -453,7 +454,7 @@ const AJAX = {
|
||||
ajaxShowMessage(data.error, false);
|
||||
AJAX.active = false;
|
||||
AJAX.xhr = null;
|
||||
Functions.handleRedirectAndReload(data);
|
||||
handleRedirectAndReload(data);
|
||||
if (data.fieldWithError) {
|
||||
$(':input.error').removeClass('error');
|
||||
$('#' + data.fieldWithError).addClass('error');
|
||||
@ -624,7 +625,7 @@ const AJAX = {
|
||||
$('html, body').animate({ scrollTop: $(document).height() }, 200);
|
||||
AJAX.active = false;
|
||||
AJAX.xhr = null;
|
||||
Functions.handleRedirectAndReload(data);
|
||||
handleRedirectAndReload(data);
|
||||
if (data.fieldWithError) {
|
||||
$(':input.error').removeClass('error');
|
||||
$('#' + data.fieldWithError).addClass('error');
|
||||
|
||||
@ -10,6 +10,7 @@ import { ajaxRemoveMessage, ajaxShowMessage } from './ajax-message.js';
|
||||
import handleCreateViewModal from './functions/handleCreateViewModal.js';
|
||||
import { escapeHtml } from './functions/escape.js';
|
||||
import getImageTag from './functions/getImageTag.js';
|
||||
import handleRedirectAndReload from './functions/handleRedirectAndReload.js';
|
||||
|
||||
/* global DatabaseStructure */ // js/database/structure.js
|
||||
/* global firstDayOfCalendar, maxInputVars, themeImagePath */ // templates/javascript/variables.twig
|
||||
@ -210,25 +211,6 @@ Functions.addDateTimePicker = function () {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle redirect and reload flags sent as part of AJAX requests
|
||||
*
|
||||
* @param data ajax response data
|
||||
*/
|
||||
Functions.handleRedirectAndReload = function (data) {
|
||||
if (parseInt(data.redirect_flag) === 1) {
|
||||
// add one more GET param to display session expiry msg
|
||||
if (window.location.href.indexOf('?') === -1) {
|
||||
window.location.href += '?session_expired=1';
|
||||
} else {
|
||||
window.location.href += CommonParams.get('arg_separator') + 'session_expired=1';
|
||||
}
|
||||
window.location.reload();
|
||||
} else if (parseInt(data.reload_flag) === 1) {
|
||||
window.location.reload();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an SQL editor which supports auto completing etc.
|
||||
*
|
||||
@ -864,7 +846,7 @@ Functions.onloadIdleEvent = function () {
|
||||
$('input[name=token]').val(data.new_token);
|
||||
}
|
||||
idleSecondsCounter = 0;
|
||||
Functions.handleRedirectAndReload(data);
|
||||
handleRedirectAndReload(data);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
20
js/src/modules/functions/handleRedirectAndReload.js
Normal file
20
js/src/modules/functions/handleRedirectAndReload.js
Normal file
@ -0,0 +1,20 @@
|
||||
import { CommonParams } from '../common.js';
|
||||
|
||||
/**
|
||||
* Handle redirect and reload flags sent as part of AJAX requests
|
||||
*
|
||||
* @param {Object} data ajax response data
|
||||
*/
|
||||
export default function handleRedirectAndReload (data) {
|
||||
if (parseInt(data.redirect_flag) === 1) {
|
||||
// add one more GET param to display session expiry msg
|
||||
if (window.location.href.indexOf('?') === -1) {
|
||||
window.location.href += '?session_expired=1';
|
||||
} else {
|
||||
window.location.href += CommonParams.get('arg_separator') + 'session_expired=1';
|
||||
}
|
||||
window.location.reload();
|
||||
} else if (parseInt(data.reload_flag) === 1) {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,11 @@
|
||||
import $ from 'jquery';
|
||||
import { Functions } from './functions.js';
|
||||
import { CommonParams } from './common.js';
|
||||
import { Config } from './config.js';
|
||||
import tooltip from './tooltip.js';
|
||||
import { ajaxRemoveMessage, ajaxShowMessage } from './ajax-message.js';
|
||||
import handleCreateViewModal from './functions/handleCreateViewModal.js';
|
||||
import { getConfigValue, setConfigValue } from './functions/config.js';
|
||||
import handleRedirectAndReload from './functions/handleRedirectAndReload.js';
|
||||
|
||||
/**
|
||||
* function used in or for navigation panel
|
||||
@ -1039,7 +1039,7 @@ Navigation.treePagination = function ($this) {
|
||||
}
|
||||
} else {
|
||||
ajaxShowMessage(data.error);
|
||||
Functions.handleRedirectAndReload(data);
|
||||
handleRedirectAndReload(data);
|
||||
}
|
||||
Navigation.treeStateUpdate();
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user