(Retrofit from trunk) Portal : Enhanced and refactored error feedback on ExternalKey / LinkedSet / CustomFields fields

SVN:2.3[4368]
This commit is contained in:
Guillaume Lajarige
2016-09-02 12:02:01 +00:00
parent 28ead17d00
commit c380c19d2a
4 changed files with 30 additions and 9 deletions

View File

@@ -97,7 +97,7 @@
break; break;
case '{{ constant('Combodo\\iTop\\Portal\\Brick\\BrowseBrick::ENUM_ACTION_CREATE_FROM_THIS') }}': case '{{ constant('Combodo\\iTop\\Portal\\Brick\\BrowseBrick::ENUM_ACTION_CREATE_FROM_THIS') }}':
url = levelPrimaryAction.url.replace(/-objectClass-/, data.class).replace(/-objectId-/, data.id); url = levelPrimaryAction.url.replace(/-objectClass-/, data.class).replace(/-objectId-/, data.id);
url = addParameterToUrl(url, 'ar_token', data.action_rules_token[levelPrimaryAction.type]); url = AddParameterToUrl(url, 'ar_token', data.action_rules_token[levelPrimaryAction.type]);
cellElem.attr('data-toggle', 'modal').attr('data-target', '#modal-for-all').attr('href', url); cellElem.attr('data-toggle', 'modal').attr('data-target', '#modal-for-all').attr('href', url);
break; break;
default: default:
@@ -150,7 +150,7 @@
break; break;
case '{{ constant('Combodo\\iTop\\Portal\\Brick\\BrowseBrick::ENUM_ACTION_CREATE_FROM_THIS') }}': case '{{ constant('Combodo\\iTop\\Portal\\Brick\\BrowseBrick::ENUM_ACTION_CREATE_FROM_THIS') }}':
url = action.url.replace(/-objectClass-/, data.class).replace(/-objectId-/, data.id); url = action.url.replace(/-objectClass-/, data.class).replace(/-objectId-/, data.id);
url = addParameterToUrl(url, 'ar_token', data.action_rules_token[action.type]); url = AddParameterToUrl(url, 'ar_token', data.action_rules_token[action.type]);
actionElem.attr('data-toggle', 'modal').attr('data-target', '#modal-for-all').attr('href', url); actionElem.attr('data-toggle', 'modal').attr('data-target', '#modal-for-all').attr('href', url);
break; break;
default: default:

View File

@@ -223,7 +223,7 @@
break; break;
case '{{ constant('Combodo\\iTop\\Portal\\Brick\\BrowseBrick::ENUM_ACTION_CREATE_FROM_THIS') }}': case '{{ constant('Combodo\\iTop\\Portal\\Brick\\BrowseBrick::ENUM_ACTION_CREATE_FROM_THIS') }}':
url = levelPrimaryAction.url.replace(/-objectClass-/, item.class).replace(/-objectId-/, item.id); url = levelPrimaryAction.url.replace(/-objectClass-/, item.class).replace(/-objectId-/, item.id);
url = addParameterToUrl(url, 'ar_token', item.action_rules_token[levelPrimaryAction.type]); url = AddParameterToUrl(url, 'ar_token', item.action_rules_token[levelPrimaryAction.type]);
aElem.attr('data-toggle', 'modal').attr('data-target', '#modal-for-all').attr('href', url); aElem.attr('data-toggle', 'modal').attr('data-target', '#modal-for-all').attr('href', url);
break; break;
default: default:
@@ -275,7 +275,7 @@
break; break;
case '{{ constant('Combodo\\iTop\\Portal\\Brick\\BrowseBrick::ENUM_ACTION_CREATE_FROM_THIS') }}': case '{{ constant('Combodo\\iTop\\Portal\\Brick\\BrowseBrick::ENUM_ACTION_CREATE_FROM_THIS') }}':
url = action.url.replace(/-objectClass-/, item.class).replace(/-objectId-/, item.id); url = action.url.replace(/-objectClass-/, item.class).replace(/-objectId-/, item.id);
url = addParameterToUrl(url, 'ar_token', item.action_rules_token[action.type]); url = AddParameterToUrl(url, 'ar_token', item.action_rules_token[action.type]);
actionElem.attr('data-toggle', 'modal').attr('data-target', '#modal-for-all').attr('href', url); actionElem.attr('data-toggle', 'modal').attr('data-target', '#modal-for-all').attr('href', url);
break; break;
default: default:

View File

@@ -92,7 +92,7 @@
$(document).ready(function(){ $(document).ready(function(){
showTableLoader(); showTableLoader();
// Note : Those options should be externalized in an library so we can use them on any DataTables for the portal. // Note : Those options should be externalized in an library so we can use them on any DataTables for the portal.
// We would just have to override / complete the necessary elements // We would just have to override / complete the necessary elements
oTable = $('#{{ sTableId }}').DataTable({ oTable = $('#{{ sTableId }}').DataTable({
@@ -170,6 +170,24 @@
// Retrieving values from source form // Retrieving values from source form
d.current_values = $('[data-form-path="{{aSource.sFormPath}}"][data-field-id="{{aSource.sFieldId}}"]').closest('.portal_form_handler').portal_form_handler('getCurrentValues'); d.current_values = $('[data-form-path="{{aSource.sFormPath}}"][data-field-id="{{aSource.sFieldId}}"]').closest('.portal_form_handler').portal_form_handler('getCurrentValues');
{% endif %} {% endif %}
},
"error": function(oData, sError, sThrow){
if(oData.responseJSON !== undefined && oData.responseJSON !== null)
{
var oResponse = oData.responseJSON;
// If we encounter an error
if(oResponse.exception !== undefined)
{
// Note : This could be refactored for a global use
$('#{{ sTableId }}').closest('.modal').html( $('#modal-for-alert').html() );
var oModalElem = $('#{{ sTableId }}').closest('.modal');
oModalElem.find('.modal-title').html(oResponse.error_title);
oModalElem.find('.modal-body .alert').html(oResponse.error_message)
.removeClass('alert-success alert-info alert-warning alert-danger')
.addClass('alert-danger');
oModalElem.modal('show');
}
}
} }
} }
}); });

View File

@@ -295,19 +295,22 @@
{ {
return '{{ app['combodo.absolute_url'] }}'; return '{{ app['combodo.absolute_url'] }}';
}; };
var addParameterToUrl = function(sUrl, sParamName, sParamValue) var AddParameterToUrl = function(sUrl, sParamName, sParamValue)
{ {
sUrl += (sUrl.split('?')[1] ? '&':'?') + sParamName + '=' + sParamValue; sUrl += (sUrl.split('?')[1] ? '&':'?') + sParamName + '=' + sParamValue;
return sUrl; return sUrl;
}; };
var contentLoaderTemplate = '<div class="content_loader"><div class="icon glyphicon glyphicon-refresh"></div><div class="message">{{ 'Page:PleaseWait'|dict_s }}</div></div>'; var GetContentLoaderTemplate = function()
{
return '<div class="content_loader"><div class="icon glyphicon glyphicon-refresh"></div><div class="message">{{ 'Page:PleaseWait'|dict_s }}</div></div>';
}
$(document).ready(function(){ $(document).ready(function(){
{% block pPageReadyScripts %} {% block pPageReadyScripts %}
// Hack to enable a same modal to load content from different urls // Hack to enable a same modal to load content from different urls
$('body').on('hidden.bs.modal', '.modal#modal-for-all', function () { $('body').on('hidden.bs.modal', '.modal#modal-for-all', function () {
$(this).removeData('bs.modal'); $(this).removeData('bs.modal');
$(this).find('.modal-content').html(contentLoaderTemplate); $(this).find('.modal-content').html(GetContentLoaderTemplate());
}); });
// Hack to enable multiple modals by making sure the .modal-open class is set to the <body> when there is at least one modal open left // Hack to enable multiple modals by making sure the .modal-open class is set to the <body> when there is at least one modal open left
$('body').on('hidden.bs.modal', function () { $('body').on('hidden.bs.modal', function () {
@@ -325,7 +328,7 @@
$('body').on('loaded.bs.modal', function (oEvent) { $('body').on('loaded.bs.modal', function (oEvent) {
var sModalContent = $(oEvent.target).find('.modal-content').html(); var sModalContent = $(oEvent.target).find('.modal-content').html();
if( (sModalContent === '') || (sModalContent.replace(/[\n\r\t]+/g, '') === contentLoaderTemplate) ) if( (sModalContent === '') || (sModalContent.replace(/[\n\r\t]+/g, '') === GetContentLoaderTemplate()) )
{ {
$(oEvent.target).find('.modal-content').html($('#modal-for-alert .modal-content').html()); $(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-header .modal-title').text('{{ 'Error:HTTP:500'|dict_s }}');