diff --git a/Build/Sources/TypeScript/form/backend/form-editor/modals-component.ts b/Build/Sources/TypeScript/form/backend/form-editor/modals-component.ts new file mode 100644 index 000000000000..66460a72126e --- /dev/null +++ b/Build/Sources/TypeScript/form/backend/form-editor/modals-component.ts @@ -0,0 +1,436 @@ +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +/** + * Module: @typo3/form/backend/form-editor/modals-component + */ +import $ from 'jquery'; +import * as Helper from '@typo3/form/backend/form-editor/helper'; +import Modal, { Button } from '@typo3/backend/modal'; +import Severity from '@typo3/backend/severity'; +import type { + FormEditor, +} from '@typo3/form/backend/form-editor'; +import type { + Utility, + FormEditorDefinitions, + FormElement, + FormElementDefinition, + NoInfer, + PublisherSubscriber, + ValidationResultsRecursive +} from '@typo3/form/backend/form-editor/core'; +import type { + Configuration as HelperConfiguration, +} from '@typo3/form/backend/form-editor/helper'; + +export interface InsertElementsModalConfiguration { + disableElementTypes: string[], + onlyEnableElementTypes?: string[], +} + +let configuration: HelperConfiguration = null; + +const defaultConfiguration: Partial = { + domElementClassNames: { + buttonDefault: 'btn-default', + buttonInfo: 'btn-info', + buttonWarning: 'btn-warning' + }, + domElementDataAttributeNames: { + elementType: 'element-type', + fullElementType: 'data-element-type' + }, + domElementDataAttributeValues: { + rowItem: 'rowItem', + rowLink: 'rowLink', + rowsContainer: 'rowsContainer', + templateInsertElements: 'Modal-InsertElements', + templateInsertPages: 'Modal-InsertPages', + templateValidationErrors: 'Modal-ValidationErrors' + } +}; + +let formEditorApp: FormEditor = null; + +function getFormEditorApp(): FormEditor { + return formEditorApp; +} + +function getHelper(_configuration?: HelperConfiguration): typeof Helper { + if (getUtility().isUndefinedOrNull(_configuration)) { + return Helper.setConfiguration(configuration); + } + return Helper.setConfiguration(_configuration); +} + +function getUtility(): Utility { + return getFormEditorApp().getUtility(); +} + +function assert(test: boolean|(() => boolean), message: string, messageCode: number): void { + return getFormEditorApp().assert(test, message, messageCode); +} + +function getRootFormElement(): FormElement { + return getFormEditorApp().getRootFormElement(); +} + +function getPublisherSubscriber(): PublisherSubscriber { + return getFormEditorApp().getPublisherSubscriber(); +} + +function getFormElementDefinition( + formElement: FormElement, + formElementDefinitionKey?: T +): T extends keyof FormElementDefinition ? FormElementDefinition[T] : FormElementDefinition { + return getFormEditorApp().getFormElementDefinition(formElement, formElementDefinitionKey); +} + +/** + * @throws 1478889044 + * @throws 1478889049 + */ +function showRemoveElementModal( + publisherTopicName: T, + publisherTopicArguments: NoInfer +): void { + const modalButtons: Button[] = []; + assert( + getUtility().isNonEmptyString(publisherTopicName), + 'Invalid parameter "publisherTopicName"', + 1478889049 + ); + assert( + 'array' === $.type(publisherTopicArguments), + 'Invalid parameter "formElement"', + 1478889044 + ); + + modalButtons.push({ + text: getFormElementDefinition(getRootFormElement(), 'modalRemoveElementCancelButton'), + active: true, + btnClass: getHelper().getDomElementClassName('buttonDefault'), + name: 'cancel', + trigger: (e, modal) => { + modal.hideModal(); + } + }); + + modalButtons.push({ + text: getFormElementDefinition(getRootFormElement(), 'modalRemoveElementConfirmButton'), + active: true, + btnClass: getHelper().getDomElementClassName('buttonWarning'), + name: 'confirm', + trigger: (e, modal) => { + getPublisherSubscriber().publish(publisherTopicName, publisherTopicArguments); + modal.hideModal(); + } + }); + + Modal.show( + getFormElementDefinition(getRootFormElement(), 'modalRemoveElementDialogTitle'), + getFormElementDefinition(getRootFormElement(), 'modalRemoveElementDialogMessage'), + Severity.warning, + modalButtons + ); +} + +/** + * @publish mixed + * @throws 1478910954 + */ +function insertElementsModalSetup( + modalContent: JQuery, + publisherTopicName: keyof PublisherSubscriberTopicArgumentsMap, + configuration?: InsertElementsModalConfiguration +): void { + assert( + getUtility().isNonEmptyString(publisherTopicName), + 'Invalid parameter "publisherTopicName"', + 1478910954 + ); + + if ('object' === $.type(configuration)) { + for (const key of Object.keys(configuration)) { + if ( + key === 'disableElementTypes' + && 'array' === $.type(configuration[key]) + ) { + for (let i = 0, len = configuration[key].length; i < len; ++i) { + $( + getHelper().getDomElementDataAttribute( + 'fullElementType', + 'bracesWithKeyValue', [configuration[key][i]] + ), + modalContent + ).addClass(getHelper().getDomElementClassName('disabled')); + } + } + + if ( + key === 'onlyEnableElementTypes' + && 'array' === $.type(configuration[key]) + ) { + $( + getHelper().getDomElementDataAttribute( + 'fullElementType', + 'bracesWithKey' + ), + modalContent + ).each(function(this: HTMLElement) { + for (let i = 0, len = configuration[key].length; i < len; ++i) { + const that = $(this); + if (that.data(getHelper().getDomElementDataAttribute('elementType')) !== configuration[key][i]) { + that.addClass(getHelper().getDomElementClassName('disabled')); + } + } + }); + } + } + } + + $('a', modalContent).on('click', function(this: HTMLElement) { + getPublisherSubscriber().publish(publisherTopicName, [$(this).data(getHelper().getDomElementDataAttribute('elementType'))]); + $('a', modalContent).off(); + Modal.currentModal.hideModal(); + }); +} + +/** + * @publish view/modal/validationErrors/element/clicked + * @throws 1479161268 + */ +function _validationErrorsModalSetup( + modalContent: JQuery, + validationResults: ValidationResultsRecursive +): void { + let formElement, newRowItem; + + assert( + 'array' === $.type(validationResults), + 'Invalid parameter "validationResults"', + 1479161268 + ); + + const rowItemTemplate = $( + getHelper().getDomElementDataIdentifierSelector('rowItem'), + modalContent + ).clone(); + + $(getHelper().getDomElementDataIdentifierSelector('rowItem'), modalContent).remove(); + + for (let i = 0, len = validationResults.length; i < len; ++i) { + let hasError = false; + for (let j = 0, len2 = validationResults[i].validationResults.length; j < len2; ++j) { + if ( + validationResults[i].validationResults[j].validationResults + && validationResults[i].validationResults[j].validationResults.length > 0 + ) { + hasError = true; + break; + } + } + + if (hasError) { + formElement = getFormEditorApp() + .getFormElementByIdentifierPath(validationResults[i].formElementIdentifierPath); + newRowItem = rowItemTemplate.clone(); + $(getHelper().getDomElementDataIdentifierSelector('rowLink'), newRowItem) + .attr( + getHelper().getDomElementDataAttribute('elementIdentifier'), + validationResults[i].formElementIdentifierPath + ) + .get(0).replaceChildren(_buildTitleByFormElement(formElement)); + $(getHelper().getDomElementDataIdentifierSelector('rowsContainer'), modalContent) + .append(newRowItem); + } + } + + $('a', modalContent).on('click', function(this: HTMLElement) { + getPublisherSubscriber().publish('view/modal/validationErrors/element/clicked', [ + $(this).attr(getHelper().getDomElementDataAttribute('elementIdentifier')) + ]); + $('a', modalContent).off(); + Modal.currentModal.hideModal(); + }); +} + +/** + * @throws 1479162557 + */ +function _buildTitleByFormElement(formElement: FormElement): HTMLElement { + assert('object' === $.type(formElement), 'Invalid parameter "formElement"', 1479162557); + + const span = document.createElement('span'); + span.textContent = formElement.get('label') ? formElement.get('label') : formElement.get('identifier'); + return span; +} + +/* ************************************************************* + * Public Methods + * ************************************************************/ + +/** + * @publish view/modal/removeFormElement/perform + */ +export function showRemoveFormElementModal(formElement: FormElement): void { + showRemoveElementModal('view/modal/removeFormElement/perform', [formElement]); +} + +/** + * @publish view/modal/removeCollectionElement/perform + * @throws 1478894420 + * @throws 1478894421 + */ +export function showRemoveCollectionElementModal( + collectionElementIdentifier: string, + collectionName: keyof FormEditorDefinitions, + formElement: FormElement +): void { + assert( + getUtility().isNonEmptyString(collectionElementIdentifier), + 'Invalid parameter "collectionElementIdentifier"', + 1478894420 + ); + assert( + getUtility().isNonEmptyString(collectionName), + 'Invalid parameter "collectionName"', + 1478894421 + ); + + showRemoveElementModal('view/modal/removeCollectionElement/perform', [collectionElementIdentifier, collectionName, formElement]); +} + +/** + * @publish view/modal/close/perform + */ +export function showCloseConfirmationModal(): void { + const modalButtons: Button[] = []; + + modalButtons.push({ + text: getFormElementDefinition(getRootFormElement(), 'modalCloseCancelButton'), + active: true, + btnClass: getHelper().getDomElementClassName('buttonDefault'), + name: 'cancel', + trigger: (e, modal) => { + modal.hideModal(); + } + }); + + modalButtons.push({ + text: getFormElementDefinition(getRootFormElement(), 'modalCloseConfirmButton'), + active: true, + btnClass: getHelper().getDomElementClassName('buttonWarning'), + name: 'confirm', + trigger: (e, modal) => { + getPublisherSubscriber().publish('view/modal/close/perform', []); + modal.hideModal(); + } + }); + + Modal.show( + getFormElementDefinition(getRootFormElement(), 'modalCloseDialogTitle'), + getFormElementDefinition(getRootFormElement(), 'modalCloseDialogMessage'), + Severity.warning, + modalButtons + ); +} + +export function showInsertElementsModal( + publisherTopicName: keyof PublisherSubscriberTopicArgumentsMap, + configuration: InsertElementsModalConfiguration +): void { + const template = getHelper().getTemplate('templateInsertElements'); + if (template.length > 0) { + const html = $(template.html()); + insertElementsModalSetup(html, publisherTopicName, configuration); + + Modal.show( + getFormElementDefinition(getRootFormElement(), 'modalInsertElementsDialogTitle'), + $(html), + Severity.info + ); + } +} + +export function showInsertPagesModal( + publisherTopicName: keyof PublisherSubscriberTopicArgumentsMap, +): void { + const template = getHelper().getTemplate('templateInsertPages'); + if (template.length > 0) { + const html = $(template.html()); + insertElementsModalSetup(html, publisherTopicName); + + Modal.show( + getFormElementDefinition(getRootFormElement(), 'modalInsertPagesDialogTitle'), + $(html), + Severity.info + ); + } +} + +export function showValidationErrorsModal(validationResults: ValidationResultsRecursive): void { + const modalButtons: Button[] = []; + + modalButtons.push({ + text: getFormElementDefinition(getRootFormElement(), 'modalValidationErrorsConfirmButton'), + active: true, + btnClass: getHelper().getDomElementClassName('buttonDefault'), + name: 'confirm', + trigger: function(e, modal) { + modal.hideModal(); + } + }); + + const template = getHelper().getTemplate('templateValidationErrors'); + if (template.length > 0) { + const html = $(template.html()).clone(); + _validationErrorsModalSetup(html, validationResults); + + Modal.show( + getFormElementDefinition(getRootFormElement(), 'modalValidationErrorsDialogTitle'), + html, + Severity.error, + modalButtons + ); + } +} + +export function bootstrap( + this: typeof import('./modals-component'), + _formEditorApp: FormEditor, + customConfiguration?: Partial +): typeof import('./modals-component') { + formEditorApp = _formEditorApp; + configuration = $.extend(true, defaultConfiguration, customConfiguration || {}); + Helper.bootstrap(formEditorApp); + return this; +} + +declare global { + interface PublisherSubscriberTopicArgumentsMap { + 'view/modal/removeFormElement/perform': readonly [ + formElement: FormElement + ]; + 'view/modal/removeCollectionElement/perform': readonly [ + collectionElementIdentifier: string, + collectionName: keyof FormEditorDefinitions, + formElement: FormElement + ]; + 'view/modal/close/perform': readonly []; + 'view/modal/validationErrors/element/clicked': readonly [ + elementIdentifier: string + ]; + } +} diff --git a/typo3/sysext/form/Resources/Public/JavaScript/backend/form-editor/modals-component.js b/typo3/sysext/form/Resources/Public/JavaScript/backend/form-editor/modals-component.js index c814d882f791..e9ac3f1a6a8e 100644 --- a/typo3/sysext/form/Resources/Public/JavaScript/backend/form-editor/modals-component.js +++ b/typo3/sysext/form/Resources/Public/JavaScript/backend/form-editor/modals-component.js @@ -10,548 +10,4 @@ * * The TYPO3 project - inspiring people to share! */ - -/** - * Module: @typo3/form/backend/form-editor/modals-component - */ -import $ from 'jquery'; -import * as Helper from '@typo3/form/backend/form-editor/helper.js'; -import Modal from '@typo3/backend/modal.js'; -import Severity from '@typo3/backend/severity.js'; -import Icons from '@typo3/backend/icons.js'; - -const { - bootstrap, - showCloseConfirmationModal, - showInsertElementsModal, - showInsertPagesModal, - showRemoveCollectionElementModal, - showRemoveFormElementModal, - showValidationErrorsModal, -} = factory($, Helper, Modal, Severity, Icons); - -export { - bootstrap, - showCloseConfirmationModal, - showInsertElementsModal, - showInsertPagesModal, - showRemoveCollectionElementModal, - showRemoveFormElementModal, - showValidationErrorsModal, -}; - -function factory($, Helper, Modal, Severity, Icons) { - return (function($, Helper, Modal, Severity, Icons) { - - /** - * @private - * - * @var object - */ - var _configuration = null; - - /** - * @private - * - * @var object - */ - var _defaultConfiguration = { - domElementClassNames: { - buttonDefault: 'btn-default', - buttonInfo: 'btn-info', - buttonWarning: 'btn-warning' - }, - domElementDataAttributeNames: { - elementType: 'element-type', - fullElementType: 'data-element-type' - }, - domElementDataAttributeValues: { - rowItem: 'rowItem', - rowLink: 'rowLink', - rowsContainer: 'rowsContainer', - templateInsertElements: 'Modal-InsertElements', - templateInsertPages: 'Modal-InsertPages', - templateValidationErrors: 'Modal-ValidationErrors' - } - }; - - /** - * @private - * - * @var object - */ - var _formEditorApp = null; - - /* ************************************************************* - * Private Methods - * ************************************************************/ - - /** - * @private - * - * @return void - * @throws 1478268638 - */ - function _helperSetup() { - assert('function' === $.type(Helper.bootstrap), - 'The view model helper does not implement the method "bootstrap"', - 1478268638 - ); - Helper.bootstrap(getFormEditorApp()); - }; - - /** - * @private - * - * @return object - */ - function getFormEditorApp() { - return _formEditorApp; - }; - - /** - * @public - * - * @param object - * @return object - */ - function getHelper(configuration) { - if (getUtility().isUndefinedOrNull(configuration)) { - return Helper.setConfiguration(_configuration); - } - return Helper.setConfiguration(configuration); - }; - - /** - * @private - * - * @return object - */ - function getUtility() { - return getFormEditorApp().getUtility(); - }; - - /** - * @private - * - * @param mixed test - * @param string message - * @param int messageCode - * @return void - */ - function assert(test, message, messageCode) { - return getFormEditorApp().assert(test, message, messageCode); - }; - - /** - * @private - * - * @return object - */ - function getRootFormElement() { - return getFormEditorApp().getRootFormElement(); - }; - - /** - * @private - * - * @return object - */ - function getPublisherSubscriber() { - return getFormEditorApp().getPublisherSubscriber(); - }; - - /** - * @private - * - * @param object - * @param string - * @return mixed - */ - function getFormElementDefinition(formElement, formElementDefinitionKey) { - return getFormEditorApp().getFormElementDefinition(formElement, formElementDefinitionKey); - }; - - /** - * @public - * - * @param string publisherTopicName - * @param object publisherTopicArguments - * @return void - * @throws 1478889044 - * @throws 1478889049 - */ - function _showRemoveElementModal(publisherTopicName, publisherTopicArguments) { - var modalButtons = []; - - assert( - getUtility().isNonEmptyString(publisherTopicName), - 'Invalid parameter "publisherTopicName"', - 1478889049 - ); - assert( - 'array' === $.type(publisherTopicArguments), - 'Invalid parameter "formElement"', - 1478889044 - ); - - modalButtons.push({ - text: getFormElementDefinition(getRootFormElement(), 'modalRemoveElementCancelButton'), - active: true, - btnClass: getHelper().getDomElementClassName('buttonDefault'), - name: 'cancel', - trigger: function(e, modal) { - modal.hideModal(); - } - }); - - modalButtons.push({ - text: getFormElementDefinition(getRootFormElement(), 'modalRemoveElementConfirmButton'), - active: true, - btnClass: getHelper().getDomElementClassName('buttonWarning'), - name: 'confirm', - trigger: function(e, modal) { - getPublisherSubscriber().publish(publisherTopicName, publisherTopicArguments); - modal.hideModal(); - } - }); - - Modal.show( - getFormElementDefinition(getRootFormElement(), 'modalRemoveElementDialogTitle'), - getFormElementDefinition(getRootFormElement(), 'modalRemoveElementDialogMessage'), - Severity.warning, - modalButtons - ); - }; - - /** - * @private - * - * @param object modalContent - * @param string publisherTopicName - * @param object configuration - * @return void - * @publish mixed - * @throws 1478910954 - */ - function _insertElementsModalSetup(modalContent, publisherTopicName, configuration) { - var formElementItems; - - assert( - getUtility().isNonEmptyString(publisherTopicName), - 'Invalid parameter "publisherTopicName"', - 1478910954 - ); - - if ('object' === $.type(configuration)) { - for (var key in configuration) { - if (!configuration.hasOwnProperty(key)) { - continue; - } - if ( - key === 'disableElementTypes' - && 'array' === $.type(configuration[key]) - ) { - for (var i = 0, len = configuration[key].length; i < len; ++i) { - $( - getHelper().getDomElementDataAttribute( - 'fullElementType', - 'bracesWithKeyValue', [configuration[key][i]] - ), - modalContent - ).addClass(getHelper().getDomElementClassName('disabled')); - } - } - - if ( - key === 'onlyEnableElementTypes' - && 'array' === $.type(configuration[key]) - ) { - $( - getHelper().getDomElementDataAttribute( - 'fullElementType', - 'bracesWithKey' - ), - modalContent - ).each(function(i, element) { - for (var i = 0, len = configuration[key].length; i < len; ++i) { - var that = $(this); - if (that.data(getHelper().getDomElementDataAttribute('elementType')) !== configuration[key][i]) { - that.addClass(getHelper().getDomElementClassName('disabled')); - } - } - }); - } - } - } - - $('a', modalContent).on("click", function(e) { - getPublisherSubscriber().publish(publisherTopicName, [$(this).data(getHelper().getDomElementDataAttribute('elementType'))]); - $('a', modalContent).off(); - Modal.currentModal.hideModal(); - }); - }; - - /** - * @private - * - * @param object modalContent - * @param object validationResults - * @return void - * @publish view/modal/validationErrors/element/clicked - * @throws 1479161268 - */ - function _validationErrorsModalSetup(modalContent, validationResults) { - var formElement, newRowItem, rowItemTemplate; - - assert( - 'array' === $.type(validationResults), - 'Invalid parameter "validationResults"', - 1479161268 - ); - - rowItemTemplate = $( - getHelper().getDomElementDataIdentifierSelector('rowItem'), - modalContent - ).clone(); - - $(getHelper().getDomElementDataIdentifierSelector('rowItem'), modalContent).remove(); - - for (var i = 0, len = validationResults.length; i < len; ++i) { - var hasError = false, validationElement; - for (var j = 0, len2 = validationResults[i]['validationResults'].length; j < len2; ++j) { - if ( - validationResults[i]['validationResults'][j]['validationResults'] - && validationResults[i]['validationResults'][j]['validationResults'].length > 0 - ) { - hasError = true; - break; - } - } - - if (hasError) { - formElement = getFormEditorApp() - .getFormElementByIdentifierPath(validationResults[i]['formElementIdentifierPath']); - newRowItem = rowItemTemplate.clone(); - $(getHelper().getDomElementDataIdentifierSelector('rowLink'), newRowItem) - .attr( - getHelper().getDomElementDataAttribute('elementIdentifier'), - validationResults[i]['formElementIdentifierPath'] - ) - .html(_buildTitleByFormElement(formElement)); - $(getHelper().getDomElementDataIdentifierSelector('rowsContainer'), modalContent) - .append(newRowItem); - } - } - - $('a', modalContent).on("click", function(e) { - getPublisherSubscriber().publish('view/modal/validationErrors/element/clicked', [ - $(this).attr(getHelper().getDomElementDataAttribute('elementIdentifier')) - ]); - $('a', modalContent).off(); - Modal.currentModal.hideModal(); - }); - }; - - /** - * @private - * - * @param object - * @return object - * @throws 1479162557 - */ - function _buildTitleByFormElement(formElement) { - var label; - assert('object' === $.type(formElement), 'Invalid parameter "formElement"', 1479162557); - - return $('').text((formElement.get('label') - ? formElement.get('label') - : formElement.get('identifier'))); - }; - - /* ************************************************************* - * Public Methods - * ************************************************************/ - - /** - * @public - * - * @param object formElement - * @return void - * @publish view/modal/removeFormElement/perform - */ - function showRemoveFormElementModal(formElement) { - _showRemoveElementModal('view/modal/removeFormElement/perform', [formElement]); - }; - - /** - * @public - * - * @param string collectionElementIdentifier - * @param string collectionName - * @param object formElement - * @return void - * @publish view/modal/removeCollectionElement/perform - * @throws 1478894420 - * @throws 1478894421 - */ - function showRemoveCollectionElementModal(collectionElementIdentifier, collectionName, formElement) { - assert( - getUtility().isNonEmptyString(collectionElementIdentifier), - 'Invalid parameter "collectionElementIdentifier"', - 1478894420 - ); - assert( - getUtility().isNonEmptyString(collectionName), - 'Invalid parameter "collectionName"', - 1478894421 - ); - - _showRemoveElementModal('view/modal/removeCollectionElement/perform', [collectionElementIdentifier, collectionName, formElement]); - }; - - /** - * @public - * - * @return void - * @publish view/modal/close/perform - */ - function showCloseConfirmationModal() { - var modalButtons = []; - - modalButtons.push({ - text: getFormElementDefinition(getRootFormElement(), 'modalCloseCancelButton'), - active: true, - btnClass: getHelper().getDomElementClassName('buttonDefault'), - name: 'cancel', - trigger: function(e, modal) { - modal.hideModal(); - } - }); - - modalButtons.push({ - text: getFormElementDefinition(getRootFormElement(), 'modalCloseConfirmButton'), - active: true, - btnClass: getHelper().getDomElementClassName('buttonWarning'), - name: 'confirm', - trigger: function(e, modal) { - getPublisherSubscriber().publish('view/modal/close/perform', []); - modal.hideModal(); - } - }); - - Modal.show( - getFormElementDefinition(getRootFormElement(), 'modalCloseDialogTitle'), - getFormElementDefinition(getRootFormElement(), 'modalCloseDialogMessage'), - Severity.warning, - modalButtons - ); - }; - - /** - * @public - * - * @param string - * @param object - * @return void - */ - function showInsertElementsModal(publisherTopicName, configuration) { - var html, template; - - template = getHelper().getTemplate('templateInsertElements'); - if (template.length > 0) { - html = $(template.html()); - _insertElementsModalSetup(html, publisherTopicName, configuration); - - Modal.show( - getFormElementDefinition(getRootFormElement(), 'modalInsertElementsDialogTitle'), - $(html), - Severity.info - ); - } - }; - - /** - * @public - * - * @param string - * @return void - */ - function showInsertPagesModal(publisherTopicName) { - var html, template; - - template = getHelper().getTemplate('templateInsertPages'); - if (template.length > 0) { - html = $(template.html()); - _insertElementsModalSetup(html, publisherTopicName); - - Modal.show( - getFormElementDefinition(getRootFormElement(), 'modalInsertPagesDialogTitle'), - $(html), - Severity.info - ); - } - }; - - /** - * @public - * - * @param object - * @return void - */ - function showValidationErrorsModal(validationResults) { - var html, template, modalButtons = []; - - modalButtons.push({ - text: getFormElementDefinition(getRootFormElement(), 'modalValidationErrorsConfirmButton'), - active: true, - btnClass: getHelper().getDomElementClassName('buttonDefault'), - name: 'confirm', - trigger: function(e, modal) { - modal.hideModal(); - } - }); - - template = getHelper().getTemplate('templateValidationErrors'); - if (template.length > 0) { - html = $(template.html()).clone(); - _validationErrorsModalSetup(html, validationResults); - - Modal.show( - getFormElementDefinition(getRootFormElement(), 'modalValidationErrorsDialogTitle'), - html, - Severity.error, - modalButtons - ); - } - } - - /** - * @public - * - * @param object - * @param object - * @return this - */ - function bootstrap(formEditorApp, configuration) { - _formEditorApp = formEditorApp; - _configuration = $.extend(true, _defaultConfiguration, configuration || {}); - _helperSetup(); - return this; - }; - - /** - * Publish the public methods. - * Implements the "Revealing Module Pattern". - */ - return { - bootstrap: bootstrap, - showCloseConfirmationModal: showCloseConfirmationModal, - showInsertElementsModal: showInsertElementsModal, - showInsertPagesModal: showInsertPagesModal, - showRemoveCollectionElementModal: showRemoveCollectionElementModal, - showRemoveFormElementModal: showRemoveFormElementModal, - showValidationErrorsModal: showValidationErrorsModal - }; - })($, Helper, Modal, Severity, Icons); -} +import $ from"jquery";import*as Helper from"@typo3/form/backend/form-editor/helper.js";import Modal from"@typo3/backend/modal.js";import Severity from"@typo3/backend/severity.js";let configuration=null;const defaultConfiguration={domElementClassNames:{buttonDefault:"btn-default",buttonInfo:"btn-info",buttonWarning:"btn-warning"},domElementDataAttributeNames:{elementType:"element-type",fullElementType:"data-element-type"},domElementDataAttributeValues:{rowItem:"rowItem",rowLink:"rowLink",rowsContainer:"rowsContainer",templateInsertElements:"Modal-InsertElements",templateInsertPages:"Modal-InsertPages",templateValidationErrors:"Modal-ValidationErrors"}};let formEditorApp=null;function getFormEditorApp(){return formEditorApp}function getHelper(e){return getUtility().isUndefinedOrNull(e)?Helper.setConfiguration(configuration):Helper.setConfiguration(e)}function getUtility(){return getFormEditorApp().getUtility()}function assert(e,t,o){return getFormEditorApp().assert(e,t,o)}function getRootFormElement(){return getFormEditorApp().getRootFormElement()}function getPublisherSubscriber(){return getFormEditorApp().getPublisherSubscriber()}function getFormElementDefinition(e,t){return getFormEditorApp().getFormElementDefinition(e,t)}function showRemoveElementModal(e,t){const o=[];assert(getUtility().isNonEmptyString(e),'Invalid parameter "publisherTopicName"',1478889049),assert("array"===$.type(t),'Invalid parameter "formElement"',1478889044),o.push({text:getFormElementDefinition(getRootFormElement(),"modalRemoveElementCancelButton"),active:!0,btnClass:getHelper().getDomElementClassName("buttonDefault"),name:"cancel",trigger:(e,t)=>{t.hideModal()}}),o.push({text:getFormElementDefinition(getRootFormElement(),"modalRemoveElementConfirmButton"),active:!0,btnClass:getHelper().getDomElementClassName("buttonWarning"),name:"confirm",trigger:(o,n)=>{getPublisherSubscriber().publish(e,t),n.hideModal()}}),Modal.show(getFormElementDefinition(getRootFormElement(),"modalRemoveElementDialogTitle"),getFormElementDefinition(getRootFormElement(),"modalRemoveElementDialogMessage"),Severity.warning,o)}function insertElementsModalSetup(e,t,o){if(assert(getUtility().isNonEmptyString(t),'Invalid parameter "publisherTopicName"',1478910954),"object"===$.type(o))for(const t of Object.keys(o)){if("disableElementTypes"===t&&"array"===$.type(o[t]))for(let n=0,l=o[t].length;n0){i=!0;break}i&&(o=getFormEditorApp().getFormElementByIdentifierPath(t[r].formElementIdentifierPath),n=l.clone(),$(getHelper().getDomElementDataIdentifierSelector("rowLink"),n).attr(getHelper().getDomElementDataAttribute("elementIdentifier"),t[r].formElementIdentifierPath).get(0).replaceChildren(_buildTitleByFormElement(o)),$(getHelper().getDomElementDataIdentifierSelector("rowsContainer"),e).append(n))}$("a",e).on("click",(function(){getPublisherSubscriber().publish("view/modal/validationErrors/element/clicked",[$(this).attr(getHelper().getDomElementDataAttribute("elementIdentifier"))]),$("a",e).off(),Modal.currentModal.hideModal()}))}function _buildTitleByFormElement(e){assert("object"===$.type(e),'Invalid parameter "formElement"',1479162557);const t=document.createElement("span");return t.textContent=e.get("label")?e.get("label"):e.get("identifier"),t}export function showRemoveFormElementModal(e){showRemoveElementModal("view/modal/removeFormElement/perform",[e])}export function showRemoveCollectionElementModal(e,t,o){assert(getUtility().isNonEmptyString(e),'Invalid parameter "collectionElementIdentifier"',1478894420),assert(getUtility().isNonEmptyString(t),'Invalid parameter "collectionName"',1478894421),showRemoveElementModal("view/modal/removeCollectionElement/perform",[e,t,o])}export function showCloseConfirmationModal(){const e=[];e.push({text:getFormElementDefinition(getRootFormElement(),"modalCloseCancelButton"),active:!0,btnClass:getHelper().getDomElementClassName("buttonDefault"),name:"cancel",trigger:(e,t)=>{t.hideModal()}}),e.push({text:getFormElementDefinition(getRootFormElement(),"modalCloseConfirmButton"),active:!0,btnClass:getHelper().getDomElementClassName("buttonWarning"),name:"confirm",trigger:(e,t)=>{getPublisherSubscriber().publish("view/modal/close/perform",[]),t.hideModal()}}),Modal.show(getFormElementDefinition(getRootFormElement(),"modalCloseDialogTitle"),getFormElementDefinition(getRootFormElement(),"modalCloseDialogMessage"),Severity.warning,e)}export function showInsertElementsModal(e,t){const o=getHelper().getTemplate("templateInsertElements");if(o.length>0){const n=$(o.html());insertElementsModalSetup(n,e,t),Modal.show(getFormElementDefinition(getRootFormElement(),"modalInsertElementsDialogTitle"),$(n),Severity.info)}}export function showInsertPagesModal(e){const t=getHelper().getTemplate("templateInsertPages");if(t.length>0){const o=$(t.html());insertElementsModalSetup(o,e),Modal.show(getFormElementDefinition(getRootFormElement(),"modalInsertPagesDialogTitle"),$(o),Severity.info)}}export function showValidationErrorsModal(e){const t=[];t.push({text:getFormElementDefinition(getRootFormElement(),"modalValidationErrorsConfirmButton"),active:!0,btnClass:getHelper().getDomElementClassName("buttonDefault"),name:"confirm",trigger:function(e,t){t.hideModal()}});const o=getHelper().getTemplate("templateValidationErrors");if(o.length>0){const n=$(o.html()).clone();_validationErrorsModalSetup(n,e),Modal.show(getFormElementDefinition(getRootFormElement(),"modalValidationErrorsDialogTitle"),n,Severity.error,t)}}export function bootstrap(e,t){return formEditorApp=e,configuration=$.extend(!0,defaultConfiguration,t||{}),Helper.bootstrap(formEditorApp),this} \ No newline at end of file