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:
Maurício Meneghini Fauth 2022-12-11 21:19:44 -03:00
parent b3e40101ee
commit 1cd484e1bc
4 changed files with 27 additions and 24 deletions

View File

@ -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');

View File

@ -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);
}
}
});

View 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();
}
}

View File

@ -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();
});