2 * This file is part of the TYPO3 CMS project.
4 * It is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, either version 2
6 * of the License, or any later version.
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
11 * The TYPO3 project - inspiring people to share!
14 import * as $ from 'jquery';
15 import Modal = require('TYPO3/CMS/Backend/Modal');
16 import Severity = require('TYPO3/CMS/Backend/Severity');
19 * Module: TYPO3/CMS/Backend/RenameFile
20 * Modal to pick the required conflict strategy for colliding filenames
21 * @exports TYPO3/CMS/Backend/RenameFile
29 public initialize(): void {
30 $('.t3js-submit-file-rename').on('click', this.checkForDuplicate);
33 private checkForDuplicate(e: any): void {
36 const form: any = $('#' + $(e.currentTarget).attr('form'));
37 const fileNameField: any = form.find('input[name="data[rename][0][target]"]');
38 const conflictModeField: any = form.find('input[name="data[rename][0][conflictMode]"]');
39 const ajaxUrl: string = TYPO3.settings.ajaxUrls.file_exists;
44 fileName: fileNameField.val(),
45 fileTarget: form.find('input[name="data[rename][0][destination]"]').val(),
47 success: (response: any): void => {
48 const fileExists: boolean = typeof response.uid !== 'undefined';
49 const originalFileName: string = fileNameField.data('original');
50 const newFileName: string = fileNameField.val();
52 if (fileExists && originalFileName !== newFileName) {
53 const description: string = TYPO3.lang['file_rename.exists.description']
54 .replace('{0}', originalFileName).replace('{1}', newFileName);
56 const modal: JQuery = Modal.confirm(
57 TYPO3.lang['file_rename.exists.title'],
63 btnClass: 'btn-default',
65 text: TYPO3.lang['file_rename.actions.cancel'],
68 btnClass: 'btn-primary',
70 text: TYPO3.lang['file_rename.actions.rename'],
73 btnClass: 'btn-default',
75 text: TYPO3.lang['file_rename.actions.override'],
79 modal.on('button.clicked', (event: any): void => {
80 if (event.target.name !== 'cancel') {
81 conflictModeField.val(event.target.name);
95 export = new RenameFile();