N°4131 - Fix multiple "User disconnected" dialogs in the backoffice

(cherry picked from commit d8f36a8aa9)
This commit is contained in:
Molkobain
2021-07-04 17:59:42 +02:00
parent 8e1e71c740
commit d6b9172e26
3 changed files with 69 additions and 32 deletions

View File

@@ -0,0 +1,63 @@
/*
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
/*
* Here we should put all the "static" (no variable) JS code that needs to be evaluated on DOM ready
*/
$(document).ready(function () {
// AJAX calls handling
// - Custom headers
$(document).ajaxSend(function (event, jqxhr, options) {
jqxhr.setRequestHeader('X-Combodo-Ajax', 'true');
});
// - Error messages regarding the error code
$(document).ajaxError(function (event, jqxhr, options) {
// User is not logged ing
if (jqxhr.status == 401) {
const oUserDisconnectedDialog = $('#ibo-user-disconnected-dialog');
// Create dialog widget if not already instantiated
if (oUserDisconnectedDialog.data('uiDialog') === undefined) {
oUserDisconnectedDialog.removeClass('ibo-is-hidden');
oUserDisconnectedDialog.dialog({
modal: true,
title: Dict.S('UI:DisconnectedDlgTitle'),
close: function () {
$(this).dialog('close');
},
minWidth: 400,
buttons: [
{
text: Dict.S('UI:LoginAgain'),
click: function () {
window.location.href = GetAbsoluteUrlAppRoot()+'pages/UI.php'
}
},
{
text: Dict.S('UI:StayOnThePage'),
click: function () {
$(this).dialog('close');
}
}
]
});
}
// Just open it otherwise
else {
oUserDisconnectedDialog.dialog('open');
}
}
});
// - Successful
$(document).ajaxSuccess(function () {
// Async. markup, small timeout to allow markup to be built if necessary
setTimeout(function () {
CombodoTooltip.InitAllNonInstantiatedTooltips();
CombodoBackofficeToolbox.InitCodeHighlighting();
// Initialize date / datetime pickers if needed
PrepareWidgets();
}, 500);
});
});

View File

@@ -153,6 +153,7 @@ class iTopWebPage extends NiceWebPage implements iTabbedPage
$this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/mousetrap/mousetrap-record.min.js');
$this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/pages/backoffice/keyboard-shortcuts.js');
$this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/pages/backoffice/toolbox.js');
$this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/pages/backoffice/on-ready.js');
}
/**
@@ -173,6 +174,10 @@ class iTopWebPage extends NiceWebPage implements iTabbedPage
$this->add_dict_entry('UI:Datatables:Language:Processing');
$this->add_dict_entries('UI:Newsroom');
// User not logged in dialog
$this->add_dict_entry('UI:DisconnectedDlgTitle');
$this->add_dict_entry('UI:LoginAgain');
$this->add_dict_entry('UI:StayOnThePage');
}
/**
@@ -210,10 +215,6 @@ class iTopWebPage extends NiceWebPage implements iTabbedPage
*/
protected function PrepareLayout()
{
$sJSDisconnectedMessage = json_encode(Dict::S('UI:DisconnectedDlgMessage'));
$sJSTitle = json_encode(Dict::S('UI:DisconnectedDlgTitle'));
$sJSLoginAgain = json_encode(Dict::S('UI:LoginAgain'));
$sJSStayOnThePage = json_encode(Dict::S('UI:StayOnThePage'));
$aDaysMin = array(
Dict::S('DayOfWeek-Sunday-Min'),
Dict::S('DayOfWeek-Monday-Min'),
@@ -353,34 +354,6 @@ JS
// $('#ModalDlg').dialog({ autoOpen: false, modal: true, width: 0.8*docWidth, height: 'auto', maxHeight: $(window).height() - 50 }); // JQuery UI dialogs
ShowDebug();
$(document).ajaxSend(function(event, jqxhr, options) {
jqxhr.setRequestHeader('X-Combodo-Ajax', 'true');
});
$(document).ajaxError(function(event, jqxhr, options) {
if (jqxhr.status == 401)
{
$('<div>'+$sJSDisconnectedMessage+'</div>').dialog({
modal:true,
title: $sJSTitle,
close: function() { $(this).remove(); },
minWidth: 400,
buttons: [
{ text: $sJSLoginAgain, click: function() { window.location.href= GetAbsoluteUrlAppRoot()+'pages/UI.php' } },
{ text: $sJSStayOnThePage, click: function() { $(this).dialog('close'); } }
]
});
}
});
$(document).ajaxSuccess(function(){
// Async. markup, small timeout to allow markup to be built if necessary
setTimeout(function(){
CombodoTooltip.InitAllNonInstantiatedTooltips();
CombodoBackofficeToolbox.InitCodeHighlighting();
// Initialize date / datetime pickers if needed
PrepareWidgets();
}, 500);
});
// Default values for blockui
$.blockUI.defaults.css = {};
$.blockUI.defaults.message= '<i class="fas fa-fw fa-spin fa-sync"></i>';

View File

@@ -28,6 +28,7 @@
<div style="display:none" title="ex2" id="ex2">Please wait...</div>
<div style="display:none" title="dialog" id="ModalDlg"></div>
<div style="display:none" id="ajax_content"></div>
<div class="ibo-is-hidden" id="ibo-user-disconnected-dialog">{{ 'UI:DisconnectedDlgMessage'|dict_s }}</div>
</div>
{% endif %}
{% endblock %}