/* * 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! */ import 'bootstrap'; import $ from 'jquery'; import {AjaxResponse} from 'TYPO3/CMS/Core/Ajax/AjaxResponse'; import {AbstractAction} from './ActionButton/AbstractAction'; import {ModalResponseEvent} from 'TYPO3/CMS/Backend/ModalInterface'; import {SeverityEnum} from './Enum/Severity'; import AjaxRequest = require('TYPO3/CMS/Core/Ajax/AjaxRequest'); import SecurityUtility = require('TYPO3/CMS/Core/SecurityUtility'); import Icons = require('./Icons'); import Severity = require('./Severity'); enum Identifiers { modal = '.t3js-modal', content = '.t3js-modal-content', title = '.t3js-modal-title', close = '.t3js-modal-close', body = '.t3js-modal-body', footer = '.t3js-modal-footer', iframe = '.t3js-modal-iframe', iconPlaceholder = '.t3js-modal-icon-placeholder', } enum Sizes { small = 'small', default = 'default', medium = 'medium', large = 'large', full = 'full', } enum Styles { default = 'default', light = 'light', dark = 'dark', } enum Types { default = 'default', ajax = 'ajax', iframe = 'iframe', } interface Button { text: string; active: boolean; btnClass: string; name: string; trigger: (e: JQueryEventObject) => {}; dataAttributes: { [key: string]: string }; icon: string; action: AbstractAction; } interface Configuration { type: Types; title: string; content: string | JQuery; severity: SeverityEnum; buttons: Array ` ); private defaultConfiguration: Configuration = { type: Types.default, title: 'Information', content: 'No content provided, please check your Modal configuration.', severity: SeverityEnum.notice, buttons: [], style: Styles.default, size: Sizes.default, additionalCssClasses: [], callback: $.noop(), ajaxCallback: $.noop(), ajaxTarget: null, }; private readonly securityUtility: SecurityUtility; private static resolveEventNameTargetElement(evt: Event): HTMLElement | null { const target = evt.target as HTMLElement; const currentTarget = evt.currentTarget as HTMLElement; if (target.dataset && target.dataset.eventName) { return target; } else if (currentTarget.dataset && currentTarget.dataset.eventName) { return currentTarget; } return null; } private static createModalResponseEventFromElement(element: HTMLElement, result: boolean): ModalResponseEvent | null { if (!element || !element.dataset.eventName) { return null; } return new CustomEvent( element.dataset.eventName, { bubbles: true, detail: { result, payload: element.dataset.eventPayload || null } }); } constructor(securityUtility: SecurityUtility) { this.securityUtility = securityUtility; $(document).on('modal-dismiss', this.dismiss); this.initializeMarkupTrigger(document); } /** * Close the current open modal */ public dismiss(): void { if (this.currentModal) { this.currentModal.modal('hide'); } } /** * Shows a confirmation dialog * Events: * - button.clicked * - confirm.button.cancel * - confirm.button.ok * * @param {string} title The title for the confirm modal * @param {string | JQuery} content The content for the conform modal, e.g. the main question * @param {SeverityEnum} severity Default SeverityEnum.warning * @param {Array