From f5ae5f7c42afa749ce0301063a4b2cbdd603642c Mon Sep 17 00:00:00 2001 From: Guillaume Lajarige Date: Fri, 3 Jun 2016 13:59:06 +0000 Subject: [PATCH] Customer portal : Added user feedback when modal dialog loading crashes server side SVN:trunk[4181] --- .../portal/src/views/layout.html.twig | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/datamodels/2.x/itop-portal-base/portal/src/views/layout.html.twig b/datamodels/2.x/itop-portal-base/portal/src/views/layout.html.twig index 1f0588d7f4..2be659ad15 100644 --- a/datamodels/2.x/itop-portal-base/portal/src/views/layout.html.twig +++ b/datamodels/2.x/itop-portal-base/portal/src/views/layout.html.twig @@ -278,7 +278,7 @@
- +
@@ -304,13 +304,14 @@ sUrl += (sUrl.split('?')[1] ? '&':'?') + sParamName + '=' + sParamValue; return sUrl; }; - + var contentLoaderTemplate = '
{{ 'Page:PleaseWait'|dict_s }}
'; + $(document).ready(function(){ {% block pPageReadyScripts %} // Hack to enable a same modal to load content from different urls $('body').on('hidden.bs.modal', '.modal#modal-for-all', function () { $(this).removeData('bs.modal'); - $(this).find('.modal-content').html('
{{ 'Page:PleaseWait'|dict_s }}
'); + $(this).find('.modal-content').html(contentLoaderTemplate); }); // Hack to enable multiple modals by making sure the .modal-open class is set to the when there is at least one modal open left $('body').on('hidden.bs.modal', function () { @@ -323,6 +324,16 @@ $('body').on('show.bs.modal', function () { $(this).find('.tooltip.in').tooltip('hide'); }); + // Display a error message on modal if the content could not be loaded. + // Note : As of now, we can't display a more detailled message based on the response because Bootstrap doesn't pass response data with the loaded event. + $('body').on('loaded.bs.modal', function (oEvent) { + if($(oEvent.target).find('.modal-content').html().replace(/[\n\r\t]+/g, '') === contentLoaderTemplate) + { + $(oEvent.target).find('.modal-content').html($('#modal-for-alert .modal-content').html()); + $(oEvent.target).find('.modal-content .modal-header .modal-title').text('{{ 'Error:HTTP:500'|dict_s }}'); + $(oEvent.target).find('.modal-content .modal-body .alert').addClass('alert-danger').text('{{ 'Error:XHR:Fail'|dict_s }}'); + } + }); {% endblock %} });