diff --git a/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/DragUploader.ts b/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/DragUploader.ts index bd73b7c5602ea98a6aadaacfad70953fbdf0a106..6e861029255d274417479dc8bc73f0bceb5cdc8a 100644 --- a/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/DragUploader.ts +++ b/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/DragUploader.ts @@ -713,6 +713,7 @@ class DragUploader { */ public static addFileToIrre(irre_object: number, file: UploadedFile): void { const message = { + actionName: 'typo3:foreignRelation:inserted', 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 1c312b7f970a4a425335b3fce33434d8ec495c14..94c43bba6e0d2ecfd7cb37149f6cb927ee29f492 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:elementBrowser:elementInserted') { + if (e.data.actionName === 'typo3:foreignRelation:inserted') { if (typeof e.data.objectGroup === 'undefined') { throw 'No object group defined for message'; } @@ -326,6 +326,8 @@ class InlineControlContainer { } this.importRecord([e.data.objectGroup, e.data.uid]); + } else { + console.warn(`Unhandled action "${e.data.actionName}"`); } } diff --git a/Build/Sources/TypeScript/recordlist/Resources/Public/TypeScript/ElementBrowser.ts b/Build/Sources/TypeScript/recordlist/Resources/Public/TypeScript/ElementBrowser.ts index 342be6cdacfac314e457ab7f5de97cd483e90607..f4d81dd1a8a04402d4c9acfd89d153dd9ae55bd5 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:elementBrowser:elementInserted', + actionName: 'typo3:foreignRelation:inserted', 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 a0c71cbb49601b343d4bdd830b80a2e2f29c0e6b..06d868e84a9881486dc82b82fcd0a78505d8b3ac 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","./Enum/Severity","jquery","moment","nprogress","./Modal","./Notification","./Utility/MessageUtility"],(function(e,t,i,s,a,r,o,n,l){"use strict";var d;Object.defineProperty(t,"__esModule",{value:!0}),function(e){e.OVERRIDE="replace",e.RENAME="rename",e.SKIP="cancel",e.USE_EXISTING="useExisting"}(d||(d={}));class p{constructor(e){this.askForOverride=[],this.percentagePerFile=1,this.dragFileIntoDocument=e=>(e.stopPropagation(),e.preventDefault(),s(e.currentTarget).addClass("drop-in-progress"),this.showDropzone(),!1),this.dragAborted=e=>(e.stopPropagation(),e.preventDefault(),s(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=s("body"),this.$element=s(e);const t=void 0!==this.$element.data("dropzoneTrigger");this.$trigger=s(this.$element.data("dropzoneTrigger")),this.defaultAction=this.$element.data("defaultAction")||d.SKIP,this.$dropzone=s("<div />").addClass("dropzone").hide(),this.irreObjectUid=this.$element.data("fileIrreObject");const i=this.$element.data("dropzoneTarget");this.irreObjectUid&&0!==this.$element.nextAll(i).length?(this.dropZoneInsertBefore=!0,this.$dropzone.insertBefore(i)):(this.dropZoneInsertBefore=!1,this.$dropzone.insertAfter(i)),this.$dropzoneMask=s("<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=s(this.$element.data("progress-container")),this.fileListColumnCount=s("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()}),s("<span />").addClass("dropzone-close").click(this.hideDropzone).appendTo(this.$dropzone),0===this.$fileList.length&&(this.$fileList=s("<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()}hideDropzone(e){e.stopPropagation(),e.preventDefault(),this.$dropzone.hide()}processFiles(e){this.queueLength=e.length,this.$fileList.is(":visible")||this.$fileList.show(),r.start(),this.percentagePerFile=1/e.length;const t=[];s.each(e,(e,i)=>{t[parseInt(e,10)]=s.ajax({url:TYPO3.settings.ajaxUrls.file_exists,data:{fileName:i.name,fileTarget:this.target},cache:!1,success:e=>{void 0!==e.uid?(this.askForOverride.push({original:e,uploaded:i,action:this.irreObjectUid?d.USE_EXISTING:d.SKIP}),r.inc(this.percentagePerFile)):new h(this,i,d.SKIP)}})}),s.when.apply(s,t).done(()=>{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&&s.ajax({url:TYPO3.settings.ajaxUrls.flashmessages_render,cache:!1,success:e=>{s.each(e,(e,t)=>{n.showMessage(t.title,t.message,t.severity)})}}))}drawOverrideModal(){const e=Object.keys(this.askForOverride).length;if(0===e)return;const t=s("<div/>").append(s("<p/>").text(TYPO3.lang["file_upload.existingfiles.description"]),s("<table/>",{class:"table"}).append(s("<thead/>").append(s("<tr />").append(s("<th/>"),s("<th/>").text(TYPO3.lang["file_upload.header.originalFile"]),s("<th/>").text(TYPO3.lang["file_upload.header.uploadedFile"]),s("<th/>").text(TYPO3.lang["file_upload.header.action"])))));for(let i=0;i<e;++i){const e=s("<tr />").append(s("<td />").append(""!==this.askForOverride[i].original.thumbUrl?s("<img />",{src:this.askForOverride[i].original.thumbUrl,height:40}):s(this.askForOverride[i].original.icon)),s("<td />").html(this.askForOverride[i].original.name+" ("+g.fileSizeAsString(this.askForOverride[i].original.size)+")<br>"+a.unix(this.askForOverride[i].original.mtime).format("YYYY-MM-DD HH:mm")),s("<td />").html(this.askForOverride[i].uploaded.name+" ("+g.fileSizeAsString(this.askForOverride[i].uploaded.size)+")<br>"+a(this.askForOverride[i].uploaded.lastModified?this.askForOverride[i].uploaded.lastModified:this.askForOverride[i].uploaded.lastModifiedDate).format("YYYY-MM-DD HH:mm")),s("<td />").append(s("<select />",{class:"form-control t3js-actions","data-override":i}).append(this.irreObjectUid?s("<option/>").val(d.USE_EXISTING).text(TYPO3.lang["file_upload.actions.use_existing"]):"",s("<option />",{selected:this.defaultAction===d.SKIP}).val(d.SKIP).text(TYPO3.lang["file_upload.actions.skip"]),s("<option />",{selected:this.defaultAction===d.RENAME}).val(d.RENAME).text(TYPO3.lang["file_upload.actions.rename"]),s("<option />",{selected:this.defaultAction===d.OVERRIDE}).val(d.OVERRIDE).text(TYPO3.lang["file_upload.actions.override"]))));t.find("table").append("<tbody />").append(e)}const r=o.confirm(TYPO3.lang["file_upload.existingfiles.title"],t,i.SeverityEnum.warning,[{text:s(this).data("button-close-text")||TYPO3.lang["file_upload.button.cancel"]||"Cancel",active:!0,btnClass:"btn-default",name:"cancel"},{text:s(this).data("button-ok-text")||TYPO3.lang["file_upload.button.continue"]||"Continue with selected actions",btnClass:"btn-warning",name:"continue"}],["modal-inner-scroll"]);r.find(".modal-dialog").addClass("modal-lg"),r.find(".modal-footer").prepend(s("<span/>").addClass("form-inline").append(s("<label/>").text(TYPO3.lang["file_upload.actions.all.label"]),s("<select/>",{class:"form-control t3js-actions-all"}).append(s("<option/>").val("").text(TYPO3.lang["file_upload.actions.all.empty"]),this.irreObjectUid?s("<option/>").val(d.USE_EXISTING).text(TYPO3.lang["file_upload.actions.all.use_existing"]):"",s("<option/>",{selected:this.defaultAction===d.SKIP}).val(d.SKIP).text(TYPO3.lang["file_upload.actions.all.skip"]),s("<option/>",{selected:this.defaultAction===d.RENAME}).val(d.RENAME).text(TYPO3.lang["file_upload.actions.all.rename"]),s("<option/>",{selected:this.defaultAction===d.OVERRIDE}).val(d.OVERRIDE).text(TYPO3.lang["file_upload.actions.all.override"]))));const n=this;r.on("change",".t3js-actions-all",(function(){const e=s(this).val();""!==e?r.find(".t3js-actions").each((t,i)=>{const a=s(i),r=parseInt(a.data("override"),10);a.val(e).prop("disabled","disabled"),n.askForOverride[r].action=a.val()}):r.find(".t3js-actions").removeProp("disabled")})).on("change",".t3js-actions",(function(){const e=s(this),t=parseInt(e.data("override"),10);n.askForOverride[t].action=e.val()})).on("button.clicked",(function(e){"cancel"===e.target.name?(n.askForOverride=[],o.dismiss()):"continue"===e.target.name&&(s.each(n.askForOverride,(e,t)=>{t.action===d.USE_EXISTING?g.addFileToIrre(n.irreObjectUid,t.original):t.action!==d.SKIP&&new h(n,t.uploaded,t.action)}),n.askForOverride=[],o.dismiss())})).on("hidden.bs.modal",()=>{this.askForOverride=[]})}}class h{constructor(e,t,i){if(this.dragUploader=e,this.file=t,this.override=i,this.$row=s("<tr />").addClass("upload-queue-item uploading"),this.$iconCol=s("<td />").addClass("col-icon").appendTo(this.$row),this.$fileName=s("<td />").text(t.name).appendTo(this.$row),this.$progress=s("<td />").attr("colspan",this.dragUploader.fileListColumnCount-2).appendTo(this.$row),this.$progressContainer=s("<div />").addClass("upload-queue-progress").appendTo(this.$progress),this.$progressBar=s("<div />").addClass("upload-queue-progress-bar").appendTo(this.$progressContainer),this.$progressPercentage=s("<span />").addClass("upload-queue-progress-percentage").appendTo(this.$progressContainer),this.$progressMessage=s("<span />").addClass("upload-queue-progress-message").appendTo(this.$progressContainer),0===s("tbody tr.upload-queue-item",this.dragUploader.$fileList).length?(this.$row.prependTo(s("tbody",this.dragUploader.$fileList)),this.$row.addClass("last")):this.$row.insertBefore(s("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,g.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("- "+g.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=s.extend(!0,{},s.ajaxSettings,{url:TYPO3.settings.ajaxUrls.file_process,contentType:!1,processData:!1,data:e,cache:!1,type:"POST",success:e=>this.uploadSuccess(e),error:e=>this.uploadError(e)});t.xhr=()=>{const e=s.ajaxSettings.xhr();return e.upload.addEventListener("progress",e=>this.updateProgress(e)),e},this.upload=s.ajax(t)}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=s(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?(g.addFileToIrre(this.dragUploader.irreObjectUid,e.upload[0]),setTimeout(()=>{this.$row.remove(),0===s("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++)s("<td />").text("").appendTo(this.$row);s("<td />").text(e.extension.toUpperCase()).appendTo(this.$row),s("<td />").text(e.date).appendTo(this.$row),s("<td />").text(g.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>"),s("<td />").html(t).appendTo(this.$row),s("<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!==s.inArray(e.toLowerCase(),t)}}class g{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={objectGroup:e,table:"sys_file",uid:t.uid};l.MessageUtility.send(i)}static init(){const e=this.options;s.fn.extend({dragUploader:function(e){return this.each((t,i)=>{const a=s(i);let r=a.data("DragUploaderPlugin");r||a.data("DragUploaderPlugin",r=new p(i)),"string"==typeof e&&r[e]()})}}),s(()=>{s(".t3js-drag-uploader").dragUploader(e)})}}t.initialize=function(){g.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"]&&s.each(TYPO3.settings.RequireJS.PostInitializationModules["TYPO3/CMS/Backend/DragUploader"],(t,i)=>{e([i])})},t.initialize()})); \ No newline at end of file +define(["require","exports","./Enum/Severity","jquery","moment","nprogress","./Modal","./Notification","./Utility/MessageUtility"],(function(e,t,i,s,a,r,o,n,l){"use strict";var d;Object.defineProperty(t,"__esModule",{value:!0}),function(e){e.OVERRIDE="replace",e.RENAME="rename",e.SKIP="cancel",e.USE_EXISTING="useExisting"}(d||(d={}));class p{constructor(e){this.askForOverride=[],this.percentagePerFile=1,this.dragFileIntoDocument=e=>(e.stopPropagation(),e.preventDefault(),s(e.currentTarget).addClass("drop-in-progress"),this.showDropzone(),!1),this.dragAborted=e=>(e.stopPropagation(),e.preventDefault(),s(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=s("body"),this.$element=s(e);const t=void 0!==this.$element.data("dropzoneTrigger");this.$trigger=s(this.$element.data("dropzoneTrigger")),this.defaultAction=this.$element.data("defaultAction")||d.SKIP,this.$dropzone=s("<div />").addClass("dropzone").hide(),this.irreObjectUid=this.$element.data("fileIrreObject");const i=this.$element.data("dropzoneTarget");this.irreObjectUid&&0!==this.$element.nextAll(i).length?(this.dropZoneInsertBefore=!0,this.$dropzone.insertBefore(i)):(this.dropZoneInsertBefore=!1,this.$dropzone.insertAfter(i)),this.$dropzoneMask=s("<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=s(this.$element.data("progress-container")),this.fileListColumnCount=s("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()}),s("<span />").addClass("dropzone-close").click(this.hideDropzone).appendTo(this.$dropzone),0===this.$fileList.length&&(this.$fileList=s("<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()}hideDropzone(e){e.stopPropagation(),e.preventDefault(),this.$dropzone.hide()}processFiles(e){this.queueLength=e.length,this.$fileList.is(":visible")||this.$fileList.show(),r.start(),this.percentagePerFile=1/e.length;const t=[];s.each(e,(e,i)=>{t[parseInt(e,10)]=s.ajax({url:TYPO3.settings.ajaxUrls.file_exists,data:{fileName:i.name,fileTarget:this.target},cache:!1,success:e=>{void 0!==e.uid?(this.askForOverride.push({original:e,uploaded:i,action:this.irreObjectUid?d.USE_EXISTING:d.SKIP}),r.inc(this.percentagePerFile)):new h(this,i,d.SKIP)}})}),s.when.apply(s,t).done(()=>{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&&s.ajax({url:TYPO3.settings.ajaxUrls.flashmessages_render,cache:!1,success:e=>{s.each(e,(e,t)=>{n.showMessage(t.title,t.message,t.severity)})}}))}drawOverrideModal(){const e=Object.keys(this.askForOverride).length;if(0===e)return;const t=s("<div/>").append(s("<p/>").text(TYPO3.lang["file_upload.existingfiles.description"]),s("<table/>",{class:"table"}).append(s("<thead/>").append(s("<tr />").append(s("<th/>"),s("<th/>").text(TYPO3.lang["file_upload.header.originalFile"]),s("<th/>").text(TYPO3.lang["file_upload.header.uploadedFile"]),s("<th/>").text(TYPO3.lang["file_upload.header.action"])))));for(let i=0;i<e;++i){const e=s("<tr />").append(s("<td />").append(""!==this.askForOverride[i].original.thumbUrl?s("<img />",{src:this.askForOverride[i].original.thumbUrl,height:40}):s(this.askForOverride[i].original.icon)),s("<td />").html(this.askForOverride[i].original.name+" ("+g.fileSizeAsString(this.askForOverride[i].original.size)+")<br>"+a.unix(this.askForOverride[i].original.mtime).format("YYYY-MM-DD HH:mm")),s("<td />").html(this.askForOverride[i].uploaded.name+" ("+g.fileSizeAsString(this.askForOverride[i].uploaded.size)+")<br>"+a(this.askForOverride[i].uploaded.lastModified?this.askForOverride[i].uploaded.lastModified:this.askForOverride[i].uploaded.lastModifiedDate).format("YYYY-MM-DD HH:mm")),s("<td />").append(s("<select />",{class:"form-control t3js-actions","data-override":i}).append(this.irreObjectUid?s("<option/>").val(d.USE_EXISTING).text(TYPO3.lang["file_upload.actions.use_existing"]):"",s("<option />",{selected:this.defaultAction===d.SKIP}).val(d.SKIP).text(TYPO3.lang["file_upload.actions.skip"]),s("<option />",{selected:this.defaultAction===d.RENAME}).val(d.RENAME).text(TYPO3.lang["file_upload.actions.rename"]),s("<option />",{selected:this.defaultAction===d.OVERRIDE}).val(d.OVERRIDE).text(TYPO3.lang["file_upload.actions.override"]))));t.find("table").append("<tbody />").append(e)}const r=o.confirm(TYPO3.lang["file_upload.existingfiles.title"],t,i.SeverityEnum.warning,[{text:s(this).data("button-close-text")||TYPO3.lang["file_upload.button.cancel"]||"Cancel",active:!0,btnClass:"btn-default",name:"cancel"},{text:s(this).data("button-ok-text")||TYPO3.lang["file_upload.button.continue"]||"Continue with selected actions",btnClass:"btn-warning",name:"continue"}],["modal-inner-scroll"]);r.find(".modal-dialog").addClass("modal-lg"),r.find(".modal-footer").prepend(s("<span/>").addClass("form-inline").append(s("<label/>").text(TYPO3.lang["file_upload.actions.all.label"]),s("<select/>",{class:"form-control t3js-actions-all"}).append(s("<option/>").val("").text(TYPO3.lang["file_upload.actions.all.empty"]),this.irreObjectUid?s("<option/>").val(d.USE_EXISTING).text(TYPO3.lang["file_upload.actions.all.use_existing"]):"",s("<option/>",{selected:this.defaultAction===d.SKIP}).val(d.SKIP).text(TYPO3.lang["file_upload.actions.all.skip"]),s("<option/>",{selected:this.defaultAction===d.RENAME}).val(d.RENAME).text(TYPO3.lang["file_upload.actions.all.rename"]),s("<option/>",{selected:this.defaultAction===d.OVERRIDE}).val(d.OVERRIDE).text(TYPO3.lang["file_upload.actions.all.override"]))));const n=this;r.on("change",".t3js-actions-all",(function(){const e=s(this).val();""!==e?r.find(".t3js-actions").each((t,i)=>{const a=s(i),r=parseInt(a.data("override"),10);a.val(e).prop("disabled","disabled"),n.askForOverride[r].action=a.val()}):r.find(".t3js-actions").removeProp("disabled")})).on("change",".t3js-actions",(function(){const e=s(this),t=parseInt(e.data("override"),10);n.askForOverride[t].action=e.val()})).on("button.clicked",(function(e){"cancel"===e.target.name?(n.askForOverride=[],o.dismiss()):"continue"===e.target.name&&(s.each(n.askForOverride,(e,t)=>{t.action===d.USE_EXISTING?g.addFileToIrre(n.irreObjectUid,t.original):t.action!==d.SKIP&&new h(n,t.uploaded,t.action)}),n.askForOverride=[],o.dismiss())})).on("hidden.bs.modal",()=>{this.askForOverride=[]})}}class h{constructor(e,t,i){if(this.dragUploader=e,this.file=t,this.override=i,this.$row=s("<tr />").addClass("upload-queue-item uploading"),this.$iconCol=s("<td />").addClass("col-icon").appendTo(this.$row),this.$fileName=s("<td />").text(t.name).appendTo(this.$row),this.$progress=s("<td />").attr("colspan",this.dragUploader.fileListColumnCount-2).appendTo(this.$row),this.$progressContainer=s("<div />").addClass("upload-queue-progress").appendTo(this.$progress),this.$progressBar=s("<div />").addClass("upload-queue-progress-bar").appendTo(this.$progressContainer),this.$progressPercentage=s("<span />").addClass("upload-queue-progress-percentage").appendTo(this.$progressContainer),this.$progressMessage=s("<span />").addClass("upload-queue-progress-message").appendTo(this.$progressContainer),0===s("tbody tr.upload-queue-item",this.dragUploader.$fileList).length?(this.$row.prependTo(s("tbody",this.dragUploader.$fileList)),this.$row.addClass("last")):this.$row.insertBefore(s("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,g.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("- "+g.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=s.extend(!0,{},s.ajaxSettings,{url:TYPO3.settings.ajaxUrls.file_process,contentType:!1,processData:!1,data:e,cache:!1,type:"POST",success:e=>this.uploadSuccess(e),error:e=>this.uploadError(e)});t.xhr=()=>{const e=s.ajaxSettings.xhr();return e.upload.addEventListener("progress",e=>this.updateProgress(e)),e},this.upload=s.ajax(t)}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=s(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?(g.addFileToIrre(this.dragUploader.irreObjectUid,e.upload[0]),setTimeout(()=>{this.$row.remove(),0===s("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++)s("<td />").text("").appendTo(this.$row);s("<td />").text(e.extension.toUpperCase()).appendTo(this.$row),s("<td />").text(e.date).appendTo(this.$row),s("<td />").text(g.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>"),s("<td />").html(t).appendTo(this.$row),s("<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!==s.inArray(e.toLowerCase(),t)}}class g{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};l.MessageUtility.send(i)}static init(){const e=this.options;s.fn.extend({dragUploader:function(e){return this.each((t,i)=>{const a=s(i);let r=a.data("DragUploaderPlugin");r||a.data("DragUploaderPlugin",r=new p(i)),"string"==typeof e&&r[e]()})}}),s(()=>{s(".t3js-drag-uploader").dragUploader(e)})}}t.initialize=function(){g.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"]&&s.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 158bb312d1a27c41a2f5f708c1e7cf9662713f1c..66a7736a46a929d018a9d997410ba0998f7c4249 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:elementBrowser:elementInserted"===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])}},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.parentElement.dataset.objectId)})).delegateTo(this.container,f.toggleSelector)}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: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.parentElement.dataset.objectId)})).delegateTo(this.container,f.toggleSelector)}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 diff --git a/typo3/sysext/recordlist/Resources/Public/JavaScript/ElementBrowser.js b/typo3/sysext/recordlist/Resources/Public/JavaScript/ElementBrowser.js index 11658e7a97b4e81dd735242126f0acc3c0f18d76..70f2eb58de795e4b5a8150b7f4afe222067fb4c9 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:elementBrowser:elementInserted",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: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 diff --git a/typo3/sysext/setup/Classes/Controller/SetupModuleController.php b/typo3/sysext/setup/Classes/Controller/SetupModuleController.php index a6179152df022d9dc8364b11d280b59be621a848..16a1e580ac980f4a9e7e8434c5c83392baea3c00 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:elementBrowser:elementInserted\') { + if (e.data.actionName === \'typo3:foreignRelation:inserted\') { if (typeof e.data.objectGroup === \'undefined\') { throw \'No object group defined for message\'; }