From 26120660c64235179ff28fa89db488964e767e05 Mon Sep 17 00:00:00 2001 From: Andreas Fernandez <a.fernandez@scripting-base.de> Date: Sun, 22 Mar 2020 09:02:34 +0100 Subject: [PATCH] [BUGFIX] Keep order of selection on importing assets If assets get imported via mass selection in the Element Browser, the order of the items is now kept. Since this requires interframe communication, the Inline Control Container now sends a postMessage to the Element Browser. When the import process starts, the first asset of the selection gets imported. After the import, the postMessage is intercepted and the next asset get imported, until the queue is empty. As this could be a rather lenghty process, a progress bar is rendered at the top of the file table. To get a more fitting naming, all previously used action names used in postMessages have been renamed from `typo3:foreignRelation:inserted` to `typo3:foreignRelation:insert`. As a drive-by fix, the server is not spammed with n request anymore due to queueing. Resolves: #86362 Resolves: #59341 Releases: master Change-Id: Ib9e3ee8d943582874a0a73632968f8660b169b42 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63838 Tested-by: Susanne Moog <look@susi.dev> Tested-by: TYPO3com <noreply@typo3.com> Tested-by: Daniel Goerz <daniel.goerz@posteo.de> Reviewed-by: Susanne Moog <look@susi.dev> Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de> --- .../Public/TypeScript/DragUploader.ts | 2 +- .../Container/InlineControlContainer.ts | 20 ++++++-- .../Public/TypeScript/OnlineMedia.ts | 2 +- .../Public/TypeScript/BrowseFiles.ts | 47 ++++++++++++++++--- .../Public/TypeScript/ElementBrowser.ts | 2 +- .../Public/JavaScript/DragUploader.js | 2 +- .../Container/InlineControlContainer.js | 2 +- .../Public/JavaScript/OnlineMedia.js | 2 +- .../Public/JavaScript/BrowseFiles.js | 2 +- .../Public/JavaScript/ElementBrowser.js | 2 +- .../Controller/SetupModuleController.php | 2 +- 11 files changed, 64 insertions(+), 21 deletions(-) diff --git a/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/DragUploader.ts b/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/DragUploader.ts index 5ee1b30e2b37..0d0237b83412 100644 --- a/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/DragUploader.ts +++ b/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/DragUploader.ts @@ -700,7 +700,7 @@ class DragUploader { */ public static addFileToIrre(irre_object: number, file: UploadedFile): void { const message = { - actionName: 'typo3:foreignRelation:inserted', + actionName: 'typo3:foreignRelation:insert', objectGroup: irre_object, table: 'sys_file', uid: file.uid, diff --git a/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/FormEngine/Container/InlineControlContainer.ts b/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/FormEngine/Container/InlineControlContainer.ts index 50a250199563..2da8222f6ec2 100644 --- a/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/FormEngine/Container/InlineControlContainer.ts +++ b/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/FormEngine/Container/InlineControlContainer.ts @@ -310,7 +310,7 @@ class InlineControlContainer { throw 'Denied message sent by ' + e.origin; } - if (e.data.actionName === 'typo3:foreignRelation:inserted') { + if (e.data.actionName === 'typo3:foreignRelation:insert') { if (typeof e.data.objectGroup === 'undefined') { throw 'No object group defined for message'; } @@ -325,7 +325,17 @@ class InlineControlContainer { return; } - this.importRecord([e.data.objectGroup, e.data.uid]); + this.importRecord([e.data.objectGroup, e.data.uid]).then((): void => { + if (e.source) { + const message = { + actionName: 'typo3:foreignRelation:inserted', + objectGroup: e.data.objectId, + table: e.data.table, + uid: e.data.uid, + }; + MessageUtility.send(message, e.source as Window); + } + }); } else { console.warn(`Unhandled action "${e.data.actionName}"`); } @@ -356,11 +366,11 @@ class InlineControlContainer { * @param {Array} params * @param {string} afterUid */ - private async importRecord(params: Array<any>, afterUid?: string): Promise<any> { - this.ajaxDispatcher.send( + private async importRecord(params: Array<any>, afterUid?: string): Promise<void> { + return this.ajaxDispatcher.send( this.ajaxDispatcher.newRequest(this.ajaxDispatcher.getEndpoint('record_inline_create')), params, - ).then(async (response: InlineResponseInterface): Promise<any> => { + ).then(async (response: InlineResponseInterface): Promise<void> => { if (this.isBelowMax()) { this.createRecord( response.compilerInput.uid, diff --git a/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/OnlineMedia.ts b/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/OnlineMedia.ts index 0b391368b356..7d8fa8a55d38 100644 --- a/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/OnlineMedia.ts +++ b/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/OnlineMedia.ts @@ -64,7 +64,7 @@ class OnlineMedia { (data: Response): void => { if (data.file) { const message = { - actionName: 'typo3:foreignRelation:inserted', + actionName: 'typo3:foreignRelation:insert', objectGroup: irreObjectUid, table: 'sys_file', uid: data.file, diff --git a/Build/Sources/TypeScript/recordlist/Resources/Public/TypeScript/BrowseFiles.ts b/Build/Sources/TypeScript/recordlist/Resources/Public/TypeScript/BrowseFiles.ts index 4419c6591941..670948d75ab8 100644 --- a/Build/Sources/TypeScript/recordlist/Resources/Public/TypeScript/BrowseFiles.ts +++ b/Build/Sources/TypeScript/recordlist/Resources/Public/TypeScript/BrowseFiles.ts @@ -12,9 +12,13 @@ */ import * as $ from 'jquery'; +import {MessageUtility} from 'TYPO3/CMS/Backend/Utility/MessageUtility'; import ElementBrowser = require('./ElementBrowser'); +import NProgress = require('nprogress'); // Yes we really need this import, because Tree... is used in inline markup... import Tree = require('TYPO3/CMS/Backend/LegacyTree'); +import RegularEvent = require('TYPO3/CMS/Core/Event/RegularEvent'); +import Icons = TYPO3.Icons; interface LinkElement { fileExt: string; @@ -112,21 +116,50 @@ class Selector { if (items.length) { items.each((position: number, item: any): void => { if (item.checked && item.name) { - selectedItems.push(item.name); + selectedItems.unshift(item.name); } }); - if (selectedItems.length > 0) { - for (let selectedItem of selectedItems) { - BrowseFiles.File.insertElement(selectedItem); - } - } - ElementBrowser.focusOpenerAndClose(); + Icons.getIcon('spinner-circle', Icons.sizes.small, null, null, Icons.markupIdentifiers.inline).then((icon: string): void => { + e.currentTarget.classList.add('disabled'); + e.currentTarget.innerHTML = icon; + }); + this.handleSelection(selectedItems); } } public getItems(): JQuery { return $('#typo3-filelist').find('.typo3-bulk-item'); } + + private handleSelection(items: string[]): void { + NProgress.configure({parent: '#typo3-filelist', showSpinner: false}); + NProgress.start(); + const stepping = 1 / items.length; + this.handleNext(items); + + new RegularEvent('message', (e: MessageEvent): void => { + if (!MessageUtility.verifyOrigin(e.origin)) { + throw 'Denied message sent by ' + e.origin; + } + + if (e.data.actionName === 'typo3:foreignRelation:inserted') { + if (items.length > 0) { + NProgress.inc(stepping); + this.handleNext(items); + } else { + NProgress.done(); + ElementBrowser.focusOpenerAndClose(); + } + } + }).bindTo(window); + } + + private handleNext(items: string[]): void { + if (items.length > 0) { + const item = items.pop(); + BrowseFiles.File.insertElement(item); + } + } } export = new BrowseFiles(); diff --git a/Build/Sources/TypeScript/recordlist/Resources/Public/TypeScript/ElementBrowser.ts b/Build/Sources/TypeScript/recordlist/Resources/Public/TypeScript/ElementBrowser.ts index f4d81dd1a8a0..992b0e650188 100644 --- a/Build/Sources/TypeScript/recordlist/Resources/Public/TypeScript/ElementBrowser.ts +++ b/Build/Sources/TypeScript/recordlist/Resources/Public/TypeScript/ElementBrowser.ts @@ -141,7 +141,7 @@ class ElementBrowser { if (this.irre.objectId) { if (this.getParent()) { const message = { - actionName: 'typo3:foreignRelation:inserted', + actionName: 'typo3:foreignRelation:insert', objectGroup: this.irre.objectId, table: table, uid: uid, diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/DragUploader.js b/typo3/sysext/backend/Resources/Public/JavaScript/DragUploader.js index 4e02ec49bcc7..82601eb8acbd 100644 --- a/typo3/sysext/backend/Resources/Public/JavaScript/DragUploader.js +++ b/typo3/sysext/backend/Resources/Public/JavaScript/DragUploader.js @@ -10,4 +10,4 @@ * * The TYPO3 project - inspiring people to share! */ -define(["require","exports","jquery","./Enum/Severity","./Utility/MessageUtility","moment","nprogress","TYPO3/CMS/Core/Ajax/AjaxRequest","./Modal","./Notification"],(function(e,t,i,s,a,o,r,n,l,d){"use strict";var p;Object.defineProperty(t,"__esModule",{value:!0}),function(e){e.OVERRIDE="replace",e.RENAME="rename",e.SKIP="cancel",e.USE_EXISTING="useExisting"}(p||(p={}));class h{constructor(e){this.askForOverride=[],this.percentagePerFile=1,this.hideDropzone=e=>{e.stopPropagation(),e.preventDefault(),this.$dropzone.hide()},this.dragFileIntoDocument=e=>(e.stopPropagation(),e.preventDefault(),i(e.currentTarget).addClass("drop-in-progress"),this.showDropzone(),!1),this.dragAborted=e=>(e.stopPropagation(),e.preventDefault(),i(e.currentTarget).removeClass("drop-in-progress"),!1),this.ignoreDrop=e=>(e.stopPropagation(),e.preventDefault(),this.dragAborted(e),!1),this.handleDrop=e=>{this.ignoreDrop(e),this.processFiles(e.originalEvent.dataTransfer.files),this.$dropzone.removeClass("drop-status-ok")},this.fileInDropzone=()=>{this.$dropzone.addClass("drop-status-ok")},this.fileOutOfDropzone=()=>{this.$dropzone.removeClass("drop-status-ok")},this.$body=i("body"),this.$element=i(e);const t=void 0!==this.$element.data("dropzoneTrigger");this.$trigger=i(this.$element.data("dropzoneTrigger")),this.defaultAction=this.$element.data("defaultAction")||p.SKIP,this.$dropzone=i("<div />").addClass("dropzone").hide(),this.irreObjectUid=this.$element.data("fileIrreObject");const s=this.$element.data("dropzoneTarget");this.irreObjectUid&&0!==this.$element.nextAll(s).length?(this.dropZoneInsertBefore=!0,this.$dropzone.insertBefore(s)):(this.dropZoneInsertBefore=!1,this.$dropzone.insertAfter(s)),this.$dropzoneMask=i("<div />").addClass("dropzone-mask").appendTo(this.$dropzone),this.fileInput=document.createElement("input"),this.fileInput.setAttribute("type","file"),this.fileInput.setAttribute("multiple","multiple"),this.fileInput.setAttribute("name","files[]"),this.fileInput.classList.add("upload-file-picker"),this.$body.append(this.fileInput),this.$fileList=i(this.$element.data("progress-container")),this.fileListColumnCount=i("thead tr:first th",this.$fileList).length,this.filesExtensionsAllowed=this.$element.data("file-allowed"),this.fileDenyPattern=this.$element.data("file-deny-pattern")?new RegExp(this.$element.data("file-deny-pattern"),"i"):null,this.maxFileSize=parseInt(this.$element.data("max-file-size"),10),this.target=this.$element.data("target-folder"),this.browserCapabilities={fileReader:"undefined"!=typeof FileReader,DnD:"draggable"in document.createElement("span"),Progress:"upload"in new XMLHttpRequest},this.browserCapabilities.DnD?(this.$body.on("dragover",this.dragFileIntoDocument),this.$body.on("dragend",this.dragAborted),this.$body.on("drop",this.ignoreDrop),this.$dropzone.on("dragenter",this.fileInDropzone),this.$dropzoneMask.on("dragenter",this.fileInDropzone),this.$dropzoneMask.on("dragleave",this.fileOutOfDropzone),this.$dropzoneMask.on("drop",e=>this.handleDrop(e)),this.$dropzone.prepend('<div class="dropzone-hint"><div class="dropzone-hint-media"><div class="dropzone-hint-icon"></div></div><div class="dropzone-hint-body"><h3 class="dropzone-hint-title">'+TYPO3.lang["file_upload.dropzonehint.title"]+'</h3><p class="dropzone-hint-message">'+TYPO3.lang["file_upload.dropzonehint.message"]+"</p></div></div>").click(()=>{this.fileInput.click()}),i("<span />").addClass("dropzone-close").click(this.hideDropzone).appendTo(this.$dropzone),0===this.$fileList.length&&(this.$fileList=i("<table />").attr("id","typo3-filelist").addClass("table table-striped table-hover upload-queue").html("<tbody></tbody>").hide(),this.dropZoneInsertBefore?this.$fileList.insertAfter(this.$dropzone):this.$fileList.insertBefore(this.$dropzone),this.fileListColumnCount=7),this.fileInput.addEventListener("change",()=>{this.processFiles(Array.apply(null,this.fileInput.files))}),this.bindUploadButton(!0===t?this.$trigger:this.$element)):console.warn("Browser has no Drag and drop capabilities; cannot initialize DragUploader")}showDropzone(){this.$dropzone.show()}processFiles(e){this.queueLength=e.length,this.$fileList.is(":visible")||this.$fileList.show(),r.start(),this.percentagePerFile=1/e.length;const t=[];Array.from(e).forEach(e=>{const i=new n(TYPO3.settings.ajaxUrls.file_exists).withQueryArguments({fileName:e.name,fileTarget:this.target}).get({cache:"no-cache"}).then(async t=>{const i=await t.resolve();void 0!==i.uid?(this.askForOverride.push({original:i,uploaded:e,action:this.irreObjectUid?p.USE_EXISTING:p.SKIP}),r.inc(this.percentagePerFile)):new g(this,e,p.SKIP)});t.push(i)}),Promise.all(t).then(()=>{this.drawOverrideModal(),r.done()}),this.fileInput.value=""}bindUploadButton(e){e.click(e=>{e.preventDefault(),this.fileInput.click(),this.showDropzone()})}decrementQueueLength(){this.queueLength>0&&(this.queueLength--,0===this.queueLength&&new n(TYPO3.settings.ajaxUrls.flashmessages_render).get({cache:"no-cache"}).then(async e=>{const t=await e.resolve();for(let e of t)d.showMessage(e.title,e.message,e.severity)}))}drawOverrideModal(){const e=Object.keys(this.askForOverride).length;if(0===e)return;const t=i("<div/>").append(i("<p/>").text(TYPO3.lang["file_upload.existingfiles.description"]),i("<table/>",{class:"table"}).append(i("<thead/>").append(i("<tr />").append(i("<th/>"),i("<th/>").text(TYPO3.lang["file_upload.header.originalFile"]),i("<th/>").text(TYPO3.lang["file_upload.header.uploadedFile"]),i("<th/>").text(TYPO3.lang["file_upload.header.action"])))));for(let s=0;s<e;++s){const e=i("<tr />").append(i("<td />").append(""!==this.askForOverride[s].original.thumbUrl?i("<img />",{src:this.askForOverride[s].original.thumbUrl,height:40}):i(this.askForOverride[s].original.icon)),i("<td />").html(this.askForOverride[s].original.name+" ("+c.fileSizeAsString(this.askForOverride[s].original.size)+")<br>"+o.unix(this.askForOverride[s].original.mtime).format("YYYY-MM-DD HH:mm")),i("<td />").html(this.askForOverride[s].uploaded.name+" ("+c.fileSizeAsString(this.askForOverride[s].uploaded.size)+")<br>"+o(this.askForOverride[s].uploaded.lastModified?this.askForOverride[s].uploaded.lastModified:this.askForOverride[s].uploaded.lastModifiedDate).format("YYYY-MM-DD HH:mm")),i("<td />").append(i("<select />",{class:"form-control t3js-actions","data-override":s}).append(this.irreObjectUid?i("<option/>").val(p.USE_EXISTING).text(TYPO3.lang["file_upload.actions.use_existing"]):"",i("<option />",{selected:this.defaultAction===p.SKIP}).val(p.SKIP).text(TYPO3.lang["file_upload.actions.skip"]),i("<option />",{selected:this.defaultAction===p.RENAME}).val(p.RENAME).text(TYPO3.lang["file_upload.actions.rename"]),i("<option />",{selected:this.defaultAction===p.OVERRIDE}).val(p.OVERRIDE).text(TYPO3.lang["file_upload.actions.override"]))));t.find("table").append("<tbody />").append(e)}const a=l.confirm(TYPO3.lang["file_upload.existingfiles.title"],t,s.SeverityEnum.warning,[{text:i(this).data("button-close-text")||TYPO3.lang["file_upload.button.cancel"]||"Cancel",active:!0,btnClass:"btn-default",name:"cancel"},{text:i(this).data("button-ok-text")||TYPO3.lang["file_upload.button.continue"]||"Continue with selected actions",btnClass:"btn-warning",name:"continue"}],["modal-inner-scroll"]);a.find(".modal-dialog").addClass("modal-lg"),a.find(".modal-footer").prepend(i("<span/>").addClass("form-inline").append(i("<label/>").text(TYPO3.lang["file_upload.actions.all.label"]),i("<select/>",{class:"form-control t3js-actions-all"}).append(i("<option/>").val("").text(TYPO3.lang["file_upload.actions.all.empty"]),this.irreObjectUid?i("<option/>").val(p.USE_EXISTING).text(TYPO3.lang["file_upload.actions.all.use_existing"]):"",i("<option/>",{selected:this.defaultAction===p.SKIP}).val(p.SKIP).text(TYPO3.lang["file_upload.actions.all.skip"]),i("<option/>",{selected:this.defaultAction===p.RENAME}).val(p.RENAME).text(TYPO3.lang["file_upload.actions.all.rename"]),i("<option/>",{selected:this.defaultAction===p.OVERRIDE}).val(p.OVERRIDE).text(TYPO3.lang["file_upload.actions.all.override"]))));const r=this;a.on("change",".t3js-actions-all",(function(){const e=i(this).val();""!==e?a.find(".t3js-actions").each((t,s)=>{const a=i(s),o=parseInt(a.data("override"),10);a.val(e).prop("disabled","disabled"),r.askForOverride[o].action=a.val()}):a.find(".t3js-actions").removeProp("disabled")})).on("change",".t3js-actions",(function(){const e=i(this),t=parseInt(e.data("override"),10);r.askForOverride[t].action=e.val()})).on("button.clicked",(function(e){"cancel"===e.target.name?(r.askForOverride=[],l.dismiss()):"continue"===e.target.name&&(i.each(r.askForOverride,(e,t)=>{t.action===p.USE_EXISTING?c.addFileToIrre(r.irreObjectUid,t.original):t.action!==p.SKIP&&new g(r,t.uploaded,t.action)}),r.askForOverride=[],l.dismiss())})).on("hidden.bs.modal",()=>{this.askForOverride=[]})}}class g{constructor(e,t,s){if(this.dragUploader=e,this.file=t,this.override=s,this.$row=i("<tr />").addClass("upload-queue-item uploading"),this.$iconCol=i("<td />").addClass("col-icon").appendTo(this.$row),this.$fileName=i("<td />").text(t.name).appendTo(this.$row),this.$progress=i("<td />").attr("colspan",this.dragUploader.fileListColumnCount-2).appendTo(this.$row),this.$progressContainer=i("<div />").addClass("upload-queue-progress").appendTo(this.$progress),this.$progressBar=i("<div />").addClass("upload-queue-progress-bar").appendTo(this.$progressContainer),this.$progressPercentage=i("<span />").addClass("upload-queue-progress-percentage").appendTo(this.$progressContainer),this.$progressMessage=i("<span />").addClass("upload-queue-progress-message").appendTo(this.$progressContainer),0===i("tbody tr.upload-queue-item",this.dragUploader.$fileList).length?(this.$row.prependTo(i("tbody",this.dragUploader.$fileList)),this.$row.addClass("last")):this.$row.insertBefore(i("tbody tr.upload-queue-item:first",this.dragUploader.$fileList)),this.$iconCol.html('<span class="t3-icon t3-icon-mimetypes t3-icon-other-other"> </span>'),this.dragUploader.maxFileSize>0&&this.file.size>this.dragUploader.maxFileSize)this.updateMessage(TYPO3.lang["file_upload.maxFileSizeExceeded"].replace(/\{0\}/g,this.file.name).replace(/\{1\}/g,c.fileSizeAsString(this.dragUploader.maxFileSize))),this.$row.addClass("error");else if(this.dragUploader.fileDenyPattern&&this.file.name.match(this.dragUploader.fileDenyPattern))this.updateMessage(TYPO3.lang["file_upload.fileNotAllowed"].replace(/\{0\}/g,this.file.name)),this.$row.addClass("error");else if(this.checkAllowedExtensions()){this.updateMessage("- "+c.fileSizeAsString(this.file.size));const e=new FormData;e.append("data[upload][1][target]",this.dragUploader.target),e.append("data[upload][1][data]","1"),e.append("overwriteExistingFiles",this.override),e.append("redirect",""),e.append("upload_1",this.file);const t=new XMLHttpRequest;t.onreadystatechange=()=>{t.readyState===XMLHttpRequest.DONE&&(200===t.status?this.uploadSuccess(JSON.parse(t.responseText)):this.uploadError(t))},t.upload.addEventListener("progress",e=>this.updateProgress(e)),t.open("POST",TYPO3.settings.ajaxUrls.file_process),t.send(e)}else this.updateMessage(TYPO3.lang["file_upload.fileExtensionExpected"].replace(/\{0\}/g,this.dragUploader.filesExtensionsAllowed)),this.$row.addClass("error")}updateMessage(e){this.$progressMessage.text(e)}removeProgress(){this.$progress&&this.$progress.remove()}uploadStart(){this.$progressPercentage.text("(0%)"),this.$progressBar.width("1%"),this.dragUploader.$trigger.trigger("uploadStart",[this])}uploadError(e){this.updateMessage(TYPO3.lang["file_upload.uploadFailed"].replace(/\{0\}/g,this.file.name));const t=i(e.responseText);t.is("t3err")?this.$progressPercentage.text(t.text()):this.$progressPercentage.text("("+e.statusText+")"),this.$row.addClass("error"),this.dragUploader.decrementQueueLength(),this.dragUploader.$trigger.trigger("uploadError",[this,e])}updateProgress(e){const t=Math.round(e.loaded/e.total*100)+"%";this.$progressBar.outerWidth(t),this.$progressPercentage.text(t),this.dragUploader.$trigger.trigger("updateProgress",[this,t,e])}uploadSuccess(e){e.upload&&(this.dragUploader.decrementQueueLength(),this.$row.removeClass("uploading"),this.$fileName.text(e.upload[0].name),this.$progressPercentage.text(""),this.$progressMessage.text("100%"),this.$progressBar.outerWidth("100%"),e.upload[0].icon&&this.$iconCol.html('<a href="#" class="t3js-contextmenutrigger" data-uid="'+e.upload[0].id+'" data-table="sys_file">'+e.upload[0].icon+" </span></a>"),this.dragUploader.irreObjectUid?(c.addFileToIrre(this.dragUploader.irreObjectUid,e.upload[0]),setTimeout(()=>{this.$row.remove(),0===i("tr",this.dragUploader.$fileList).length&&(this.dragUploader.$fileList.hide(),this.dragUploader.$trigger.trigger("uploadSuccess",[this,e]))},3e3)):setTimeout(()=>{this.showFileInfo(e.upload[0]),this.dragUploader.$trigger.trigger("uploadSuccess",[this,e])},3e3))}showFileInfo(e){this.removeProgress();for(let e=7;e<this.dragUploader.fileListColumnCount;e++)i("<td />").text("").appendTo(this.$row);i("<td />").text(e.extension.toUpperCase()).appendTo(this.$row),i("<td />").text(e.date).appendTo(this.$row),i("<td />").text(c.fileSizeAsString(e.size)).appendTo(this.$row);let t="";e.permissions.read&&(t+='<strong class="text-danger">'+TYPO3.lang["permissions.read"]+"</strong>"),e.permissions.write&&(t+='<strong class="text-danger">'+TYPO3.lang["permissions.write"]+"</strong>"),i("<td />").html(t).appendTo(this.$row),i("<td />").text("-").appendTo(this.$row)}checkAllowedExtensions(){if(!this.dragUploader.filesExtensionsAllowed)return!0;const e=this.file.name.split(".").pop(),t=this.dragUploader.filesExtensionsAllowed.split(",");return-1!==i.inArray(e.toLowerCase(),t)}}class c{static fileSizeAsString(e){const t=e/1024;let i="";return i=t>1024?(t/1024).toFixed(1)+" MB":t.toFixed(1)+" KB",i}static addFileToIrre(e,t){const i={actionName:"typo3:foreignRelation:inserted",objectGroup:e,table:"sys_file",uid:t.uid};a.MessageUtility.send(i)}static init(){const e=this.options;i.fn.extend({dragUploader:function(e){return this.each((t,s)=>{const a=i(s);let o=a.data("DragUploaderPlugin");o||a.data("DragUploaderPlugin",o=new h(s)),"string"==typeof e&&o[e]()})}}),i(()=>{i(".t3js-drag-uploader").dragUploader(e)})}}t.initialize=function(){c.init(),void 0!==TYPO3.settings&&void 0!==TYPO3.settings.RequireJS&&void 0!==TYPO3.settings.RequireJS.PostInitializationModules&&void 0!==TYPO3.settings.RequireJS.PostInitializationModules["TYPO3/CMS/Backend/DragUploader"]&&i.each(TYPO3.settings.RequireJS.PostInitializationModules["TYPO3/CMS/Backend/DragUploader"],(t,i)=>{e([i])})},t.initialize()})); \ No newline at end of file +define(["require","exports","jquery","./Enum/Severity","./Utility/MessageUtility","moment","nprogress","TYPO3/CMS/Core/Ajax/AjaxRequest","./Modal","./Notification"],(function(e,t,i,s,a,o,r,n,l,d){"use strict";var p;Object.defineProperty(t,"__esModule",{value:!0}),function(e){e.OVERRIDE="replace",e.RENAME="rename",e.SKIP="cancel",e.USE_EXISTING="useExisting"}(p||(p={}));class h{constructor(e){this.askForOverride=[],this.percentagePerFile=1,this.hideDropzone=e=>{e.stopPropagation(),e.preventDefault(),this.$dropzone.hide()},this.dragFileIntoDocument=e=>(e.stopPropagation(),e.preventDefault(),i(e.currentTarget).addClass("drop-in-progress"),this.showDropzone(),!1),this.dragAborted=e=>(e.stopPropagation(),e.preventDefault(),i(e.currentTarget).removeClass("drop-in-progress"),!1),this.ignoreDrop=e=>(e.stopPropagation(),e.preventDefault(),this.dragAborted(e),!1),this.handleDrop=e=>{this.ignoreDrop(e),this.processFiles(e.originalEvent.dataTransfer.files),this.$dropzone.removeClass("drop-status-ok")},this.fileInDropzone=()=>{this.$dropzone.addClass("drop-status-ok")},this.fileOutOfDropzone=()=>{this.$dropzone.removeClass("drop-status-ok")},this.$body=i("body"),this.$element=i(e);const t=void 0!==this.$element.data("dropzoneTrigger");this.$trigger=i(this.$element.data("dropzoneTrigger")),this.defaultAction=this.$element.data("defaultAction")||p.SKIP,this.$dropzone=i("<div />").addClass("dropzone").hide(),this.irreObjectUid=this.$element.data("fileIrreObject");const s=this.$element.data("dropzoneTarget");this.irreObjectUid&&0!==this.$element.nextAll(s).length?(this.dropZoneInsertBefore=!0,this.$dropzone.insertBefore(s)):(this.dropZoneInsertBefore=!1,this.$dropzone.insertAfter(s)),this.$dropzoneMask=i("<div />").addClass("dropzone-mask").appendTo(this.$dropzone),this.fileInput=document.createElement("input"),this.fileInput.setAttribute("type","file"),this.fileInput.setAttribute("multiple","multiple"),this.fileInput.setAttribute("name","files[]"),this.fileInput.classList.add("upload-file-picker"),this.$body.append(this.fileInput),this.$fileList=i(this.$element.data("progress-container")),this.fileListColumnCount=i("thead tr:first th",this.$fileList).length,this.filesExtensionsAllowed=this.$element.data("file-allowed"),this.fileDenyPattern=this.$element.data("file-deny-pattern")?new RegExp(this.$element.data("file-deny-pattern"),"i"):null,this.maxFileSize=parseInt(this.$element.data("max-file-size"),10),this.target=this.$element.data("target-folder"),this.browserCapabilities={fileReader:"undefined"!=typeof FileReader,DnD:"draggable"in document.createElement("span"),Progress:"upload"in new XMLHttpRequest},this.browserCapabilities.DnD?(this.$body.on("dragover",this.dragFileIntoDocument),this.$body.on("dragend",this.dragAborted),this.$body.on("drop",this.ignoreDrop),this.$dropzone.on("dragenter",this.fileInDropzone),this.$dropzoneMask.on("dragenter",this.fileInDropzone),this.$dropzoneMask.on("dragleave",this.fileOutOfDropzone),this.$dropzoneMask.on("drop",e=>this.handleDrop(e)),this.$dropzone.prepend('<div class="dropzone-hint"><div class="dropzone-hint-media"><div class="dropzone-hint-icon"></div></div><div class="dropzone-hint-body"><h3 class="dropzone-hint-title">'+TYPO3.lang["file_upload.dropzonehint.title"]+'</h3><p class="dropzone-hint-message">'+TYPO3.lang["file_upload.dropzonehint.message"]+"</p></div></div>").click(()=>{this.fileInput.click()}),i("<span />").addClass("dropzone-close").click(this.hideDropzone).appendTo(this.$dropzone),0===this.$fileList.length&&(this.$fileList=i("<table />").attr("id","typo3-filelist").addClass("table table-striped table-hover upload-queue").html("<tbody></tbody>").hide(),this.dropZoneInsertBefore?this.$fileList.insertAfter(this.$dropzone):this.$fileList.insertBefore(this.$dropzone),this.fileListColumnCount=7),this.fileInput.addEventListener("change",()=>{this.processFiles(Array.apply(null,this.fileInput.files))}),this.bindUploadButton(!0===t?this.$trigger:this.$element)):console.warn("Browser has no Drag and drop capabilities; cannot initialize DragUploader")}showDropzone(){this.$dropzone.show()}processFiles(e){this.queueLength=e.length,this.$fileList.is(":visible")||this.$fileList.show(),r.start(),this.percentagePerFile=1/e.length;const t=[];Array.from(e).forEach(e=>{const i=new n(TYPO3.settings.ajaxUrls.file_exists).withQueryArguments({fileName:e.name,fileTarget:this.target}).get({cache:"no-cache"}).then(async t=>{const i=await t.resolve();void 0!==i.uid?(this.askForOverride.push({original:i,uploaded:e,action:this.irreObjectUid?p.USE_EXISTING:p.SKIP}),r.inc(this.percentagePerFile)):new g(this,e,p.SKIP)});t.push(i)}),Promise.all(t).then(()=>{this.drawOverrideModal(),r.done()}),this.fileInput.value=""}bindUploadButton(e){e.click(e=>{e.preventDefault(),this.fileInput.click(),this.showDropzone()})}decrementQueueLength(){this.queueLength>0&&(this.queueLength--,0===this.queueLength&&new n(TYPO3.settings.ajaxUrls.flashmessages_render).get({cache:"no-cache"}).then(async e=>{const t=await e.resolve();for(let e of t)d.showMessage(e.title,e.message,e.severity)}))}drawOverrideModal(){const e=Object.keys(this.askForOverride).length;if(0===e)return;const t=i("<div/>").append(i("<p/>").text(TYPO3.lang["file_upload.existingfiles.description"]),i("<table/>",{class:"table"}).append(i("<thead/>").append(i("<tr />").append(i("<th/>"),i("<th/>").text(TYPO3.lang["file_upload.header.originalFile"]),i("<th/>").text(TYPO3.lang["file_upload.header.uploadedFile"]),i("<th/>").text(TYPO3.lang["file_upload.header.action"])))));for(let s=0;s<e;++s){const e=i("<tr />").append(i("<td />").append(""!==this.askForOverride[s].original.thumbUrl?i("<img />",{src:this.askForOverride[s].original.thumbUrl,height:40}):i(this.askForOverride[s].original.icon)),i("<td />").html(this.askForOverride[s].original.name+" ("+c.fileSizeAsString(this.askForOverride[s].original.size)+")<br>"+o.unix(this.askForOverride[s].original.mtime).format("YYYY-MM-DD HH:mm")),i("<td />").html(this.askForOverride[s].uploaded.name+" ("+c.fileSizeAsString(this.askForOverride[s].uploaded.size)+")<br>"+o(this.askForOverride[s].uploaded.lastModified?this.askForOverride[s].uploaded.lastModified:this.askForOverride[s].uploaded.lastModifiedDate).format("YYYY-MM-DD HH:mm")),i("<td />").append(i("<select />",{class:"form-control t3js-actions","data-override":s}).append(this.irreObjectUid?i("<option/>").val(p.USE_EXISTING).text(TYPO3.lang["file_upload.actions.use_existing"]):"",i("<option />",{selected:this.defaultAction===p.SKIP}).val(p.SKIP).text(TYPO3.lang["file_upload.actions.skip"]),i("<option />",{selected:this.defaultAction===p.RENAME}).val(p.RENAME).text(TYPO3.lang["file_upload.actions.rename"]),i("<option />",{selected:this.defaultAction===p.OVERRIDE}).val(p.OVERRIDE).text(TYPO3.lang["file_upload.actions.override"]))));t.find("table").append("<tbody />").append(e)}const a=l.confirm(TYPO3.lang["file_upload.existingfiles.title"],t,s.SeverityEnum.warning,[{text:i(this).data("button-close-text")||TYPO3.lang["file_upload.button.cancel"]||"Cancel",active:!0,btnClass:"btn-default",name:"cancel"},{text:i(this).data("button-ok-text")||TYPO3.lang["file_upload.button.continue"]||"Continue with selected actions",btnClass:"btn-warning",name:"continue"}],["modal-inner-scroll"]);a.find(".modal-dialog").addClass("modal-lg"),a.find(".modal-footer").prepend(i("<span/>").addClass("form-inline").append(i("<label/>").text(TYPO3.lang["file_upload.actions.all.label"]),i("<select/>",{class:"form-control t3js-actions-all"}).append(i("<option/>").val("").text(TYPO3.lang["file_upload.actions.all.empty"]),this.irreObjectUid?i("<option/>").val(p.USE_EXISTING).text(TYPO3.lang["file_upload.actions.all.use_existing"]):"",i("<option/>",{selected:this.defaultAction===p.SKIP}).val(p.SKIP).text(TYPO3.lang["file_upload.actions.all.skip"]),i("<option/>",{selected:this.defaultAction===p.RENAME}).val(p.RENAME).text(TYPO3.lang["file_upload.actions.all.rename"]),i("<option/>",{selected:this.defaultAction===p.OVERRIDE}).val(p.OVERRIDE).text(TYPO3.lang["file_upload.actions.all.override"]))));const r=this;a.on("change",".t3js-actions-all",(function(){const e=i(this).val();""!==e?a.find(".t3js-actions").each((t,s)=>{const a=i(s),o=parseInt(a.data("override"),10);a.val(e).prop("disabled","disabled"),r.askForOverride[o].action=a.val()}):a.find(".t3js-actions").removeProp("disabled")})).on("change",".t3js-actions",(function(){const e=i(this),t=parseInt(e.data("override"),10);r.askForOverride[t].action=e.val()})).on("button.clicked",(function(e){"cancel"===e.target.name?(r.askForOverride=[],l.dismiss()):"continue"===e.target.name&&(i.each(r.askForOverride,(e,t)=>{t.action===p.USE_EXISTING?c.addFileToIrre(r.irreObjectUid,t.original):t.action!==p.SKIP&&new g(r,t.uploaded,t.action)}),r.askForOverride=[],l.dismiss())})).on("hidden.bs.modal",()=>{this.askForOverride=[]})}}class g{constructor(e,t,s){if(this.dragUploader=e,this.file=t,this.override=s,this.$row=i("<tr />").addClass("upload-queue-item uploading"),this.$iconCol=i("<td />").addClass("col-icon").appendTo(this.$row),this.$fileName=i("<td />").text(t.name).appendTo(this.$row),this.$progress=i("<td />").attr("colspan",this.dragUploader.fileListColumnCount-2).appendTo(this.$row),this.$progressContainer=i("<div />").addClass("upload-queue-progress").appendTo(this.$progress),this.$progressBar=i("<div />").addClass("upload-queue-progress-bar").appendTo(this.$progressContainer),this.$progressPercentage=i("<span />").addClass("upload-queue-progress-percentage").appendTo(this.$progressContainer),this.$progressMessage=i("<span />").addClass("upload-queue-progress-message").appendTo(this.$progressContainer),0===i("tbody tr.upload-queue-item",this.dragUploader.$fileList).length?(this.$row.prependTo(i("tbody",this.dragUploader.$fileList)),this.$row.addClass("last")):this.$row.insertBefore(i("tbody tr.upload-queue-item:first",this.dragUploader.$fileList)),this.$iconCol.html('<span class="t3-icon t3-icon-mimetypes t3-icon-other-other"> </span>'),this.dragUploader.maxFileSize>0&&this.file.size>this.dragUploader.maxFileSize)this.updateMessage(TYPO3.lang["file_upload.maxFileSizeExceeded"].replace(/\{0\}/g,this.file.name).replace(/\{1\}/g,c.fileSizeAsString(this.dragUploader.maxFileSize))),this.$row.addClass("error");else if(this.dragUploader.fileDenyPattern&&this.file.name.match(this.dragUploader.fileDenyPattern))this.updateMessage(TYPO3.lang["file_upload.fileNotAllowed"].replace(/\{0\}/g,this.file.name)),this.$row.addClass("error");else if(this.checkAllowedExtensions()){this.updateMessage("- "+c.fileSizeAsString(this.file.size));const e=new FormData;e.append("data[upload][1][target]",this.dragUploader.target),e.append("data[upload][1][data]","1"),e.append("overwriteExistingFiles",this.override),e.append("redirect",""),e.append("upload_1",this.file);const t=new XMLHttpRequest;t.onreadystatechange=()=>{t.readyState===XMLHttpRequest.DONE&&(200===t.status?this.uploadSuccess(JSON.parse(t.responseText)):this.uploadError(t))},t.upload.addEventListener("progress",e=>this.updateProgress(e)),t.open("POST",TYPO3.settings.ajaxUrls.file_process),t.send(e)}else this.updateMessage(TYPO3.lang["file_upload.fileExtensionExpected"].replace(/\{0\}/g,this.dragUploader.filesExtensionsAllowed)),this.$row.addClass("error")}updateMessage(e){this.$progressMessage.text(e)}removeProgress(){this.$progress&&this.$progress.remove()}uploadStart(){this.$progressPercentage.text("(0%)"),this.$progressBar.width("1%"),this.dragUploader.$trigger.trigger("uploadStart",[this])}uploadError(e){this.updateMessage(TYPO3.lang["file_upload.uploadFailed"].replace(/\{0\}/g,this.file.name));const t=i(e.responseText);t.is("t3err")?this.$progressPercentage.text(t.text()):this.$progressPercentage.text("("+e.statusText+")"),this.$row.addClass("error"),this.dragUploader.decrementQueueLength(),this.dragUploader.$trigger.trigger("uploadError",[this,e])}updateProgress(e){const t=Math.round(e.loaded/e.total*100)+"%";this.$progressBar.outerWidth(t),this.$progressPercentage.text(t),this.dragUploader.$trigger.trigger("updateProgress",[this,t,e])}uploadSuccess(e){e.upload&&(this.dragUploader.decrementQueueLength(),this.$row.removeClass("uploading"),this.$fileName.text(e.upload[0].name),this.$progressPercentage.text(""),this.$progressMessage.text("100%"),this.$progressBar.outerWidth("100%"),e.upload[0].icon&&this.$iconCol.html('<a href="#" class="t3js-contextmenutrigger" data-uid="'+e.upload[0].id+'" data-table="sys_file">'+e.upload[0].icon+" </span></a>"),this.dragUploader.irreObjectUid?(c.addFileToIrre(this.dragUploader.irreObjectUid,e.upload[0]),setTimeout(()=>{this.$row.remove(),0===i("tr",this.dragUploader.$fileList).length&&(this.dragUploader.$fileList.hide(),this.dragUploader.$trigger.trigger("uploadSuccess",[this,e]))},3e3)):setTimeout(()=>{this.showFileInfo(e.upload[0]),this.dragUploader.$trigger.trigger("uploadSuccess",[this,e])},3e3))}showFileInfo(e){this.removeProgress();for(let e=7;e<this.dragUploader.fileListColumnCount;e++)i("<td />").text("").appendTo(this.$row);i("<td />").text(e.extension.toUpperCase()).appendTo(this.$row),i("<td />").text(e.date).appendTo(this.$row),i("<td />").text(c.fileSizeAsString(e.size)).appendTo(this.$row);let t="";e.permissions.read&&(t+='<strong class="text-danger">'+TYPO3.lang["permissions.read"]+"</strong>"),e.permissions.write&&(t+='<strong class="text-danger">'+TYPO3.lang["permissions.write"]+"</strong>"),i("<td />").html(t).appendTo(this.$row),i("<td />").text("-").appendTo(this.$row)}checkAllowedExtensions(){if(!this.dragUploader.filesExtensionsAllowed)return!0;const e=this.file.name.split(".").pop(),t=this.dragUploader.filesExtensionsAllowed.split(",");return-1!==i.inArray(e.toLowerCase(),t)}}class c{static fileSizeAsString(e){const t=e/1024;let i="";return i=t>1024?(t/1024).toFixed(1)+" MB":t.toFixed(1)+" KB",i}static addFileToIrre(e,t){const i={actionName:"typo3:foreignRelation:insert",objectGroup:e,table:"sys_file",uid:t.uid};a.MessageUtility.send(i)}static init(){const e=this.options;i.fn.extend({dragUploader:function(e){return this.each((t,s)=>{const a=i(s);let o=a.data("DragUploaderPlugin");o||a.data("DragUploaderPlugin",o=new h(s)),"string"==typeof e&&o[e]()})}}),i(()=>{i(".t3js-drag-uploader").dragUploader(e)})}}t.initialize=function(){c.init(),void 0!==TYPO3.settings&&void 0!==TYPO3.settings.RequireJS&&void 0!==TYPO3.settings.RequireJS.PostInitializationModules&&void 0!==TYPO3.settings.RequireJS.PostInitializationModules["TYPO3/CMS/Backend/DragUploader"]&&i.each(TYPO3.settings.RequireJS.PostInitializationModules["TYPO3/CMS/Backend/DragUploader"],(t,i)=>{e([i])})},t.initialize()})); \ No newline at end of file diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/FormEngine/Container/InlineControlContainer.js b/typo3/sysext/backend/Resources/Public/JavaScript/FormEngine/Container/InlineControlContainer.js index fc4503fc2e66..fa709c8e23da 100644 --- a/typo3/sysext/backend/Resources/Public/JavaScript/FormEngine/Container/InlineControlContainer.js +++ b/typo3/sysext/backend/Resources/Public/JavaScript/FormEngine/Container/InlineControlContainer.js @@ -10,4 +10,4 @@ * * The TYPO3 project - inspiring people to share! */ -define(["require","exports","jquery","../../Utility/MessageUtility","./../InlineRelation/AjaxDispatcher","nprogress","Sortable","TYPO3/CMS/Backend/FormEngine","TYPO3/CMS/Backend/FormEngineValidation","../../Icons","../../InfoWindow","../../Modal","../../Notification","TYPO3/CMS/Core/Event/RegularEvent","../../Severity","../../Utility"],(function(e,t,n,i,o,r,a,s,l,c,d,u,h,p,g,m){"use strict";var f,b,S,j;!function(e){e.toggleSelector='[data-toggle="formengine-inline"]',e.controlSectionSelector=".t3js-formengine-irre-control",e.createNewRecordButtonSelector=".t3js-create-new-button",e.createNewRecordBySelectorSelector=".t3js-create-new-selector",e.deleteRecordButtonSelector=".t3js-editform-delete-inline-record",e.enableDisableRecordButtonSelector=".t3js-toggle-visibility-button",e.infoWindowButton='[data-action="infowindow"]',e.synchronizeLocalizeRecordButtonSelector=".t3js-synchronizelocalize-button",e.uniqueValueSelectors="select.t3js-inline-unique",e.revertUniqueness=".t3js-revert-unique",e.controlContainerButtons=".t3js-inline-controls"}(f||(f={})),function(e){e.new="inlineIsNewRecord",e.visible="panel-visible",e.collapsed="panel-collapsed"}(b||(b={})),function(e){e.structureSeparator="-"}(S||(S={})),function(e){e.DOWN="down",e.UP="up"}(j||(j={}));class v{constructor(e){this.container=null,this.ajaxDispatcher=null,this.appearance=null,this.requestQueue={},this.progessQueue={},this.noTitleString=TYPO3.lang?TYPO3.lang["FormEngine.noRecordTitle"]:"[No title]",this.handlePostMessage=e=>{if(!i.MessageUtility.verifyOrigin(e.origin))throw"Denied message sent by "+e.origin;if("typo3:foreignRelation:inserted"===e.data.actionName){if(void 0===e.data.objectGroup)throw"No object group defined for message";if(e.data.objectGroup!==this.container.dataset.objectGroup)return;if(this.isUniqueElementUsed(parseInt(e.data.uid,10),e.data.table))return void h.error("There is already a relation to the selected element");this.importRecord([e.data.objectGroup,e.data.uid])}else console.warn(`Unhandled action "${e.data.actionName}"`)},n(()=>{this.container=document.querySelector("#"+e),this.ajaxDispatcher=new o.AjaxDispatcher(this.container.dataset.objectGroup),this.registerEvents()})}static getInlineRecordContainer(e){return document.querySelector('[data-object-id="'+e+'"]')}static toggleElement(e){const t=v.getInlineRecordContainer(e);t.classList.contains(b.collapsed)?(t.classList.remove(b.collapsed),t.classList.add(b.visible)):(t.classList.remove(b.visible),t.classList.add(b.collapsed))}static isNewRecord(e){return v.getInlineRecordContainer(e).classList.contains(b.new)}static updateExpandedCollapsedStateLocally(e,t){const n=v.getInlineRecordContainer(e),i="uc[inlineView]["+n.dataset.topmostParentTable+"]["+n.dataset.topmostParentUid+"]"+n.dataset.fieldName,o=document.getElementsByName(i);o.length&&(o[0].value=t?"1":"0")}static getValuesFromHashMap(e){return Object.keys(e).map(t=>e[t])}static selectOptionValueExists(e,t){return null!==e.querySelector('option[value="'+t+'"]')}static removeSelectOptionByValue(e,t){const n=e.querySelector('option[value="'+t+'"]');null!==n&&n.remove()}static reAddSelectOption(e,t,n){if(v.selectOptionValueExists(e,t))return;const i=e.querySelectorAll("option");let o=-1;for(let e of Object.keys(n.possible)){if(e===t)break;for(let t=0;t<i.length;++t){if(i[t].value===e){o=t;break}}}-1===o?o=0:o<i.length&&o++;const r=document.createElement("option");r.text=n.possible[t],r.value=t,e.insertBefore(r,e.options[o])}registerEvents(){if(this.registerInfoButton(),this.registerSort(),this.registerCreateRecordButton(),this.registerEnableDisableButton(),this.registerDeleteButton(),this.registerSynchronizeLocalize(),this.registerRevertUniquenessAction(),this.registerToggle(),this.registerCreateRecordBySelector(),this.registerUniqueSelectFieldChanged(),new p("message",this.handlePostMessage).bindTo(window),this.getAppearance().useSortable){const e=document.querySelector("#"+this.container.getAttribute("id")+"_records");new a(e,{group:e.getAttribute("id"),handle:".sortableHandle",onSort:()=>{this.updateSorting()}})}}registerToggle(){const e=this;new p("click",(function(t){t.preventDefault(),t.stopImmediatePropagation(),e.loadRecordDetails(this.closest(f.toggleSelector).parentElement.dataset.objectId)})).delegateTo(this.container,`${f.toggleSelector} .form-irre-header-cell:not(${f.controlSectionSelector}`)}registerSort(){const e=this;new p("click",(function(t){t.preventDefault(),t.stopImmediatePropagation(),e.changeSortingByButton(this.closest("[data-object-id]").dataset.objectId,this.dataset.direction)})).delegateTo(this.container,f.controlSectionSelector+' [data-action="sort"]')}registerCreateRecordButton(){const e=this;new p("click",(function(t){if(t.preventDefault(),t.stopImmediatePropagation(),e.isBelowMax()){let t=e.container.dataset.objectGroup;void 0!==this.dataset.recordUid&&(t+=S.structureSeparator+this.dataset.recordUid),e.importRecord([t],this.dataset.recordUid)}})).delegateTo(this.container,f.createNewRecordButtonSelector)}registerCreateRecordBySelector(){const e=this;new p("change",(function(t){t.preventDefault(),t.stopImmediatePropagation();const n=this.options[this.selectedIndex].getAttribute("value");e.importRecord([e.container.dataset.objectGroup,n])})).delegateTo(this.container,f.createNewRecordBySelectorSelector)}createRecord(e,t,n=null,i=null){let o=this.container.dataset.objectGroup;null!==n&&(o+=S.structureSeparator+n),null!==n?(v.getInlineRecordContainer(o).insertAdjacentHTML("afterend",t),this.memorizeAddRecord(e,n,i)):(document.querySelector("#"+this.container.getAttribute("id")+"_records").insertAdjacentHTML("beforeend",t),this.memorizeAddRecord(e,null,i))}async importRecord(e,t){this.ajaxDispatcher.send(this.ajaxDispatcher.newRequest(this.ajaxDispatcher.getEndpoint("record_inline_create")),e).then(async e=>{this.isBelowMax()&&(this.createRecord(e.compilerInput.uid,e.data,void 0!==t?t:null,void 0!==e.compilerInput.childChildUid?e.compilerInput.childChildUid:null),s.reinitialize(),s.Validation.initializeInputFields(),s.Validation.validate())})}registerEnableDisableButton(){new p("click",(function(e){e.preventDefault(),e.stopImmediatePropagation();const t=this.closest("[data-object-id]").dataset.objectId,n=v.getInlineRecordContainer(t),i="data"+n.dataset.fieldName+"["+this.dataset.hiddenField+"]",o=document.querySelector('[data-formengine-input-name="'+i+'"'),r=document.querySelector('[name="'+i+'"');null!==o&&null!==r&&(o.checked=!o.checked,r.value=o.checked?"1":"0",TBE_EDITOR.fieldChanged_fName(i,i));const a="t3-form-field-container-inline-hidden";let s="";n.classList.contains(a)?(s="actions-edit-hide",n.classList.remove(a)):(s="actions-edit-unhide",n.classList.add(a)),c.getIcon(s,c.sizes.small).then(e=>{this.replaceChild(document.createRange().createContextualFragment(e),this.querySelector(".t3js-icon"))})})).delegateTo(this.container,f.enableDisableRecordButtonSelector)}registerInfoButton(){new p("click",(function(e){e.preventDefault(),e.stopImmediatePropagation(),d.showItem(this.dataset.infoTable,this.dataset.infoUid)})).delegateTo(this.container,f.infoWindowButton)}registerDeleteButton(){const e=this;new p("click",(function(t){t.preventDefault(),t.stopImmediatePropagation();const n=TYPO3.lang["label.confirm.delete_record.title"]||"Delete this record?",i=TYPO3.lang["label.confirm.delete_record.content"]||"Are you sure you want to delete this record?";u.confirm(n,i,g.warning,[{text:TYPO3.lang["buttons.confirm.delete_record.no"]||"Cancel",active:!0,btnClass:"btn-default",name:"no"},{text:TYPO3.lang["buttons.confirm.delete_record.yes"]||"Yes, delete this record",btnClass:"btn-warning",name:"yes"}]).on("button.clicked",t=>{if("yes"===t.target.name){const t=this.closest("[data-object-id]").dataset.objectId;e.deleteRecord(t)}u.dismiss()})})).delegateTo(this.container,f.deleteRecordButtonSelector)}registerSynchronizeLocalize(){const e=this;new p("click",(function(t){t.preventDefault(),t.stopImmediatePropagation(),e.ajaxDispatcher.send(e.ajaxDispatcher.newRequest(e.ajaxDispatcher.getEndpoint("record_inline_synchronizelocalize")),[e.container.dataset.objectGroup,this.dataset.type]).then(async t=>{document.querySelector("#"+e.container.getAttribute("id")+"_records").insertAdjacentHTML("beforeend",t.data);const n=e.container.dataset.objectGroup+S.structureSeparator;for(let i of t.compilerInput.delete)e.deleteRecord(n+i,!0);for(let i of t.compilerInput.localize){if(void 0!==i.remove){const e=v.getInlineRecordContainer(n+i.remove);e.parentElement.removeChild(e)}e.memorizeAddRecord(i.uid,null,i.selectedValue)}})})).delegateTo(this.container,f.synchronizeLocalizeRecordButtonSelector)}registerUniqueSelectFieldChanged(){const e=this;new p("change",(function(t){t.preventDefault(),t.stopImmediatePropagation();const n=this.closest("[data-object-id]");if(null!==n){const t=n.dataset.objectId,i=n.dataset.objectUid;e.handleChangedField(this,t);const o=e.getFormFieldForElements();if(null===o)return;e.updateUnique(this,o,i)}})).delegateTo(this.container,f.uniqueValueSelectors)}registerRevertUniquenessAction(){const e=this;new p("click",(function(t){t.preventDefault(),t.stopImmediatePropagation(),e.revertUnique(this.dataset.uid)})).delegateTo(this.container,f.revertUniqueness)}loadRecordDetails(e){const t=document.querySelector("#"+e+"_fields"),n=void 0!==this.requestQueue[e];if(null!==t&&"\x3c!--notloaded--\x3e"!==t.innerHTML.substr(0,16))this.collapseExpandRecord(e);else{const i=this.getProgress(e);if(n)this.requestQueue[e].abort(),delete this.requestQueue[e],delete this.progessQueue[e],i.done();else{const n=this.ajaxDispatcher.newRequest(this.ajaxDispatcher.getEndpoint("record_inline_details"));this.ajaxDispatcher.send(n,[e]).then(async n=>{if(delete this.requestQueue[e],delete this.progessQueue[e],t.innerHTML=n.data,this.collapseExpandRecord(e),i.done(),s.reinitialize(),s.Validation.initializeInputFields(),s.Validation.validate(),this.hasObjectGroupDefinedUniqueConstraints()){const t=v.getInlineRecordContainer(e);this.removeUsed(t)}}),this.requestQueue[e]=n,i.start()}}}collapseExpandRecord(e){const t=v.getInlineRecordContainer(e),n=!0===this.getAppearance().expandSingle,i=t.classList.contains(b.collapsed);let o=[];const r=[];n&&i&&(o=this.collapseAllRecords(t.dataset.objectUid)),v.toggleElement(e),v.isNewRecord(e)?v.updateExpandedCollapsedStateLocally(e,i):i?r.push(t.dataset.objectUid):i||o.push(t.dataset.objectUid),this.ajaxDispatcher.send(this.ajaxDispatcher.newRequest(this.ajaxDispatcher.getEndpoint("record_inline_expandcollapse")),[e,r.join(","),o.join(",")])}memorizeAddRecord(e,t=null,i=null){const o=this.getFormFieldForElements();if(null===o)return;let r=m.trimExplode(",",o.value);if(t){const n=[];for(let i=0;i<r.length;i++)r[i].length&&n.push(r[i]),t===r[i]&&n.push(e);r=n}else r.push(e);o.value=r.join(","),o.classList.add("has-change"),n(document).trigger("change"),this.redrawSortingButtons(this.container.dataset.objectGroup,r),this.setUnique(e,i),this.isBelowMax()||this.toggleContainerControls(!1),TBE_EDITOR.fieldChanged_fName(o.name,o)}memorizeRemoveRecord(e){const t=this.getFormFieldForElements();if(null===t)return[];let i=m.trimExplode(",",t.value);const o=i.indexOf(e);return o>-1&&(delete i[o],t.value=i.join(","),t.classList.add("has-change"),n(document).trigger("change"),this.redrawSortingButtons(this.container.dataset.objectGroup,i)),i}changeSortingByButton(e,t){const n=v.getInlineRecordContainer(e),i=n.dataset.objectUid,o=document.querySelector("#"+this.container.getAttribute("id")+"_records"),r=Array.from(o.children).map(e=>e.dataset.objectUid);let a=r.indexOf(i),s=!1;if(t===j.UP&&a>0?(r[a]=r[a-1],r[a-1]=i,s=!0):t===j.DOWN&&a<r.length-1&&(r[a]=r[a+1],r[a+1]=i,s=!0),s){const e=this.container.dataset.objectGroup+S.structureSeparator,i=t===j.UP?1:0;n.parentElement.insertBefore(v.getInlineRecordContainer(e+r[a-i]),v.getInlineRecordContainer(e+r[a+1-i])),this.updateSorting()}}updateSorting(){const e=this.getFormFieldForElements();if(null===e)return;const t=document.querySelector("#"+this.container.getAttribute("id")+"_records"),i=Array.from(t.children).map(e=>e.dataset.objectUid);e.value=i.join(","),e.classList.add("has-change"),n(document).trigger("inline:sorting-changed"),n(document).trigger("change"),this.redrawSortingButtons(this.container.dataset.objectGroup,i)}deleteRecord(e,t=!1){const n=v.getInlineRecordContainer(e),i=n.dataset.objectUid;if(n.classList.add("t3js-inline-record-deleted"),!v.isNewRecord(e)&&!t){const e=this.container.querySelector('[name="cmd'+n.dataset.fieldName+'[delete]"]');e.removeAttribute("disabled"),n.parentElement.insertAdjacentElement("afterbegin",e)}new p("transitionend",()=>{n.parentElement.removeChild(n),l.validate()}).bindTo(n),this.revertUnique(i),this.memorizeRemoveRecord(i),n.classList.add("form-irre-object--deleted"),this.isBelowMax()&&this.toggleContainerControls(!0)}toggleContainerControls(e){this.container.querySelectorAll(f.controlContainerButtons+" a").forEach(t=>{t.style.display=e?null:"none"})}getProgress(e){const t="#"+e+"_header";let n;return void 0!==this.progessQueue[e]?n=this.progessQueue[e]:(n=r,n.configure({parent:t,showSpinner:!1}),this.progessQueue[e]=n),n}collapseAllRecords(e){const t=this.getFormFieldForElements(),n=[];if(null!==t){const i=m.trimExplode(",",t.value);for(let t of i){if(t===e)continue;const i=this.container.dataset.objectGroup+S.structureSeparator+t,o=v.getInlineRecordContainer(i);o.classList.contains(b.visible)&&(o.classList.remove(b.visible),o.classList.add(b.collapsed),v.isNewRecord(i)?v.updateExpandedCollapsedStateLocally(i,!1):n.push(t))}}return n}getFormFieldForElements(){const e=document.getElementsByName(this.container.dataset.formField);return e.length>0?e[0]:null}redrawSortingButtons(e,t=[]){if(0===t.length){const e=this.getFormFieldForElements();null!==e&&(t=m.trimExplode(",",e.value))}0!==t.length&&t.forEach((n,i)=>{const o="#"+e+S.structureSeparator+n+"_header",r=document.querySelector(o),a=r.querySelector('[data-action="sort"][data-direction="'+j.UP+'"]');if(null!==a){let e="actions-move-up";0===i?(a.classList.add("disabled"),e="empty-empty"):a.classList.remove("disabled"),c.getIcon(e,c.sizes.small).then(e=>{a.replaceChild(document.createRange().createContextualFragment(e),a.querySelector(".t3js-icon"))})}const s=r.querySelector('[data-action="sort"][data-direction="'+j.DOWN+'"]');if(null!==s){let e="actions-move-down";i===t.length-1?(s.classList.add("disabled"),e="empty-empty"):s.classList.remove("disabled"),c.getIcon(e,c.sizes.small).then(e=>{s.replaceChild(document.createRange().createContextualFragment(e),s.querySelector(".t3js-icon"))})}})}isBelowMax(){const e=this.getFormFieldForElements();if(null===e)return!0;if(void 0!==TYPO3.settings.FormEngineInline.config[this.container.dataset.objectGroup]){if(m.trimExplode(",",e.value).length>=TYPO3.settings.FormEngineInline.config[this.container.dataset.objectGroup].max)return!1;if(this.hasObjectGroupDefinedUniqueConstraints()){const e=TYPO3.settings.FormEngineInline.unique[this.container.dataset.objectGroup];if(e.used.length>=e.max&&e.max>=0)return!1}}return!0}isUniqueElementUsed(e,t){if(!this.hasObjectGroupDefinedUniqueConstraints())return!1;const n=TYPO3.settings.FormEngineInline.unique[this.container.dataset.objectGroup],i=v.getValuesFromHashMap(n.used);if("select"===n.type&&-1!==i.indexOf(e))return!0;if("groupdb"===n.type)for(let n=i.length-1;n>=0;n--)if(i[n].table===t&&i[n].uid===e)return!0;return!1}removeUsed(e){if(!this.hasObjectGroupDefinedUniqueConstraints())return;const t=TYPO3.settings.FormEngineInline.unique[this.container.dataset.objectGroup];if("select"!==t.type)return;let n=e.querySelector('[name="data['+t.table+"]["+e.dataset.objectUid+"]["+t.field+']"]');const i=v.getValuesFromHashMap(t.used);if(null!==n){const e=n.options[n.selectedIndex].value;for(let t of i)t!==e&&v.removeSelectOptionByValue(n,t)}}setUnique(e,t){if(!this.hasObjectGroupDefinedUniqueConstraints())return;const n=document.querySelector("#"+this.container.dataset.objectGroup+"_selector"),i=TYPO3.settings.FormEngineInline.unique[this.container.dataset.objectGroup];if("select"===i.type){if(!i.selector||-1!==i.max){const o=this.getFormFieldForElements(),r=this.container.dataset.objectGroup+S.structureSeparator+e;let a=v.getInlineRecordContainer(r).querySelector('[name="data['+i.table+"]["+e+"]["+i.field+']"]');const s=v.getValuesFromHashMap(i.used);if(null!==n){if(null!==a){for(let e of s)v.removeSelectOptionByValue(a,e);i.selector||(t=a.options[0].value,a.options[0].selected=!0,this.updateUnique(a,o,e),this.handleChangedField(a,this.container.dataset.objectGroup+"["+e+"]"))}for(let e of s)v.removeSelectOptionByValue(a,e);void 0!==i.used.length&&(i.used={}),i.used[e]={table:i.elTable,uid:t}}if(null!==o&&v.selectOptionValueExists(n,t)){const n=m.trimExplode(",",o.value);for(let o of n)a=document.querySelector('[name="data['+i.table+"]["+o+"]["+i.field+']"]'),null!==a&&o!==e&&v.removeSelectOptionByValue(a,t)}}}else"groupdb"===i.type&&(i.used[e]={table:i.elTable,uid:t});"select"===i.selector&&v.selectOptionValueExists(n,t)&&(v.removeSelectOptionByValue(n,t),i.used[e]={table:i.elTable,uid:t})}updateUnique(e,t,n){if(!this.hasObjectGroupDefinedUniqueConstraints())return;const i=TYPO3.settings.FormEngineInline.unique[this.container.dataset.objectGroup],o=i.used[n];if("select"===i.selector){const t=document.querySelector("#"+this.container.dataset.objectGroup+"_selector");v.removeSelectOptionByValue(t,e.value),void 0!==o&&v.reAddSelectOption(t,o,i)}if(i.selector&&-1===i.max)return;if(!i||null===t)return;const r=m.trimExplode(",",t.value);let a;for(let t of r)a=document.querySelector('[name="data['+i.table+"]["+t+"]["+i.field+']"]'),null!==a&&a!==e&&(v.removeSelectOptionByValue(a,e.value),void 0!==o&&v.reAddSelectOption(a,o,i));i.used[n]=e.value}revertUnique(e){if(!this.hasObjectGroupDefinedUniqueConstraints())return;const t=TYPO3.settings.FormEngineInline.unique[this.container.dataset.objectGroup],n=this.container.dataset.objectGroup+S.structureSeparator+e,i=v.getInlineRecordContainer(n);let o=i.querySelector('[name="data['+t.table+"]["+i.dataset.objectUid+"]["+t.field+']"]');if("select"===t.type){let n;if(null!==o)n=o.value;else{if(""===i.dataset.tableUniqueOriginalValue)return;n=i.dataset.tableUniqueOriginalValue}if("select"===t.selector&&!isNaN(parseInt(n,10))){const e=document.querySelector("#"+this.container.dataset.objectGroup+"_selector");v.reAddSelectOption(e,n,t)}if(t.selector&&-1===t.max)return;const r=this.getFormFieldForElements();if(null===r)return;const a=m.trimExplode(",",r.value);let s;for(let e=0;e<a.length;e++)s=document.querySelector('[name="data['+t.table+"]["+a[e]+"]["+t.field+']"]'),null!==s&&v.reAddSelectOption(s,n,t);delete t.used[e]}else"groupdb"===t.type&&delete t.used[e]}hasObjectGroupDefinedUniqueConstraints(){return void 0!==TYPO3.settings.FormEngineInline.unique&&void 0!==TYPO3.settings.FormEngineInline.unique[this.container.dataset.objectGroup]}handleChangedField(e,t){let n;n=e instanceof HTMLSelectElement?e.options[e.selectedIndex].text:e.value,document.querySelector("#"+t+"_label").textContent=n.length?n:this.noTitleString}getAppearance(){if(null===this.appearance&&(this.appearance={},"string"==typeof this.container.dataset.appearance))try{this.appearance=JSON.parse(this.container.dataset.appearance)}catch(e){console.error(e)}return this.appearance}}return v})); \ No newline at end of file +define(["require","exports","jquery","../../Utility/MessageUtility","./../InlineRelation/AjaxDispatcher","nprogress","Sortable","TYPO3/CMS/Backend/FormEngine","TYPO3/CMS/Backend/FormEngineValidation","../../Icons","../../InfoWindow","../../Modal","../../Notification","TYPO3/CMS/Core/Event/RegularEvent","../../Severity","../../Utility"],(function(e,t,n,i,o,r,a,s,l,c,d,u,h,p,g,m){"use strict";var f,b,S,j;!function(e){e.toggleSelector='[data-toggle="formengine-inline"]',e.controlSectionSelector=".t3js-formengine-irre-control",e.createNewRecordButtonSelector=".t3js-create-new-button",e.createNewRecordBySelectorSelector=".t3js-create-new-selector",e.deleteRecordButtonSelector=".t3js-editform-delete-inline-record",e.enableDisableRecordButtonSelector=".t3js-toggle-visibility-button",e.infoWindowButton='[data-action="infowindow"]',e.synchronizeLocalizeRecordButtonSelector=".t3js-synchronizelocalize-button",e.uniqueValueSelectors="select.t3js-inline-unique",e.revertUniqueness=".t3js-revert-unique",e.controlContainerButtons=".t3js-inline-controls"}(f||(f={})),function(e){e.new="inlineIsNewRecord",e.visible="panel-visible",e.collapsed="panel-collapsed"}(b||(b={})),function(e){e.structureSeparator="-"}(S||(S={})),function(e){e.DOWN="down",e.UP="up"}(j||(j={}));class v{constructor(e){this.container=null,this.ajaxDispatcher=null,this.appearance=null,this.requestQueue={},this.progessQueue={},this.noTitleString=TYPO3.lang?TYPO3.lang["FormEngine.noRecordTitle"]:"[No title]",this.handlePostMessage=e=>{if(!i.MessageUtility.verifyOrigin(e.origin))throw"Denied message sent by "+e.origin;if("typo3:foreignRelation:insert"===e.data.actionName){if(void 0===e.data.objectGroup)throw"No object group defined for message";if(e.data.objectGroup!==this.container.dataset.objectGroup)return;if(this.isUniqueElementUsed(parseInt(e.data.uid,10),e.data.table))return void h.error("There is already a relation to the selected element");this.importRecord([e.data.objectGroup,e.data.uid]).then(()=>{if(e.source){const t={actionName:"typo3:foreignRelation:inserted",objectGroup:e.data.objectId,table:e.data.table,uid:e.data.uid};i.MessageUtility.send(t,e.source)}})}else console.warn(`Unhandled action "${e.data.actionName}"`)},n(()=>{this.container=document.querySelector("#"+e),this.ajaxDispatcher=new o.AjaxDispatcher(this.container.dataset.objectGroup),this.registerEvents()})}static getInlineRecordContainer(e){return document.querySelector('[data-object-id="'+e+'"]')}static toggleElement(e){const t=v.getInlineRecordContainer(e);t.classList.contains(b.collapsed)?(t.classList.remove(b.collapsed),t.classList.add(b.visible)):(t.classList.remove(b.visible),t.classList.add(b.collapsed))}static isNewRecord(e){return v.getInlineRecordContainer(e).classList.contains(b.new)}static updateExpandedCollapsedStateLocally(e,t){const n=v.getInlineRecordContainer(e),i="uc[inlineView]["+n.dataset.topmostParentTable+"]["+n.dataset.topmostParentUid+"]"+n.dataset.fieldName,o=document.getElementsByName(i);o.length&&(o[0].value=t?"1":"0")}static getValuesFromHashMap(e){return Object.keys(e).map(t=>e[t])}static selectOptionValueExists(e,t){return null!==e.querySelector('option[value="'+t+'"]')}static removeSelectOptionByValue(e,t){const n=e.querySelector('option[value="'+t+'"]');null!==n&&n.remove()}static reAddSelectOption(e,t,n){if(v.selectOptionValueExists(e,t))return;const i=e.querySelectorAll("option");let o=-1;for(let e of Object.keys(n.possible)){if(e===t)break;for(let t=0;t<i.length;++t){if(i[t].value===e){o=t;break}}}-1===o?o=0:o<i.length&&o++;const r=document.createElement("option");r.text=n.possible[t],r.value=t,e.insertBefore(r,e.options[o])}registerEvents(){if(this.registerInfoButton(),this.registerSort(),this.registerCreateRecordButton(),this.registerEnableDisableButton(),this.registerDeleteButton(),this.registerSynchronizeLocalize(),this.registerRevertUniquenessAction(),this.registerToggle(),this.registerCreateRecordBySelector(),this.registerUniqueSelectFieldChanged(),new p("message",this.handlePostMessage).bindTo(window),this.getAppearance().useSortable){const e=document.querySelector("#"+this.container.getAttribute("id")+"_records");new a(e,{group:e.getAttribute("id"),handle:".sortableHandle",onSort:()=>{this.updateSorting()}})}}registerToggle(){const e=this;new p("click",(function(t){t.preventDefault(),t.stopImmediatePropagation(),e.loadRecordDetails(this.closest(f.toggleSelector).parentElement.dataset.objectId)})).delegateTo(this.container,`${f.toggleSelector} .form-irre-header-cell:not(${f.controlSectionSelector}`)}registerSort(){const e=this;new p("click",(function(t){t.preventDefault(),t.stopImmediatePropagation(),e.changeSortingByButton(this.closest("[data-object-id]").dataset.objectId,this.dataset.direction)})).delegateTo(this.container,f.controlSectionSelector+' [data-action="sort"]')}registerCreateRecordButton(){const e=this;new p("click",(function(t){if(t.preventDefault(),t.stopImmediatePropagation(),e.isBelowMax()){let t=e.container.dataset.objectGroup;void 0!==this.dataset.recordUid&&(t+=S.structureSeparator+this.dataset.recordUid),e.importRecord([t],this.dataset.recordUid)}})).delegateTo(this.container,f.createNewRecordButtonSelector)}registerCreateRecordBySelector(){const e=this;new p("change",(function(t){t.preventDefault(),t.stopImmediatePropagation();const n=this.options[this.selectedIndex].getAttribute("value");e.importRecord([e.container.dataset.objectGroup,n])})).delegateTo(this.container,f.createNewRecordBySelectorSelector)}createRecord(e,t,n=null,i=null){let o=this.container.dataset.objectGroup;null!==n&&(o+=S.structureSeparator+n),null!==n?(v.getInlineRecordContainer(o).insertAdjacentHTML("afterend",t),this.memorizeAddRecord(e,n,i)):(document.querySelector("#"+this.container.getAttribute("id")+"_records").insertAdjacentHTML("beforeend",t),this.memorizeAddRecord(e,null,i))}async importRecord(e,t){return this.ajaxDispatcher.send(this.ajaxDispatcher.newRequest(this.ajaxDispatcher.getEndpoint("record_inline_create")),e).then(async e=>{this.isBelowMax()&&(this.createRecord(e.compilerInput.uid,e.data,void 0!==t?t:null,void 0!==e.compilerInput.childChildUid?e.compilerInput.childChildUid:null),s.reinitialize(),s.Validation.initializeInputFields(),s.Validation.validate())})}registerEnableDisableButton(){new p("click",(function(e){e.preventDefault(),e.stopImmediatePropagation();const t=this.closest("[data-object-id]").dataset.objectId,n=v.getInlineRecordContainer(t),i="data"+n.dataset.fieldName+"["+this.dataset.hiddenField+"]",o=document.querySelector('[data-formengine-input-name="'+i+'"'),r=document.querySelector('[name="'+i+'"');null!==o&&null!==r&&(o.checked=!o.checked,r.value=o.checked?"1":"0",TBE_EDITOR.fieldChanged_fName(i,i));const a="t3-form-field-container-inline-hidden";let s="";n.classList.contains(a)?(s="actions-edit-hide",n.classList.remove(a)):(s="actions-edit-unhide",n.classList.add(a)),c.getIcon(s,c.sizes.small).then(e=>{this.replaceChild(document.createRange().createContextualFragment(e),this.querySelector(".t3js-icon"))})})).delegateTo(this.container,f.enableDisableRecordButtonSelector)}registerInfoButton(){new p("click",(function(e){e.preventDefault(),e.stopImmediatePropagation(),d.showItem(this.dataset.infoTable,this.dataset.infoUid)})).delegateTo(this.container,f.infoWindowButton)}registerDeleteButton(){const e=this;new p("click",(function(t){t.preventDefault(),t.stopImmediatePropagation();const n=TYPO3.lang["label.confirm.delete_record.title"]||"Delete this record?",i=TYPO3.lang["label.confirm.delete_record.content"]||"Are you sure you want to delete this record?";u.confirm(n,i,g.warning,[{text:TYPO3.lang["buttons.confirm.delete_record.no"]||"Cancel",active:!0,btnClass:"btn-default",name:"no"},{text:TYPO3.lang["buttons.confirm.delete_record.yes"]||"Yes, delete this record",btnClass:"btn-warning",name:"yes"}]).on("button.clicked",t=>{if("yes"===t.target.name){const t=this.closest("[data-object-id]").dataset.objectId;e.deleteRecord(t)}u.dismiss()})})).delegateTo(this.container,f.deleteRecordButtonSelector)}registerSynchronizeLocalize(){const e=this;new p("click",(function(t){t.preventDefault(),t.stopImmediatePropagation(),e.ajaxDispatcher.send(e.ajaxDispatcher.newRequest(e.ajaxDispatcher.getEndpoint("record_inline_synchronizelocalize")),[e.container.dataset.objectGroup,this.dataset.type]).then(async t=>{document.querySelector("#"+e.container.getAttribute("id")+"_records").insertAdjacentHTML("beforeend",t.data);const n=e.container.dataset.objectGroup+S.structureSeparator;for(let i of t.compilerInput.delete)e.deleteRecord(n+i,!0);for(let i of t.compilerInput.localize){if(void 0!==i.remove){const e=v.getInlineRecordContainer(n+i.remove);e.parentElement.removeChild(e)}e.memorizeAddRecord(i.uid,null,i.selectedValue)}})})).delegateTo(this.container,f.synchronizeLocalizeRecordButtonSelector)}registerUniqueSelectFieldChanged(){const e=this;new p("change",(function(t){t.preventDefault(),t.stopImmediatePropagation();const n=this.closest("[data-object-id]");if(null!==n){const t=n.dataset.objectId,i=n.dataset.objectUid;e.handleChangedField(this,t);const o=e.getFormFieldForElements();if(null===o)return;e.updateUnique(this,o,i)}})).delegateTo(this.container,f.uniqueValueSelectors)}registerRevertUniquenessAction(){const e=this;new p("click",(function(t){t.preventDefault(),t.stopImmediatePropagation(),e.revertUnique(this.dataset.uid)})).delegateTo(this.container,f.revertUniqueness)}loadRecordDetails(e){const t=document.querySelector("#"+e+"_fields"),n=void 0!==this.requestQueue[e];if(null!==t&&"\x3c!--notloaded--\x3e"!==t.innerHTML.substr(0,16))this.collapseExpandRecord(e);else{const i=this.getProgress(e);if(n)this.requestQueue[e].abort(),delete this.requestQueue[e],delete this.progessQueue[e],i.done();else{const n=this.ajaxDispatcher.newRequest(this.ajaxDispatcher.getEndpoint("record_inline_details"));this.ajaxDispatcher.send(n,[e]).then(async n=>{if(delete this.requestQueue[e],delete this.progessQueue[e],t.innerHTML=n.data,this.collapseExpandRecord(e),i.done(),s.reinitialize(),s.Validation.initializeInputFields(),s.Validation.validate(),this.hasObjectGroupDefinedUniqueConstraints()){const t=v.getInlineRecordContainer(e);this.removeUsed(t)}}),this.requestQueue[e]=n,i.start()}}}collapseExpandRecord(e){const t=v.getInlineRecordContainer(e),n=!0===this.getAppearance().expandSingle,i=t.classList.contains(b.collapsed);let o=[];const r=[];n&&i&&(o=this.collapseAllRecords(t.dataset.objectUid)),v.toggleElement(e),v.isNewRecord(e)?v.updateExpandedCollapsedStateLocally(e,i):i?r.push(t.dataset.objectUid):i||o.push(t.dataset.objectUid),this.ajaxDispatcher.send(this.ajaxDispatcher.newRequest(this.ajaxDispatcher.getEndpoint("record_inline_expandcollapse")),[e,r.join(","),o.join(",")])}memorizeAddRecord(e,t=null,i=null){const o=this.getFormFieldForElements();if(null===o)return;let r=m.trimExplode(",",o.value);if(t){const n=[];for(let i=0;i<r.length;i++)r[i].length&&n.push(r[i]),t===r[i]&&n.push(e);r=n}else r.push(e);o.value=r.join(","),o.classList.add("has-change"),n(document).trigger("change"),this.redrawSortingButtons(this.container.dataset.objectGroup,r),this.setUnique(e,i),this.isBelowMax()||this.toggleContainerControls(!1),TBE_EDITOR.fieldChanged_fName(o.name,o)}memorizeRemoveRecord(e){const t=this.getFormFieldForElements();if(null===t)return[];let i=m.trimExplode(",",t.value);const o=i.indexOf(e);return o>-1&&(delete i[o],t.value=i.join(","),t.classList.add("has-change"),n(document).trigger("change"),this.redrawSortingButtons(this.container.dataset.objectGroup,i)),i}changeSortingByButton(e,t){const n=v.getInlineRecordContainer(e),i=n.dataset.objectUid,o=document.querySelector("#"+this.container.getAttribute("id")+"_records"),r=Array.from(o.children).map(e=>e.dataset.objectUid);let a=r.indexOf(i),s=!1;if(t===j.UP&&a>0?(r[a]=r[a-1],r[a-1]=i,s=!0):t===j.DOWN&&a<r.length-1&&(r[a]=r[a+1],r[a+1]=i,s=!0),s){const e=this.container.dataset.objectGroup+S.structureSeparator,i=t===j.UP?1:0;n.parentElement.insertBefore(v.getInlineRecordContainer(e+r[a-i]),v.getInlineRecordContainer(e+r[a+1-i])),this.updateSorting()}}updateSorting(){const e=this.getFormFieldForElements();if(null===e)return;const t=document.querySelector("#"+this.container.getAttribute("id")+"_records"),i=Array.from(t.children).map(e=>e.dataset.objectUid);e.value=i.join(","),e.classList.add("has-change"),n(document).trigger("inline:sorting-changed"),n(document).trigger("change"),this.redrawSortingButtons(this.container.dataset.objectGroup,i)}deleteRecord(e,t=!1){const n=v.getInlineRecordContainer(e),i=n.dataset.objectUid;if(n.classList.add("t3js-inline-record-deleted"),!v.isNewRecord(e)&&!t){const e=this.container.querySelector('[name="cmd'+n.dataset.fieldName+'[delete]"]');e.removeAttribute("disabled"),n.parentElement.insertAdjacentElement("afterbegin",e)}new p("transitionend",()=>{n.parentElement.removeChild(n),l.validate()}).bindTo(n),this.revertUnique(i),this.memorizeRemoveRecord(i),n.classList.add("form-irre-object--deleted"),this.isBelowMax()&&this.toggleContainerControls(!0)}toggleContainerControls(e){this.container.querySelectorAll(f.controlContainerButtons+" a").forEach(t=>{t.style.display=e?null:"none"})}getProgress(e){const t="#"+e+"_header";let n;return void 0!==this.progessQueue[e]?n=this.progessQueue[e]:(n=r,n.configure({parent:t,showSpinner:!1}),this.progessQueue[e]=n),n}collapseAllRecords(e){const t=this.getFormFieldForElements(),n=[];if(null!==t){const i=m.trimExplode(",",t.value);for(let t of i){if(t===e)continue;const i=this.container.dataset.objectGroup+S.structureSeparator+t,o=v.getInlineRecordContainer(i);o.classList.contains(b.visible)&&(o.classList.remove(b.visible),o.classList.add(b.collapsed),v.isNewRecord(i)?v.updateExpandedCollapsedStateLocally(i,!1):n.push(t))}}return n}getFormFieldForElements(){const e=document.getElementsByName(this.container.dataset.formField);return e.length>0?e[0]:null}redrawSortingButtons(e,t=[]){if(0===t.length){const e=this.getFormFieldForElements();null!==e&&(t=m.trimExplode(",",e.value))}0!==t.length&&t.forEach((n,i)=>{const o="#"+e+S.structureSeparator+n+"_header",r=document.querySelector(o),a=r.querySelector('[data-action="sort"][data-direction="'+j.UP+'"]');if(null!==a){let e="actions-move-up";0===i?(a.classList.add("disabled"),e="empty-empty"):a.classList.remove("disabled"),c.getIcon(e,c.sizes.small).then(e=>{a.replaceChild(document.createRange().createContextualFragment(e),a.querySelector(".t3js-icon"))})}const s=r.querySelector('[data-action="sort"][data-direction="'+j.DOWN+'"]');if(null!==s){let e="actions-move-down";i===t.length-1?(s.classList.add("disabled"),e="empty-empty"):s.classList.remove("disabled"),c.getIcon(e,c.sizes.small).then(e=>{s.replaceChild(document.createRange().createContextualFragment(e),s.querySelector(".t3js-icon"))})}})}isBelowMax(){const e=this.getFormFieldForElements();if(null===e)return!0;if(void 0!==TYPO3.settings.FormEngineInline.config[this.container.dataset.objectGroup]){if(m.trimExplode(",",e.value).length>=TYPO3.settings.FormEngineInline.config[this.container.dataset.objectGroup].max)return!1;if(this.hasObjectGroupDefinedUniqueConstraints()){const e=TYPO3.settings.FormEngineInline.unique[this.container.dataset.objectGroup];if(e.used.length>=e.max&&e.max>=0)return!1}}return!0}isUniqueElementUsed(e,t){if(!this.hasObjectGroupDefinedUniqueConstraints())return!1;const n=TYPO3.settings.FormEngineInline.unique[this.container.dataset.objectGroup],i=v.getValuesFromHashMap(n.used);if("select"===n.type&&-1!==i.indexOf(e))return!0;if("groupdb"===n.type)for(let n=i.length-1;n>=0;n--)if(i[n].table===t&&i[n].uid===e)return!0;return!1}removeUsed(e){if(!this.hasObjectGroupDefinedUniqueConstraints())return;const t=TYPO3.settings.FormEngineInline.unique[this.container.dataset.objectGroup];if("select"!==t.type)return;let n=e.querySelector('[name="data['+t.table+"]["+e.dataset.objectUid+"]["+t.field+']"]');const i=v.getValuesFromHashMap(t.used);if(null!==n){const e=n.options[n.selectedIndex].value;for(let t of i)t!==e&&v.removeSelectOptionByValue(n,t)}}setUnique(e,t){if(!this.hasObjectGroupDefinedUniqueConstraints())return;const n=document.querySelector("#"+this.container.dataset.objectGroup+"_selector"),i=TYPO3.settings.FormEngineInline.unique[this.container.dataset.objectGroup];if("select"===i.type){if(!i.selector||-1!==i.max){const o=this.getFormFieldForElements(),r=this.container.dataset.objectGroup+S.structureSeparator+e;let a=v.getInlineRecordContainer(r).querySelector('[name="data['+i.table+"]["+e+"]["+i.field+']"]');const s=v.getValuesFromHashMap(i.used);if(null!==n){if(null!==a){for(let e of s)v.removeSelectOptionByValue(a,e);i.selector||(t=a.options[0].value,a.options[0].selected=!0,this.updateUnique(a,o,e),this.handleChangedField(a,this.container.dataset.objectGroup+"["+e+"]"))}for(let e of s)v.removeSelectOptionByValue(a,e);void 0!==i.used.length&&(i.used={}),i.used[e]={table:i.elTable,uid:t}}if(null!==o&&v.selectOptionValueExists(n,t)){const n=m.trimExplode(",",o.value);for(let o of n)a=document.querySelector('[name="data['+i.table+"]["+o+"]["+i.field+']"]'),null!==a&&o!==e&&v.removeSelectOptionByValue(a,t)}}}else"groupdb"===i.type&&(i.used[e]={table:i.elTable,uid:t});"select"===i.selector&&v.selectOptionValueExists(n,t)&&(v.removeSelectOptionByValue(n,t),i.used[e]={table:i.elTable,uid:t})}updateUnique(e,t,n){if(!this.hasObjectGroupDefinedUniqueConstraints())return;const i=TYPO3.settings.FormEngineInline.unique[this.container.dataset.objectGroup],o=i.used[n];if("select"===i.selector){const t=document.querySelector("#"+this.container.dataset.objectGroup+"_selector");v.removeSelectOptionByValue(t,e.value),void 0!==o&&v.reAddSelectOption(t,o,i)}if(i.selector&&-1===i.max)return;if(!i||null===t)return;const r=m.trimExplode(",",t.value);let a;for(let t of r)a=document.querySelector('[name="data['+i.table+"]["+t+"]["+i.field+']"]'),null!==a&&a!==e&&(v.removeSelectOptionByValue(a,e.value),void 0!==o&&v.reAddSelectOption(a,o,i));i.used[n]=e.value}revertUnique(e){if(!this.hasObjectGroupDefinedUniqueConstraints())return;const t=TYPO3.settings.FormEngineInline.unique[this.container.dataset.objectGroup],n=this.container.dataset.objectGroup+S.structureSeparator+e,i=v.getInlineRecordContainer(n);let o=i.querySelector('[name="data['+t.table+"]["+i.dataset.objectUid+"]["+t.field+']"]');if("select"===t.type){let n;if(null!==o)n=o.value;else{if(""===i.dataset.tableUniqueOriginalValue)return;n=i.dataset.tableUniqueOriginalValue}if("select"===t.selector&&!isNaN(parseInt(n,10))){const e=document.querySelector("#"+this.container.dataset.objectGroup+"_selector");v.reAddSelectOption(e,n,t)}if(t.selector&&-1===t.max)return;const r=this.getFormFieldForElements();if(null===r)return;const a=m.trimExplode(",",r.value);let s;for(let e=0;e<a.length;e++)s=document.querySelector('[name="data['+t.table+"]["+a[e]+"]["+t.field+']"]'),null!==s&&v.reAddSelectOption(s,n,t);delete t.used[e]}else"groupdb"===t.type&&delete t.used[e]}hasObjectGroupDefinedUniqueConstraints(){return void 0!==TYPO3.settings.FormEngineInline.unique&&void 0!==TYPO3.settings.FormEngineInline.unique[this.container.dataset.objectGroup]}handleChangedField(e,t){let n;n=e instanceof HTMLSelectElement?e.options[e.selectedIndex].text:e.value,document.querySelector("#"+t+"_label").textContent=n.length?n:this.noTitleString}getAppearance(){if(null===this.appearance&&(this.appearance={},"string"==typeof this.container.dataset.appearance))try{this.appearance=JSON.parse(this.container.dataset.appearance)}catch(e){console.error(e)}return this.appearance}}return v})); \ No newline at end of file diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/OnlineMedia.js b/typo3/sysext/backend/Resources/Public/JavaScript/OnlineMedia.js index 4af0d31c5c05..fec50dc00bd8 100644 --- a/typo3/sysext/backend/Resources/Public/JavaScript/OnlineMedia.js +++ b/typo3/sysext/backend/Resources/Public/JavaScript/OnlineMedia.js @@ -10,4 +10,4 @@ * * The TYPO3 project - inspiring people to share! */ -define(["require","exports","./Enum/KeyTypes","jquery","nprogress","./Modal","./Severity","TYPO3/CMS/Core/SecurityUtility","TYPO3/CMS/Backend/Utility/MessageUtility"],(function(e,t,i,n,a,r,o,l,s){"use strict";return new class{constructor(){this.securityUtility=new l,n(()=>{this.registerEvents()})}registerEvents(){const e=this;n(document).on("click",".t3js-online-media-add-btn",t=>{e.triggerModal(n(t.currentTarget))})}addOnlineMedia(e,t){const i=e.data("target-folder"),l=e.data("online-media-allowed"),d=e.data("file-irre-object");a.start(),n.post(TYPO3.settings.ajaxUrls.online_media_create,{url:t,targetFolder:i,allowed:l},e=>{if(e.file){const t={actionName:"typo3:foreignRelation:inserted",objectGroup:d,table:"sys_file",uid:e.file};s.MessageUtility.send(t)}else{const t=r.confirm("ERROR",e.error,o.error,[{text:TYPO3.lang["button.ok"]||"OK",btnClass:"btn-"+o.getCssClass(o.error),name:"ok",active:!0}]).on("confirm.button.ok",()=>{t.modal("hide")})}a.done()})}triggerModal(e){const t=e.data("btn-submit")||"Add",a=e.data("placeholder")||"Paste media url here...",l=n.map(e.data("online-media-allowed").split(","),e=>'<span class="label label-success">'+this.securityUtility.encodeHtml(e.toUpperCase(),!1)+"</span>"),s=e.data("online-media-allowed-help-text")||"Allow to embed from sources:",d=n("<div>").attr("class","form-control-wrap").append([n("<input>").attr("type","text").attr("class","form-control online-media-url").attr("placeholder",a),n("<div>").attr("class","help-block").html(this.securityUtility.encodeHtml(s,!1)+"<br>"+l.join(" "))]),c=r.show(e.attr("title"),d,o.notice,[{text:t,btnClass:"btn btn-primary",name:"ok",trigger:()=>{const t=c.find("input.online-media-url").val();t&&(c.modal("hide"),this.addOnlineMedia(e,t))}}]);c.on("shown.bs.modal",e=>{n(e.currentTarget).find("input.online-media-url").first().focus().on("keydown",e=>{e.keyCode===i.KeyTypesEnum.ENTER&&c.find('button[name="ok"]').trigger("click")})})}}})); \ No newline at end of file +define(["require","exports","./Enum/KeyTypes","jquery","nprogress","./Modal","./Severity","TYPO3/CMS/Core/SecurityUtility","TYPO3/CMS/Backend/Utility/MessageUtility"],(function(e,t,i,n,a,r,o,l,s){"use strict";return new class{constructor(){this.securityUtility=new l,n(()=>{this.registerEvents()})}registerEvents(){const e=this;n(document).on("click",".t3js-online-media-add-btn",t=>{e.triggerModal(n(t.currentTarget))})}addOnlineMedia(e,t){const i=e.data("target-folder"),l=e.data("online-media-allowed"),d=e.data("file-irre-object");a.start(),n.post(TYPO3.settings.ajaxUrls.online_media_create,{url:t,targetFolder:i,allowed:l},e=>{if(e.file){const t={actionName:"typo3:foreignRelation:insert",objectGroup:d,table:"sys_file",uid:e.file};s.MessageUtility.send(t)}else{const t=r.confirm("ERROR",e.error,o.error,[{text:TYPO3.lang["button.ok"]||"OK",btnClass:"btn-"+o.getCssClass(o.error),name:"ok",active:!0}]).on("confirm.button.ok",()=>{t.modal("hide")})}a.done()})}triggerModal(e){const t=e.data("btn-submit")||"Add",a=e.data("placeholder")||"Paste media url here...",l=n.map(e.data("online-media-allowed").split(","),e=>'<span class="label label-success">'+this.securityUtility.encodeHtml(e.toUpperCase(),!1)+"</span>"),s=e.data("online-media-allowed-help-text")||"Allow to embed from sources:",d=n("<div>").attr("class","form-control-wrap").append([n("<input>").attr("type","text").attr("class","form-control online-media-url").attr("placeholder",a),n("<div>").attr("class","help-block").html(this.securityUtility.encodeHtml(s,!1)+"<br>"+l.join(" "))]),c=r.show(e.attr("title"),d,o.notice,[{text:t,btnClass:"btn btn-primary",name:"ok",trigger:()=>{const t=c.find("input.online-media-url").val();t&&(c.modal("hide"),this.addOnlineMedia(e,t))}}]);c.on("shown.bs.modal",e=>{n(e.currentTarget).find("input.online-media-url").first().focus().on("keydown",e=>{e.keyCode===i.KeyTypesEnum.ENTER&&c.find('button[name="ok"]').trigger("click")})})}}})); \ No newline at end of file diff --git a/typo3/sysext/recordlist/Resources/Public/JavaScript/BrowseFiles.js b/typo3/sysext/recordlist/Resources/Public/JavaScript/BrowseFiles.js index f17274cdb3eb..c7eeada300eb 100644 --- a/typo3/sysext/recordlist/Resources/Public/JavaScript/BrowseFiles.js +++ b/typo3/sysext/recordlist/Resources/Public/JavaScript/BrowseFiles.js @@ -10,4 +10,4 @@ * * The TYPO3 project - inspiring people to share! */ -define(["require","exports","jquery","./ElementBrowser","TYPO3/CMS/Backend/LegacyTree"],(function(e,t,n,l,c){"use strict";class s{constructor(){c.noop(),s.File=new r,s.Selector=new i,n(()=>{s.elements=n("body").data("elements"),n("[data-close]").on("click",e=>{e.preventDefault(),s.File.insertElement("file_"+n(e.currentTarget).data("fileIndex"),1===parseInt(n(e.currentTarget).data("close"),10))}),n("#t3js-importSelection").on("click",s.Selector.handle),n("#t3js-toggleSelection").on("click",s.Selector.toggle)})}}class r{insertElement(e,t){let n=!1;if(void 0!==s.elements[e]){const c=s.elements[e];n=l.insertElement(c.table,c.uid,c.type,c.fileName,c.filePath,c.fileExt,c.fileIcon,"",t)}return n}}class i{constructor(){this.toggle=e=>{e.preventDefault();const t=this.getItems();t.length&&t.each((e,t)=>{t.checked=t.checked?null:"checked"})},this.handle=e=>{e.preventDefault();const t=this.getItems(),n=[];if(t.length){if(t.each((e,t)=>{t.checked&&t.name&&n.push(t.name)}),n.length>0)for(let e of n)s.File.insertElement(e);l.focusOpenerAndClose()}}}getItems(){return n("#typo3-filelist").find(".typo3-bulk-item")}}return new s})); \ No newline at end of file +define(["require","exports","jquery","TYPO3/CMS/Backend/Utility/MessageUtility","./ElementBrowser","nprogress","TYPO3/CMS/Backend/LegacyTree","TYPO3/CMS/Core/Event/RegularEvent"],(function(e,t,n,i,l,s,r,c){"use strict";var o=TYPO3.Icons;class a{constructor(){r.noop(),a.File=new d,a.Selector=new g,n(()=>{a.elements=n("body").data("elements"),n("[data-close]").on("click",e=>{e.preventDefault(),a.File.insertElement("file_"+n(e.currentTarget).data("fileIndex"),1===parseInt(n(e.currentTarget).data("close"),10))}),n("#t3js-importSelection").on("click",a.Selector.handle),n("#t3js-toggleSelection").on("click",a.Selector.toggle)})}}class d{insertElement(e,t){let n=!1;if(void 0!==a.elements[e]){const i=a.elements[e];n=l.insertElement(i.table,i.uid,i.type,i.fileName,i.filePath,i.fileExt,i.fileIcon,"",t)}return n}}class g{constructor(){this.toggle=e=>{e.preventDefault();const t=this.getItems();t.length&&t.each((e,t)=>{t.checked=t.checked?null:"checked"})},this.handle=e=>{e.preventDefault();const t=this.getItems(),n=[];t.length&&(t.each((e,t)=>{t.checked&&t.name&&n.unshift(t.name)}),o.getIcon("spinner-circle",o.sizes.small,null,null,o.markupIdentifiers.inline).then(t=>{e.currentTarget.classList.add("disabled"),e.currentTarget.innerHTML=t}),this.handleSelection(n))}}getItems(){return n("#typo3-filelist").find(".typo3-bulk-item")}handleSelection(e){s.configure({parent:"#typo3-filelist",showSpinner:!1}),s.start();const t=1/e.length;this.handleNext(e),new c("message",n=>{if(!i.MessageUtility.verifyOrigin(n.origin))throw"Denied message sent by "+n.origin;"typo3:foreignRelation:inserted"===n.data.actionName&&(e.length>0?(s.inc(t),this.handleNext(e)):(s.done(),l.focusOpenerAndClose()))}).bindTo(window)}handleNext(e){if(e.length>0){const t=e.pop();a.File.insertElement(t)}}}return new a})); \ No newline at end of file diff --git a/typo3/sysext/recordlist/Resources/Public/JavaScript/ElementBrowser.js b/typo3/sysext/recordlist/Resources/Public/JavaScript/ElementBrowser.js index 70f2eb58de79..6bc5e8ae39dc 100644 --- a/typo3/sysext/recordlist/Resources/Public/JavaScript/ElementBrowser.js +++ b/typo3/sysext/recordlist/Resources/Public/JavaScript/ElementBrowser.js @@ -10,4 +10,4 @@ * * The TYPO3 project - inspiring people to share! */ -define(["require","exports","TYPO3/CMS/Backend/Utility/MessageUtility","jquery","TYPO3/CMS/Backend/Modal"],(function(e,t,r,i,n){"use strict";return new class{constructor(){this.opener=null,this.thisScriptUrl="",this.mode="",this.formFieldName="",this.fieldReference="",this.fieldReferenceSlashed="",this.rte={parameters:"",configuration:""},this.irre={objectId:0},this.focusOpenerAndClose=()=>{this.getParent()&&this.getParent().focus(),n.dismiss(),close()},i(()=>{const e=i("body").data();this.thisScriptUrl=e.thisScriptUrl,this.mode=e.mode,this.formFieldName=e.formFieldName,this.fieldReference=e.fieldReference,this.fieldReferenceSlashed=e.fieldReferenceSlashed,this.rte.parameters=e.rteParameters,this.rte.configuration=e.rteConfiguration,this.irre.objectId=e.irreObjectId})}setReferences(){return!!(this.getParent()&&this.getParent().content&&this.getParent().content.document.editform&&this.getParent().content.document.editform[this.formFieldName])&&(this.targetDoc=this.getParent().content.document,this.elRef=this.targetDoc.editform[this.formFieldName],!0)}executeFunctionByName(e,t,...r){const i=e.split("."),n=i.pop();for(let e of i)t=t[e];return t[n].apply(t,r)}getParent(){return null===this.opener&&(void 0!==window.parent&&void 0!==window.parent.document.list_frame&&null!==window.parent.document.list_frame.parent.document.querySelector(".t3js-modal-iframe")?this.opener=window.parent.document.list_frame:void 0!==window.parent&&void 0!==window.parent.frames.list_frame&&null!==window.parent.frames.list_frame.parent.document.querySelector(".t3js-modal-iframe")?this.opener=window.parent.frames.list_frame:void 0!==window.frames&&void 0!==window.frames.frameElement&&null!==window.frames.frameElement&&window.frames.frameElement.classList.contains("t3js-modal-iframe")?this.opener=window.frames.frameElement.contentWindow.parent:window.opener&&(this.opener=window.opener)),this.opener}insertElement(e,t,i,n,s,o,a,d,l){if(this.irre.objectId){if(this.getParent()){const i={actionName:"typo3:foreignRelation:inserted",objectGroup:this.irre.objectId,table:e,uid:t};r.MessageUtility.send(i,this.getParent())}else alert("Error - reference to main window is not set properly!"),this.focusOpenerAndClose();return l&&this.focusOpenerAndClose(),!0}return!this.fieldReference||this.rte.parameters||this.rte.configuration||this.addElement(n,e+"_"+t,s,l),!1}addElement(e,t,i,n){if(this.getParent()){this.getParent().setFormValueFromBrowseWin&&(console.warn("setFormValueFromBrowseWin has been marked as deprecated. Listen to message events instead."),this.getParent().setFormValueFromBrowseWin(this.fieldReference,i||t,e));const s={actionName:"typo3:elementBrowser:elementAdded",fieldName:this.fieldReference,value:i||t,label:e};r.MessageUtility.send(s,this.getParent()),n&&this.focusOpenerAndClose()}else alert("Error - reference to main window is not set properly!"),this.focusOpenerAndClose()}}})); \ No newline at end of file +define(["require","exports","TYPO3/CMS/Backend/Utility/MessageUtility","jquery","TYPO3/CMS/Backend/Modal"],(function(e,t,r,i,n){"use strict";return new class{constructor(){this.opener=null,this.thisScriptUrl="",this.mode="",this.formFieldName="",this.fieldReference="",this.fieldReferenceSlashed="",this.rte={parameters:"",configuration:""},this.irre={objectId:0},this.focusOpenerAndClose=()=>{this.getParent()&&this.getParent().focus(),n.dismiss(),close()},i(()=>{const e=i("body").data();this.thisScriptUrl=e.thisScriptUrl,this.mode=e.mode,this.formFieldName=e.formFieldName,this.fieldReference=e.fieldReference,this.fieldReferenceSlashed=e.fieldReferenceSlashed,this.rte.parameters=e.rteParameters,this.rte.configuration=e.rteConfiguration,this.irre.objectId=e.irreObjectId})}setReferences(){return!!(this.getParent()&&this.getParent().content&&this.getParent().content.document.editform&&this.getParent().content.document.editform[this.formFieldName])&&(this.targetDoc=this.getParent().content.document,this.elRef=this.targetDoc.editform[this.formFieldName],!0)}executeFunctionByName(e,t,...r){const i=e.split("."),n=i.pop();for(let e of i)t=t[e];return t[n].apply(t,r)}getParent(){return null===this.opener&&(void 0!==window.parent&&void 0!==window.parent.document.list_frame&&null!==window.parent.document.list_frame.parent.document.querySelector(".t3js-modal-iframe")?this.opener=window.parent.document.list_frame:void 0!==window.parent&&void 0!==window.parent.frames.list_frame&&null!==window.parent.frames.list_frame.parent.document.querySelector(".t3js-modal-iframe")?this.opener=window.parent.frames.list_frame:void 0!==window.frames&&void 0!==window.frames.frameElement&&null!==window.frames.frameElement&&window.frames.frameElement.classList.contains("t3js-modal-iframe")?this.opener=window.frames.frameElement.contentWindow.parent:window.opener&&(this.opener=window.opener)),this.opener}insertElement(e,t,i,n,s,o,a,d,l){if(this.irre.objectId){if(this.getParent()){const i={actionName:"typo3:foreignRelation:insert",objectGroup:this.irre.objectId,table:e,uid:t};r.MessageUtility.send(i,this.getParent())}else alert("Error - reference to main window is not set properly!"),this.focusOpenerAndClose();return l&&this.focusOpenerAndClose(),!0}return!this.fieldReference||this.rte.parameters||this.rte.configuration||this.addElement(n,e+"_"+t,s,l),!1}addElement(e,t,i,n){if(this.getParent()){this.getParent().setFormValueFromBrowseWin&&(console.warn("setFormValueFromBrowseWin has been marked as deprecated. Listen to message events instead."),this.getParent().setFormValueFromBrowseWin(this.fieldReference,i||t,e));const s={actionName:"typo3:elementBrowser:elementAdded",fieldName:this.fieldReference,value:i||t,label:e};r.MessageUtility.send(s,this.getParent()),n&&this.focusOpenerAndClose()}else alert("Error - reference to main window is not set properly!"),this.focusOpenerAndClose()}}})); \ No newline at end of file diff --git a/typo3/sysext/setup/Classes/Controller/SetupModuleController.php b/typo3/sysext/setup/Classes/Controller/SetupModuleController.php index 1bcf928172aa..46bcf8ed7ba3 100644 --- a/typo3/sysext/setup/Classes/Controller/SetupModuleController.php +++ b/typo3/sysext/setup/Classes/Controller/SetupModuleController.php @@ -933,7 +933,7 @@ class SetupModuleController if (!MessageUtility.MessageUtility.verifyOrigin(e.origin)) { throw \'Denied message sent by \' + e.origin; } - if (e.data.actionName === \'typo3:foreignRelation:inserted\') { + if (e.data.actionName === \'typo3:foreignRelation:insert\') { if (typeof e.data.objectGroup === \'undefined\') { throw \'No object group defined for message\'; } -- GitLab