Commit 2e4e8e07 authored by Andreas Fernandez's avatar Andreas Fernandez Committed by Benni Mack
Browse files

[TASK] Open ElementBrowser event based in FormEngine

Currently, the ElementBrowser is used in three different places in
FormEngine, all of them trigger it differently. This patch introduces
an event-driven approach and streamlines all usages.

Resolves: #88436
Releases: master
Change-Id: I13e696f29ade0aede6a2466cbca1e27cebc86c61
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60818

Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent d4533ea2
......@@ -31,7 +31,6 @@ enum Selectors {
controlSectionSelector = '.t3js-formengine-irre-control',
createNewRecordButtonSelector = '.t3js-create-new-button',
createNewRecordBySelectorSelector = '.t3js-create-new-selector',
insertRecordButtonSelector = '.t3js-insert-record-button',
deleteRecordButtonSelector = '.t3js-editform-delete-inline-record',
enableDisableRecordButtonSelector = '.t3js-toggle-visibility-button',
infoWindowButton = '[data-action="infowindow"]',
......@@ -142,24 +141,6 @@ class InlineControlContainer {
InfoWindow.showItem(target.dataset.infoTable, target.dataset.infoUid);
}
/**
* @param {Event} e
*/
private static registerInsertRecordButton(e: Event): void {
let target: HTMLElement;
if ((target = InlineControlContainer.getDelegatedEventTarget(e.target, Selectors.insertRecordButtonSelector)) === null) {
return;
}
e.preventDefault();
e.stopImmediatePropagation();
const mode = target.dataset.mode;
const params = target.dataset.params;
FormEngine.openPopupWindow(mode, params);
}
/**
* @param {string} objectId
*/
......@@ -273,7 +254,6 @@ class InlineControlContainer {
this.registerSort(e);
this.registerCreateRecordButton(e);
this.registerCreateRecordBySelector(e);
InlineControlContainer.registerInsertRecordButton(e);
this.registerEnableDisableButton(e);
InlineControlContainer.registerInfoButton(e);
this.registerDeleteButton(e);
......
......@@ -498,7 +498,7 @@ class InlineControlContainer extends AbstractContainer
$item = '';
if ($elementBrowserEnabled) {
$item .= '
<a href="#" class="btn btn-default t3js-insert-record-button" data-mode="' . htmlspecialchars($mode) . '" data-params="' . htmlspecialchars($browserParams) . '"
<a href="#" class="btn btn-default t3js-element-browser" data-mode="' . htmlspecialchars($mode) . '" data-params="' . htmlspecialchars($browserParams) . '"
' . $buttonStyle . ' title="' . $createNewRelationText . '">
' . $this->iconFactory->getIcon('actions-insert-record', Icon::SIZE_SMALL)->render() . '
' . $createNewRelationText . '
......
......@@ -71,17 +71,14 @@ class ElementBrowser extends AbstractNode
if (is_array($config['appearance']) && isset($config['appearance']['elementBrowserAllowed'])) {
$elementBrowserAllowed = $config['appearance']['elementBrowserAllowed'];
}
$elementBrowserOnClick = 'setFormValueOpenBrowser('
. GeneralUtility::quoteJSvalue($elementBrowserType) . ','
. GeneralUtility::quoteJSvalue($elementName . '|||' . $elementBrowserAllowed . '|' . $elementBrowserOnClickInline)
. ');'
. ' return false;';
return [
'iconIdentifier' => 'actions-insert-record',
'title' => $title,
'linkAttributes' => [
'onClick' => $elementBrowserOnClick,
'class' => 't3js-element-browser',
'data-mode' => htmlspecialchars($elementBrowserType),
'data-params' => htmlspecialchars($elementName . '|||' . $elementBrowserAllowed . '|' . $elementBrowserOnClickInline)
],
];
}
......
......@@ -41,9 +41,7 @@ class TableList extends AbstractNode
$config = $parameterArray['fieldConf']['config'];
$itemName = $parameterArray['itemFormElName'];
if (!isset($config['allowed']) || !is_string($config['allowed']) || empty($config['allowed'])
|| !isset($config['internal_type']) || $config['internal_type'] !== 'db'
) {
if (empty($config['allowed']) || !is_string($config['allowed']) || !isset($config['internal_type']) || $config['internal_type'] !== 'db') {
// No handling if the field has no, or funny "allowed" setting, and if internal_type is not "db"
return $result;
}
......@@ -59,13 +57,7 @@ class TableList extends AbstractNode
$allowedTablesHtml[] = '</span>';
} else {
$label = $languageService->sL($GLOBALS['TCA'][$tableName]['ctrl']['title']);
$onClick = [];
$onClick[] = 'setFormValueOpenBrowser(';
$onClick[] = '\'db\',';
$onClick[] = GeneralUtility::quoteJSvalue($itemName . '|||' . $tableName);
$onClick[] = ');';
$onClick[] = 'return false;';
$allowedTablesHtml[] = '<a href="#" onClick="' . htmlspecialchars(implode('', $onClick)) . '" class="btn btn-default">';
$allowedTablesHtml[] = '<a href="#" class="btn btn-default t3js-element-browser" data-mode="db" data-params="' . htmlspecialchars($itemName . '|||' . $tableName) . '">';
$allowedTablesHtml[] = $iconFactory->getIconForRecord($tableName, [], Icon::SIZE_SMALL)->render();
$allowedTablesHtml[] = htmlspecialchars($label);
$allowedTablesHtml[] = '</a>';
......
......@@ -537,6 +537,15 @@ define(['jquery',
FormEngine.toggleCheckboxField($(this));
}).on('change', function(event) {
$('.module-docheader-bar .btn').removeClass('disabled').prop('disabled', false);
}).on('click', '.t3js-element-browser', function(e) {
e.preventDefault();
e.stopPropagation();
const $me = $(e.currentTarget);
const mode = $me.data('mode');
const params = $me.data('params');
FormEngine.openPopupWindow(mode, params);
});
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment