diff --git a/js/pages/backoffice/on-ready.js b/js/pages/backoffice/on-ready.js new file mode 100644 index 000000000..93949c2f6 --- /dev/null +++ b/js/pages/backoffice/on-ready.js @@ -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); + }); +}); diff --git a/sources/application/WebPage/iTopWebPage.php b/sources/application/WebPage/iTopWebPage.php index 1994e1c8d..0e6046063 100644 --- a/sources/application/WebPage/iTopWebPage.php +++ b/sources/application/WebPage/iTopWebPage.php @@ -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) - { - $('
'+$sJSDisconnectedMessage+'
').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= ''; diff --git a/templates/pages/backoffice/itopwebpage/layout.html.twig b/templates/pages/backoffice/itopwebpage/layout.html.twig index 32c233c33..8924d5735 100644 --- a/templates/pages/backoffice/itopwebpage/layout.html.twig +++ b/templates/pages/backoffice/itopwebpage/layout.html.twig @@ -28,6 +28,7 @@ +
{{ 'UI:DisconnectedDlgMessage'|dict_s }}
{% endif %} {% endblock %}