diff --git a/datamodels/2.x/itop-portal-base/portal/public/js/bootstrap-portal-modal.js b/datamodels/2.x/itop-portal-base/portal/public/js/bootstrap-portal-modal.js index 56446eabb..e71499b12 100644 --- a/datamodels/2.x/itop-portal-base/portal/public/js/bootstrap-portal-modal.js +++ b/datamodels/2.x/itop-portal-base/portal/public/js/bootstrap-portal-modal.js @@ -14,132 +14,8 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * - * */ -/** - * Creates a Bootstrap modal dialog from a base modal element (template or reusable one) and loads the content while displaying a nice loader. - * - * Technical: We made this to work around the base modal interactions as it was not possible to define a loader, nor to clone the base modal natively. - * - * @param oOptions - * @constructor - * @since 2.7.0 - */ -var CreatePortalModal = function (oOptions) -{ - // Set default options - oOptions = $.extend( - true, - { - id: null, // ID of the created modal - attributes: {}, // HTML attributes - base_modal: { - usage: 'clone', // Either 'clone' or 'replace' - selector: '#modal-for-all' // Either a selector of the modal element used to base this one on or the modal element itself - }, - content: undefined, // Either a string, an object containing the endpoint / data or undefined to keep base modal content as-is - size: 'lg', // Either 'xs' / 'sm' / 'md' / 'lg' - }, - oOptions - ); - - // Compute modal selector - var oSelectorElem = null; - switch(typeof oOptions.base_modal.selector) - { - case 'string': - oSelectorElem = $(oOptions.base_modal.selector); - break; - - case 'object': - oSelectorElem = oOptions.base_modal.selector; - break; - - default: - if (window.console && window.console.warn) - { - console.warn('Could not open modal dialog as the select option was malformed: ', oOptions.content); - } - break; - } - - // Get modal element by either - var oModalElem = null; - // - Create a new modal from template - // Note : This could be better if we check for an existing modal first instead of always creating a new one - if (oOptions.base_modal.usage === 'clone') - { - oModalElem = oSelectorElem.clone(); - oModalElem.attr('id', oOptions.id) - .appendTo('body'); - } - // - Get an existing modal in the DOM - else - { - oModalElem = oSelectorElem; - } - - // Set attributes - for(var sProp in oOptions.attributes) - { - oModalElem.attr(sProp, oOptions.attributes[sProp]); - } - - // Resize to small modal - oModalElem.find('.modal-dialog') - .removeClass('modal-lg') - .addClass('modal-' + oOptions.size); - - // Load content - switch (typeof oOptions.content) - { - case 'string': - oModalElem.find('.modal-content').html(oOptions.content); - - //Manually triggers bootstrap event in order to keep listeners working - oModalElem.trigger('loaded.bs.modal'); - break; - - case 'object': - // Put loader while fetching content - oModalElem.find('.modal-content').html($('#page_overlay .overlay_content').html()); - // Fetch content in background - oModalElem.find('.modal-content').load( - oOptions.content.endpoint, - oOptions.content.data || {}, - function (sResponseText, sStatus) - { - // Hiding modal in case of error as the general AJAX error handler will display a message - if (sStatus === 'error') - { - oModalElem.modal('hide'); - } - - //Manually triggers bootstrap event in order to keep listeners working - oModalElem.trigger('loaded.bs.modal'); - } - ); - break; - - case 'undefined': - // Do nothing, we keep the content as-is - break; - - default: - if (window.console && window.console.warn) - { - console.warn('Could not open modal dialog as the content option was malformed: ', oOptions.content); - } - } - - // Show modal - oModalElem.modal('show'); - - return oModalElem; -}; - $(document).ready(function() { var oBodyElem = $('body'); @@ -196,6 +72,6 @@ $(document).ready(function() }; } - CreatePortalModal(oOptions); + CombodoPortalToolbox.OpenModal(oOptions); }); }); \ No newline at end of file diff --git a/datamodels/2.x/itop-portal-base/portal/public/js/portal_form_handler.js b/datamodels/2.x/itop-portal-base/portal/public/js/portal_form_handler.js index 281ebda4a..e34364c5b 100644 --- a/datamodels/2.x/itop-portal-base/portal/public/js/portal_form_handler.js +++ b/datamodels/2.x/itop-portal-base/portal/public/js/portal_form_handler.js @@ -195,7 +195,7 @@ $(function() if(bRedirectionAjax) { // Creating a new modal - CreatePortalModal({ + CombodoPortalToolbox.OpenModal({ content: { endpoint: sUrl, data: { diff --git a/datamodels/2.x/itop-portal-base/portal/templates/bricks/create/modal.html.twig b/datamodels/2.x/itop-portal-base/portal/templates/bricks/create/modal.html.twig index fe9cbbb31..147de59a1 100644 --- a/datamodels/2.x/itop-portal-base/portal/templates/bricks/create/modal.html.twig +++ b/datamodels/2.x/itop-portal-base/portal/templates/bricks/create/modal.html.twig @@ -25,7 +25,7 @@ sUrl = AddParameterToUrl(sUrl, 'ar_token', '{{ ar_token }}'); // Creating a new modal - CreatePortalModal({ + CombodoPortalToolbox.OpenModal({ base_modal: { usage: 'replace', selector: $(this).closest('.modal'), diff --git a/datamodels/2.x/itop-portal-base/portal/templates/bricks/object/mode_search_regular.html.twig b/datamodels/2.x/itop-portal-base/portal/templates/bricks/object/mode_search_regular.html.twig index f5919406a..fa6b99bf9 100644 --- a/datamodels/2.x/itop-portal-base/portal/templates/bricks/object/mode_search_regular.html.twig +++ b/datamodels/2.x/itop-portal-base/portal/templates/bricks/object/mode_search_regular.html.twig @@ -143,7 +143,7 @@ oEvent.stopPropagation(); // Creating a new modal - CreatePortalModal({ + CombodoPortalToolbox.OpenModal({ content: { endpoint: $(this).attr('href'), }, diff --git a/sources/renderer/bootstrap/fieldrenderer/bslinkedsetfieldrenderer.class.inc.php b/sources/renderer/bootstrap/fieldrenderer/bslinkedsetfieldrenderer.class.inc.php index 74fa22e1e..e701cd193 100644 --- a/sources/renderer/bootstrap/fieldrenderer/bslinkedsetfieldrenderer.class.inc.php +++ b/sources/renderer/bootstrap/fieldrenderer/bslinkedsetfieldrenderer.class.inc.php @@ -1,21 +1,22 @@ +/** + * Copyright (C) 2013-2019 Combodo SARL + * + * This file is part of iTop. + * + * iTop is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * iTop is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + */ namespace Combodo\iTop\Renderer\Bootstrap\FieldRenderer; @@ -253,7 +254,7 @@ EOF oEvent.stopPropagation(); // Note : This could be better if we check for an existing modal first instead of always creating a new one - CreatePortalModal({ + CombodoPortalToolbox.OpenModal({ content: { endpoint: $(this).attr('href'), }, @@ -531,7 +532,7 @@ EOF 'selector': '.modal[data-source-element="{$sButtonAddId}"]:first' }; } - CreatePortalModal(oOptions); + CombodoPortalToolbox.OpenModal(oOptions); }); JS ); diff --git a/sources/renderer/bootstrap/fieldrenderer/bsselectobjectfieldrenderer.class.inc.php b/sources/renderer/bootstrap/fieldrenderer/bsselectobjectfieldrenderer.class.inc.php index 106865926..2cb692500 100644 --- a/sources/renderer/bootstrap/fieldrenderer/bsselectobjectfieldrenderer.class.inc.php +++ b/sources/renderer/bootstrap/fieldrenderer/bsselectobjectfieldrenderer.class.inc.php @@ -16,8 +16,6 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * - * */ namespace Combodo\iTop\Renderer\Bootstrap\FieldRenderer; @@ -388,7 +386,7 @@ EOF <<