diff --git a/application/displayblock.class.inc.php b/application/displayblock.class.inc.php index 2298eab30..822f37dcb 100644 --- a/application/displayblock.class.inc.php +++ b/application/displayblock.class.inc.php @@ -2321,10 +2321,15 @@ class MenuBlock extends DisplayBlock false ); + // creation form title + if (array_key_exists('creation_in_modal_form_title', $aExtraParams)) { + $oAddLinkActionButton->AddDataAttribute('modal-title', $aExtraParams['creation_in_modal_form_title']); + } + // - If we are used in a Datatable, 'datatable_' will be prefixed to our $sId, so we do the same here $sRealId = $sId; - if(in_array($this->m_sStyle, [static::ENUM_STYLE_LIST, 'links', static::ENUM_STYLE_LIST_IN_OBJECT])){ - $sRealId = 'datatable_' . $sId; + if (in_array($this->m_sStyle, [static::ENUM_STYLE_LIST, 'links', static::ENUM_STYLE_LIST_IN_OBJECT])) { + $sRealId = 'datatable_'.$sId; } $oAddLinkActionButton->AddCSSClasses(['ibo-action-button', 'ibo-regular-action-button']) ->SetOnClickJsCode("$('#$sRealId').trigger('open_creation_modal.object.itop');"); diff --git a/js/links/links_view_table_widget.js b/js/links/links_view_table_widget.js index 362be11af..6bf42e226 100644 --- a/js/links/links_view_table_widget.js +++ b/js/links/links_view_table_widget.js @@ -78,6 +78,11 @@ $(function() // retrieve new button const $NewButton = $('[name="UI:Links:New"]', this.element); const sButtonTooltipContent = $NewButton.attr('data-tooltip-content'); + let sButtonTitleContent = $NewButton.attr('data-modal-title'); + + let aParams = { + form_title: sButtonTitleContent + } // retrieve context parameters const sClass = $Table.closest('[data-role="ibo-block-links-table"]').attr('data-link-class'); @@ -93,7 +98,8 @@ $(function() if(data.success){ me.$tableSettingsDialog.DataTableSettings('DoRefresh'); } - }); + }, + aParams); }, /** @@ -114,12 +120,13 @@ $(function() sButtonTitleContent = sButtonTitleContent.replaceAll('{item}', sRemoteFriendlyname); // Specify that external key to host object will be readonly - let aReadOnlyParams = { + let aParams = { 'readonly': { } + } - aReadOnlyParams['readonly'][this.options.external_key_to_me] = 1; - aReadOnlyParams['form_title'] = sButtonTitleContent; + aParams['readonly'][this.options.external_key_to_me] = 1; + aParams['form_title'] = sButtonTitleContent; // link object modification iTopObjectWorker.ModifyObject(sButtonTooltipContent, this.options.link_class, sLinkedObjectKey, function () { @@ -130,7 +137,7 @@ $(function() me.$tableSettingsDialog.DataTableSettings('DoRefresh'); } }, - aReadOnlyParams); + aParams); }, }); diff --git a/js/links/linkset-worker.js b/js/links/linkset-worker.js index ef4ddc9c2..9240c4425 100644 --- a/js/links/linkset-worker.js +++ b/js/links/linkset-worker.js @@ -53,19 +53,25 @@ const iTopLinkSetWorker = new function(){ * @param {string} sHostObjectId * @param oOnModalCloseCallback * @param oOnFormSubmittedCallback + * @param {Object} aAdditionalData */ - const CallAjaxCreateLinkedObject = function(sModalTitle, sClass, sAttCode, sHostObjectClass, sHostObjectId, oOnModalCloseCallback = null, oOnFormSubmittedCallback = null){ + const CallAjaxCreateLinkedObject = function(sModalTitle, sClass, sAttCode, sHostObjectClass, sHostObjectId, oOnModalCloseCallback = null, oOnFormSubmittedCallback = null, aAdditionalData = []){ + + let aData = $.extend( + { + class: sClass, + att_code: sAttCode, + host_class: sHostObjectClass, + host_id: sHostObjectId + }, + aAdditionalData + ); let oOptions = { title: sModalTitle, content: { endpoint: `${ROUTER_BASE_URL}?route=${ROUTE_LINK_SET_CREATE_OBJECT}`, - data: { - class: sClass, - att_code: sAttCode, - host_class: sHostObjectClass, - host_id: sHostObjectId - } + data: aData, }, extra_options: { callback_on_modal_close: oOnModalCloseCallback diff --git a/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php b/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php index 356ede615..545bb92a3 100644 --- a/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php +++ b/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php @@ -935,6 +935,8 @@ JS; /** bool to perform a creation of a new object of this type in a modal */ 'creation_in_modal_tooltip', /** creation in modal button tooltip */ + 'creation_in_modal_form_title', + /** creation in modal form title */ 'creation_in_modal_js_handler', /** Handler to call when trying to create a new object in modal */ 'creation_disallowed', diff --git a/sources/Application/UI/Links/AbstractBlockLinkSetViewTable.php b/sources/Application/UI/Links/AbstractBlockLinkSetViewTable.php index 294cc0d25..ee2d91546 100644 --- a/sources/Application/UI/Links/AbstractBlockLinkSetViewTable.php +++ b/sources/Application/UI/Links/AbstractBlockLinkSetViewTable.php @@ -43,8 +43,10 @@ abstract class AbstractBlockLinkSetViewTable extends UIContentBlock ]; // Dictionnary entries - public const BUTTON_TOOLTIP = 'UI:Links:Add:Button+'; + public const DICT_ADD_BUTTON_TOOLTIP = 'UI:Links:Add:Button+'; + public const DICT_ADD_MODAL_TITLE = 'UI:Links:Add:Modal:Title'; public const DICT_CREATE_BUTTON_TOOLTIP = 'UI:Links:Create:Button+'; + public const DICT_CREATE_MODAL_TITLE = 'UI:Links:Create:Modal:Title'; public const DICT_MODIFY_LINK_BUTTON_TOOLTIP = 'UI:Links:ModifyLink:Button+'; public const DICT_MODIFY_LINK_MODAL_TITLE = 'UI:Links:ModifyLink:Modal:Title'; public const DICT_MODIFY_OBJECT_BUTTON_TOOLTIP = 'UI:Links:ModifyObject:Button+'; diff --git a/sources/Application/UI/Links/Direct/BlockDirectLinkSetViewTable.php b/sources/Application/UI/Links/Direct/BlockDirectLinkSetViewTable.php index 77c01cc9a..9a8d51a12 100644 --- a/sources/Application/UI/Links/Direct/BlockDirectLinkSetViewTable.php +++ b/sources/Application/UI/Links/Direct/BlockDirectLinkSetViewTable.php @@ -53,7 +53,8 @@ class BlockDirectLinkSetViewTable extends AbstractBlockLinkSetViewTable && $this->oAttDef->GetEditMode() != LINKSET_EDITMODE_NONE && $this->bIsAllowCreate) { $aExtraParams['creation_in_modal'] = true; - $aExtraParams['creation_in_modal_tooltip'] = $this->GetDictionaryEntry(static::DICT_CREATE_BUTTON_TOOLTIP); + $aExtraParams['creation_in_modal_tooltip'] = $this->oAttDef->GetEditMode() == LINKSET_EDITMODE_ADDREMOVE ? $this->GetDictionaryEntry(static::DICT_ADD_BUTTON_TOOLTIP) : $this->GetDictionaryEntry(static::DICT_CREATE_BUTTON_TOOLTIP); + $aExtraParams['creation_in_modal_form_title'] = $this->oAttDef->GetEditMode() == LINKSET_EDITMODE_ADDREMOVE ? $this->GetDictionaryEntry(static::DICT_ADD_MODAL_TITLE) : $this->GetDictionaryEntry(static::DICT_CREATE_MODAL_TITLE); $aExtraParams['creation_in_modal_js_handler'] = "{$this->GetWidgetName()}.links_view_table('CreateLinkedObject');"; } else { $aExtraParams['creation_disallowed'] = true; @@ -111,13 +112,13 @@ class BlockDirectLinkSetViewTable extends AbstractBlockLinkSetViewTable 'color' => Button::ENUM_COLOR_SCHEME_DESTRUCTIVE, 'js_row_action' => "{$this->GetWidgetName()}.links_view_table('DeleteLinkedObject', aRowData['{$this->oAttDef->GetLinkedClass()}/_key_/raw'], oTrElement);", 'confirmation' => [ - 'title' => $this->GetDictionaryEntry(static::DICT_DELETE_MODAL_TITLE), - 'message' => $this->GetDictionaryEntry(static::DICT_DELETE_MODAL_MESSAGE), - 'confirm_button_class' => 'ibo-is-danger', - 'row_data' => "{$this->sTargetClass}/hyperlink", - 'do_not_show_again_pref_key' => $this->GetDoNotShowAgainPreferenceKey(), - ], - ); + 'title' => $this->GetDictionaryEntry(static::DICT_DELETE_MODAL_TITLE), + 'message' => $this->GetDictionaryEntry(static::DICT_DELETE_MODAL_MESSAGE), + 'confirm_button_class' => 'ibo-is-danger', + 'row_data' => "{$this->sTargetClass}/hyperlink", + 'do_not_show_again_pref_key' => $this->GetDoNotShowAgainPreferenceKey(), + ], + ); } break; diff --git a/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetViewTable.php b/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetViewTable.php index 573d8df6b..94f222f6c 100644 --- a/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetViewTable.php +++ b/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetViewTable.php @@ -63,7 +63,8 @@ class BlockIndirectLinkSetViewTable extends AbstractBlockLinkSetViewTable if (!$this->oAttDef->GetReadOnly() && $this->bIsAllowCreate) { $aExtraParams['creation_in_modal'] = true; - $aExtraParams['creation_in_modal_tooltip'] = $this->GetDictionaryEntry(static::BUTTON_TOOLTIP); + $aExtraParams['creation_in_modal_tooltip'] = $this->GetDictionaryEntry(static::DICT_ADD_BUTTON_TOOLTIP); + $aExtraParams['creation_in_modal_form_title'] = $this->GetDictionaryEntry(static::DICT_ADD_MODAL_TITLE); $aExtraParams['creation_in_modal_js_handler'] = "{$this->GetWidgetName()}.links_view_table('CreateLinkedObject');"; } else { $aExtraParams['creation_disallowed'] = true; diff --git a/sources/Controller/Links/LinkSetController.php b/sources/Controller/Links/LinkSetController.php index ca59a972e..57cbc740e 100644 --- a/sources/Controller/Links/LinkSetController.php +++ b/sources/Controller/Links/LinkSetController.php @@ -142,6 +142,7 @@ class LinkSetController extends AbstractController $sAttCode = utils::ReadParam('att_code', '', false, 'raw'); $sClass = utils::ReadParam('host_class', '', false, 'class'); $sId = utils::ReadParam('host_id', '', false, 'integer'); + $sFormTitle = utils::ReadPostedParam('form_title', null, utils::ENUM_SANITIZATION_FILTER_STRING); // For security reasons: check that the "proposed" class is actually a subclass of the linked class // and that the current user is allowed to create objects of this class @@ -202,17 +203,7 @@ class LinkSetController extends AbstractController } JS; - - // Form title - /** @var \AttributeLinkedSet $oLinksetDef */ - $oLinksetDef = MetaModel::GetAttributeDef($sClass, $sAttCode); - $oHostObj = MetaModel::GetObject($sClass, $sId); - $sFormTitle = $oLinksetDef->SearchSpecificLabel('UI:Links:Add:Modal:Title', '', true, - MetaModel::GetName($sClass), - $oHostObj->Get('friendlyname'), - $oLinksetDef->GetLabel(), - MetaModel::GetName(LinkSetModel::GetTargetClass($oLinksetDef))); - + $aExtraParams = [ 'noRelations' => true, 'hide_transitions' => true,