From e0d3cfbe48ddfb83f968a514a421f66d06224b2d Mon Sep 17 00:00:00 2001 From: Andreas Fernandez <a.fernandez@scripting-base.de> Date: Thu, 24 Nov 2022 14:22:27 +0100 Subject: [PATCH] [BUGFIX] Make backdrop for EXT:recycler confirmations static The confirmation in modal windows of EXT:recycler may run long running tasks, depending on the database structure and amount of data. It was possible to close the modal by clicking the backdrop, while the actions still run which may lead to undefined behavior when the recycler is used. The backdrop is now made static. Resolves: #99181 Releases: main Change-Id: I60cae362382bf249d4b6ac564f5134a2c782ef9e Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/76806 Tested-by: core-ci <typo3@b13.com> Reviewed-by: Josef Glatz <josefglatz@gmail.com> Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de> Reviewed-by: Benni Mack <benni@typo3.org> Tested-by: Benni Mack <benni@typo3.org> Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de> Tested-by: Josef Glatz <josefglatz@gmail.com> Reviewed-by: Oliver Bartsch <bo@cedev.de> Tested-by: Oliver Bartsch <bo@cedev.de> --- Build/Sources/TypeScript/recycler/recycler.ts | 80 +++++++++++-------- .../Resources/Public/JavaScript/recycler.js | 2 +- 2 files changed, 47 insertions(+), 35 deletions(-) diff --git a/Build/Sources/TypeScript/recycler/recycler.ts b/Build/Sources/TypeScript/recycler/recycler.ts index 14beb38db9bb..dfc1bdd2e5b3 100644 --- a/Build/Sources/TypeScript/recycler/recycler.ts +++ b/Build/Sources/TypeScript/recycler/recycler.ts @@ -18,7 +18,7 @@ import '@typo3/backend/element/icon-element'; import DeferredAction from '@typo3/backend/action-button/deferred-action'; import Modal from '@typo3/backend/modal'; import Notification from '@typo3/backend/notification'; -import Severity from '@typo3/backend/severity'; +import {SeverityEnum} from '@typo3/backend/enum/severity'; import RegularEvent from '@typo3/core/event/regular-event'; enum RecyclerIdentifiers { @@ -337,21 +337,27 @@ class Recycler { message = this.createMessage(message, [recordTitle, '[' + records[0] + ']']); } - Modal.confirm(TYPO3.lang['modal.delete.header'], message, Severity.error, [ - { - text: TYPO3.lang['button.cancel'], - btnClass: 'btn-default', - trigger: function(): void { - Modal.dismiss(); + Modal.advanced({ + title: TYPO3.lang['modal.delete.header'], + content: message, + severity: SeverityEnum.error, + staticBackdrop: true, + buttons: [ + { + text: TYPO3.lang['button.cancel'], + btnClass: 'btn-default', + trigger: function(): void { + Modal.dismiss(); + }, + }, { + text: TYPO3.lang['button.delete'], + btnClass: 'btn-danger', + action: new DeferredAction(() => { + Promise.resolve(this.callAjaxAction('delete', records, isMassDelete)); + }), }, - }, { - text: TYPO3.lang['button.delete'], - btnClass: 'btn-danger', - action: new DeferredAction(() => { - Promise.resolve(this.callAjaxAction('delete', records, isMassDelete)); - }), - }, - ]); + ] + }); } private undoRecord = (e: Event): void => { @@ -400,26 +406,32 @@ class Recycler { $message = $('<p />').text(messageText); } - Modal.confirm(TYPO3.lang['modal.undo.header'], $message, Severity.ok, [ - { - text: TYPO3.lang['button.cancel'], - btnClass: 'btn-default', - trigger: function(): void { - Modal.dismiss(); + Modal.advanced({ + title: TYPO3.lang['modal.undo.header'], + content: $message, + severity: SeverityEnum.ok, + staticBackdrop: true, + buttons: [ + { + text: TYPO3.lang['button.cancel'], + btnClass: 'btn-default', + trigger: function(): void { + Modal.dismiss(); + }, + }, { + text: TYPO3.lang['button.undo'], + btnClass: 'btn-success', + action: new DeferredAction(() => { + Promise.resolve(this.callAjaxAction( + 'undo', + typeof records === 'object' ? records : [records], + isMassUndo, + $message.find('#undo-recursive').prop('checked'), + )); + }), }, - }, { - text: TYPO3.lang['button.undo'], - btnClass: 'btn-success', - action: new DeferredAction(() => { - Promise.resolve(this.callAjaxAction( - 'undo', - typeof records === 'object' ? records : [records], - isMassUndo, - $message.find('#undo-recursive').prop('checked'), - )); - }), - }, - ]); + ] + }); } /** diff --git a/typo3/sysext/recycler/Resources/Public/JavaScript/recycler.js b/typo3/sysext/recycler/Resources/Public/JavaScript/recycler.js index 3acc6c1864fa..7f98bf234288 100644 --- a/typo3/sysext/recycler/Resources/Public/JavaScript/recycler.js +++ b/typo3/sysext/recycler/Resources/Public/JavaScript/recycler.js @@ -10,4 +10,4 @@ * * The TYPO3 project - inspiring people to share! */ -import $ from"jquery";import NProgress from"nprogress";import"@typo3/backend/input/clearable.js";import"@typo3/backend/element/icon-element.js";import DeferredAction from"@typo3/backend/action-button/deferred-action.js";import Modal from"@typo3/backend/modal.js";import Notification from"@typo3/backend/notification.js";import Severity from"@typo3/backend/severity.js";import RegularEvent from"@typo3/core/event/regular-event.js";var RecyclerIdentifiers;!function(e){e.searchForm="#recycler-form",e.searchText="#recycler-form [name=search-text]",e.searchSubmitBtn="#recycler-form button[type=submit]",e.depthSelector="#recycler-form [name=depth]",e.tableSelector="#recycler-form [name=pages]",e.recyclerTable="#itemsInRecycler",e.paginator="#recycler-index nav",e.reloadAction="a[data-action=reload]",e.undo="a[data-action=undo]",e.delete="a[data-action=delete]",e.massUndo="button[data-multi-record-selection-action=massundo]",e.massDelete="button[data-multi-record-selection-action=massdelete]"}(RecyclerIdentifiers||(RecyclerIdentifiers={}));class Recycler{constructor(){this.elements={},this.paging={currentPage:1,totalPages:1,totalItems:0,itemsPerPage:TYPO3.settings.Recycler.pagingSize},this.markedRecordsForMassAction=[],this.handleCheckboxStateChanged=e=>{const t=$(e.target),a=t.parents("tr"),s=a.data("table")+":"+a.data("uid");if(t.prop("checked"))this.markedRecordsForMassAction.push(s);else{const e=this.markedRecordsForMassAction.indexOf(s);e>-1&&this.markedRecordsForMassAction.splice(e,1)}this.markedRecordsForMassAction.length>0?(this.elements.$massUndo.find("span.text").text(this.createMessage(TYPO3.lang["button.undoselected"],[this.markedRecordsForMassAction.length])),this.elements.$massDelete.find("span.text").text(this.createMessage(TYPO3.lang["button.deleteselected"],[this.markedRecordsForMassAction.length]))):this.resetMassActionButtons()},this.deleteRecord=e=>{if(TYPO3.settings.Recycler.deleteDisable)return;const t=$(e.target).parents("tr"),a="TBODY"!==t.parent().prop("tagName");let s,n;if(a)s=this.markedRecordsForMassAction,n=TYPO3.lang["modal.massdelete.text"];else{const e=t.data("uid"),a=t.data("table"),i=t.data("recordtitle");s=[a+":"+e],n="pages"===a?TYPO3.lang["modal.deletepage.text"]:TYPO3.lang["modal.deletecontent.text"],n=this.createMessage(n,[i,"["+s[0]+"]"])}Modal.confirm(TYPO3.lang["modal.delete.header"],n,Severity.error,[{text:TYPO3.lang["button.cancel"],btnClass:"btn-default",trigger:function(){Modal.dismiss()}},{text:TYPO3.lang["button.delete"],btnClass:"btn-danger",action:new DeferredAction((()=>{Promise.resolve(this.callAjaxAction("delete",s,a))}))}])},this.undoRecord=e=>{const t=$(e.target).parents("tr"),a="TBODY"!==t.parent().prop("tagName");let s,n,i;if(a)s=this.markedRecordsForMassAction,n=TYPO3.lang["modal.massundo.text"],i=!0;else{const e=t.data("uid"),a=t.data("table"),r=t.data("recordtitle");s=[a+":"+e],i="pages"===a,n=i?TYPO3.lang["modal.undopage.text"]:TYPO3.lang["modal.undocontent.text"],n=this.createMessage(n,[r,"["+s[0]+"]"]),i&&t.data("parentDeleted")&&(n+=TYPO3.lang["modal.undo.parentpages"])}let r=null;r=i?$("<div />").append($("<p />").text(n),$("<div />",{class:"form-check"}).append($("<input />",{type:"checkbox",id:"undo-recursive",class:"form-check-input"}),$("<label />",{class:"form-check-label",for:"undo-recursive"}).text(TYPO3.lang["modal.undo.recursive"]))):$("<p />").text(n),Modal.confirm(TYPO3.lang["modal.undo.header"],r,Severity.ok,[{text:TYPO3.lang["button.cancel"],btnClass:"btn-default",trigger:function(){Modal.dismiss()}},{text:TYPO3.lang["button.undo"],btnClass:"btn-success",action:new DeferredAction((()=>{Promise.resolve(this.callAjaxAction("undo","object"==typeof s?s:[s],a,r.find("#undo-recursive").prop("checked")))}))}])},$((()=>{this.initialize()}))}static refreshPageTree(){top.document.dispatchEvent(new CustomEvent("typo3:pagetree:refresh"))}getElements(){this.elements={$searchForm:$(RecyclerIdentifiers.searchForm),$searchTextField:$(RecyclerIdentifiers.searchText),$searchSubmitBtn:$(RecyclerIdentifiers.searchSubmitBtn),$depthSelector:$(RecyclerIdentifiers.depthSelector),$tableSelector:$(RecyclerIdentifiers.tableSelector),$recyclerTable:$(RecyclerIdentifiers.recyclerTable),$tableBody:$(RecyclerIdentifiers.recyclerTable).find("tbody"),$paginator:$(RecyclerIdentifiers.paginator),$reloadAction:$(RecyclerIdentifiers.reloadAction),$massUndo:$(RecyclerIdentifiers.massUndo),$massDelete:$(RecyclerIdentifiers.massDelete)}}registerEvents(){this.elements.$searchForm.on("submit",(e=>{e.preventDefault(),""!==this.elements.$searchTextField.val()&&this.loadDeletedElements()})),this.elements.$searchTextField.on("keyup",(e=>{""!==$(e.currentTarget).val()?this.elements.$searchSubmitBtn.removeClass("disabled"):(this.elements.$searchSubmitBtn.addClass("disabled"),this.loadDeletedElements())})),this.elements.$searchTextField.get(0).clearable({onClear:()=>{this.elements.$searchSubmitBtn.addClass("disabled"),this.loadDeletedElements()}}),this.elements.$depthSelector.on("change",(()=>{$.when(this.loadAvailableTables()).done((()=>{this.loadDeletedElements()}))})),this.elements.$tableSelector.on("change",(()=>{this.paging.currentPage=1,this.loadDeletedElements()})),new RegularEvent("click",this.undoRecord).delegateTo(document,RecyclerIdentifiers.undo),new RegularEvent("click",this.deleteRecord).delegateTo(document,RecyclerIdentifiers.delete),this.elements.$reloadAction.on("click",(e=>{e.preventDefault(),$.when(this.loadAvailableTables()).done((()=>{this.loadDeletedElements()}))})),this.elements.$paginator.on("click","[data-action]",(e=>{e.preventDefault();const t=$(e.currentTarget);let a=!1;switch(t.data("action")){case"previous":this.paging.currentPage>1&&(this.paging.currentPage--,a=!0);break;case"next":this.paging.currentPage<this.paging.totalPages&&(this.paging.currentPage++,a=!0);break;case"page":this.paging.currentPage=parseInt(t.find("span").text(),10),a=!0}a&&this.loadDeletedElements()})),TYPO3.settings.Recycler.deleteDisable?this.elements.$massDelete.remove():this.elements.$massDelete.show(),new RegularEvent("multiRecordSelection:checkbox:state:changed",this.handleCheckboxStateChanged).bindTo(document),new RegularEvent("multiRecordSelection:action:massundo",this.undoRecord).bindTo(document),new RegularEvent("multiRecordSelection:action:massdelete",this.deleteRecord).bindTo(document)}initialize(){NProgress.configure({parent:".module-loading-indicator",showSpinner:!1}),this.getElements(),this.registerEvents(),TYPO3.settings.Recycler.depthSelection>0?this.elements.$depthSelector.val(TYPO3.settings.Recycler.depthSelection).trigger("change"):$.when(this.loadAvailableTables()).done((()=>{this.loadDeletedElements()}))}resetMassActionButtons(){this.markedRecordsForMassAction=[],this.elements.$massUndo.find("span.text").text(TYPO3.lang["button.undo"]),this.elements.$massDelete.find("span.text").text(TYPO3.lang["button.delete"]),document.dispatchEvent(new CustomEvent("multiRecordSelection:actions:hide"))}loadAvailableTables(){return $.ajax({url:TYPO3.settings.ajaxUrls.recycler,dataType:"json",data:{action:"getTables",startUid:TYPO3.settings.Recycler.startUid,depth:this.elements.$depthSelector.find("option:selected").val()},beforeSend:()=>{NProgress.start(),this.elements.$tableSelector.val(""),this.paging.currentPage=1},success:e=>{const t=[];this.elements.$tableSelector.children().remove(),$.each(e,((e,a)=>{const s=a[0],n=a[1],i=(a[2]?a[2]:TYPO3.lang.label_allrecordtypes)+" ("+n+")";t.push($("<option />").val(s).text(i))})),t.length>0&&(this.elements.$tableSelector.append(t),""!==TYPO3.settings.Recycler.tableSelection&&this.elements.$tableSelector.val(TYPO3.settings.Recycler.tableSelection))},complete:()=>{NProgress.done()}})}loadDeletedElements(){return $.ajax({url:TYPO3.settings.ajaxUrls.recycler,dataType:"json",data:{action:"getDeletedRecords",depth:this.elements.$depthSelector.find("option:selected").val(),startUid:TYPO3.settings.Recycler.startUid,table:this.elements.$tableSelector.find("option:selected").val(),filterTxt:this.elements.$searchTextField.val(),start:(this.paging.currentPage-1)*this.paging.itemsPerPage,limit:this.paging.itemsPerPage},beforeSend:()=>{NProgress.start(),this.resetMassActionButtons()},success:e=>{this.elements.$tableBody.html(e.rows),this.buildPaginator(e.totalItems)},complete:()=>{NProgress.done()}})}callAjaxAction(e,t,a,s=!1){let n={records:t,action:""},i=!1;if("undo"===e)n.action="undoRecords",n.recursive=s?1:0,i=!0;else{if("delete"!==e)return;n.action="deleteRecords"}return $.ajax({url:TYPO3.settings.ajaxUrls.recycler,type:"POST",dataType:"json",data:n,beforeSend:()=>{NProgress.start()},success:e=>{e.success?Notification.success("",e.message):Notification.error("",e.message),this.paging.currentPage=1,$.when(this.loadAvailableTables()).done((()=>{this.loadDeletedElements(),a&&this.resetMassActionButtons(),i&&Recycler.refreshPageTree()}))},complete:()=>{NProgress.done()}})}createMessage(e,t){return void 0===e?"":e.replace(/\{([0-9]+)\}/g,(function(e,a){return t[a]}))}buildPaginator(e){if(0===e)return void this.elements.$paginator.contents().remove();if(this.paging.totalItems=e,this.paging.totalPages=Math.ceil(e/this.paging.itemsPerPage),1===this.paging.totalPages)return void this.elements.$paginator.contents().remove();const t=$("<ul />",{class:"pagination"}),a=[],s=$("<li />",{class:"page-item"}).append($("<button />",{class:"page-link",type:"button","data-action":"previous"}).append($("<typo3-backend-icon />",{identifier:"actions-arrow-left-alt",size:"small"}))),n=$("<li />",{class:"page-item"}).append($("<button />",{class:"page-link",type:"button","data-action":"next"}).append($("<typo3-backend-icon />",{identifier:"actions-arrow-right-alt",size:"small"})));1===this.paging.currentPage&&s.disablePagingAction(),this.paging.currentPage===this.paging.totalPages&&n.disablePagingAction();for(let e=1;e<=this.paging.totalPages;e++){const t=$("<li />",{class:"page-item"+(this.paging.currentPage===e?" active":"")});t.append($("<button />",{class:"page-link",type:"button","data-action":"page"}).append($("<span />").text(e))),a.push(t)}t.append(s,a,n),this.elements.$paginator.html(t)}}$.fn.disablePagingAction=function(){$(this).addClass("disabled").find("button").prop("disabled",!0)};export default new Recycler; \ No newline at end of file +import $ from"jquery";import NProgress from"nprogress";import"@typo3/backend/input/clearable.js";import"@typo3/backend/element/icon-element.js";import DeferredAction from"@typo3/backend/action-button/deferred-action.js";import Modal from"@typo3/backend/modal.js";import Notification from"@typo3/backend/notification.js";import{SeverityEnum}from"@typo3/backend/enum/severity.js";import RegularEvent from"@typo3/core/event/regular-event.js";var RecyclerIdentifiers;!function(e){e.searchForm="#recycler-form",e.searchText="#recycler-form [name=search-text]",e.searchSubmitBtn="#recycler-form button[type=submit]",e.depthSelector="#recycler-form [name=depth]",e.tableSelector="#recycler-form [name=pages]",e.recyclerTable="#itemsInRecycler",e.paginator="#recycler-index nav",e.reloadAction="a[data-action=reload]",e.undo="a[data-action=undo]",e.delete="a[data-action=delete]",e.massUndo="button[data-multi-record-selection-action=massundo]",e.massDelete="button[data-multi-record-selection-action=massdelete]"}(RecyclerIdentifiers||(RecyclerIdentifiers={}));class Recycler{constructor(){this.elements={},this.paging={currentPage:1,totalPages:1,totalItems:0,itemsPerPage:TYPO3.settings.Recycler.pagingSize},this.markedRecordsForMassAction=[],this.handleCheckboxStateChanged=e=>{const t=$(e.target),a=t.parents("tr"),s=a.data("table")+":"+a.data("uid");if(t.prop("checked"))this.markedRecordsForMassAction.push(s);else{const e=this.markedRecordsForMassAction.indexOf(s);e>-1&&this.markedRecordsForMassAction.splice(e,1)}this.markedRecordsForMassAction.length>0?(this.elements.$massUndo.find("span.text").text(this.createMessage(TYPO3.lang["button.undoselected"],[this.markedRecordsForMassAction.length])),this.elements.$massDelete.find("span.text").text(this.createMessage(TYPO3.lang["button.deleteselected"],[this.markedRecordsForMassAction.length]))):this.resetMassActionButtons()},this.deleteRecord=e=>{if(TYPO3.settings.Recycler.deleteDisable)return;const t=$(e.target).parents("tr"),a="TBODY"!==t.parent().prop("tagName");let s,n;if(a)s=this.markedRecordsForMassAction,n=TYPO3.lang["modal.massdelete.text"];else{const e=t.data("uid"),a=t.data("table"),i=t.data("recordtitle");s=[a+":"+e],n="pages"===a?TYPO3.lang["modal.deletepage.text"]:TYPO3.lang["modal.deletecontent.text"],n=this.createMessage(n,[i,"["+s[0]+"]"])}Modal.advanced({title:TYPO3.lang["modal.delete.header"],content:n,severity:SeverityEnum.error,staticBackdrop:!0,buttons:[{text:TYPO3.lang["button.cancel"],btnClass:"btn-default",trigger:function(){Modal.dismiss()}},{text:TYPO3.lang["button.delete"],btnClass:"btn-danger",action:new DeferredAction((()=>{Promise.resolve(this.callAjaxAction("delete",s,a))}))}]})},this.undoRecord=e=>{const t=$(e.target).parents("tr"),a="TBODY"!==t.parent().prop("tagName");let s,n,i;if(a)s=this.markedRecordsForMassAction,n=TYPO3.lang["modal.massundo.text"],i=!0;else{const e=t.data("uid"),a=t.data("table"),r=t.data("recordtitle");s=[a+":"+e],i="pages"===a,n=i?TYPO3.lang["modal.undopage.text"]:TYPO3.lang["modal.undocontent.text"],n=this.createMessage(n,[r,"["+s[0]+"]"]),i&&t.data("parentDeleted")&&(n+=TYPO3.lang["modal.undo.parentpages"])}let r=null;r=i?$("<div />").append($("<p />").text(n),$("<div />",{class:"form-check"}).append($("<input />",{type:"checkbox",id:"undo-recursive",class:"form-check-input"}),$("<label />",{class:"form-check-label",for:"undo-recursive"}).text(TYPO3.lang["modal.undo.recursive"]))):$("<p />").text(n),Modal.advanced({title:TYPO3.lang["modal.undo.header"],content:r,severity:SeverityEnum.ok,staticBackdrop:!0,buttons:[{text:TYPO3.lang["button.cancel"],btnClass:"btn-default",trigger:function(){Modal.dismiss()}},{text:TYPO3.lang["button.undo"],btnClass:"btn-success",action:new DeferredAction((()=>{Promise.resolve(this.callAjaxAction("undo","object"==typeof s?s:[s],a,r.find("#undo-recursive").prop("checked")))}))}]})},$((()=>{this.initialize()}))}static refreshPageTree(){top.document.dispatchEvent(new CustomEvent("typo3:pagetree:refresh"))}getElements(){this.elements={$searchForm:$(RecyclerIdentifiers.searchForm),$searchTextField:$(RecyclerIdentifiers.searchText),$searchSubmitBtn:$(RecyclerIdentifiers.searchSubmitBtn),$depthSelector:$(RecyclerIdentifiers.depthSelector),$tableSelector:$(RecyclerIdentifiers.tableSelector),$recyclerTable:$(RecyclerIdentifiers.recyclerTable),$tableBody:$(RecyclerIdentifiers.recyclerTable).find("tbody"),$paginator:$(RecyclerIdentifiers.paginator),$reloadAction:$(RecyclerIdentifiers.reloadAction),$massUndo:$(RecyclerIdentifiers.massUndo),$massDelete:$(RecyclerIdentifiers.massDelete)}}registerEvents(){this.elements.$searchForm.on("submit",(e=>{e.preventDefault(),""!==this.elements.$searchTextField.val()&&this.loadDeletedElements()})),this.elements.$searchTextField.on("keyup",(e=>{""!==$(e.currentTarget).val()?this.elements.$searchSubmitBtn.removeClass("disabled"):(this.elements.$searchSubmitBtn.addClass("disabled"),this.loadDeletedElements())})),this.elements.$searchTextField.get(0).clearable({onClear:()=>{this.elements.$searchSubmitBtn.addClass("disabled"),this.loadDeletedElements()}}),this.elements.$depthSelector.on("change",(()=>{$.when(this.loadAvailableTables()).done((()=>{this.loadDeletedElements()}))})),this.elements.$tableSelector.on("change",(()=>{this.paging.currentPage=1,this.loadDeletedElements()})),new RegularEvent("click",this.undoRecord).delegateTo(document,RecyclerIdentifiers.undo),new RegularEvent("click",this.deleteRecord).delegateTo(document,RecyclerIdentifiers.delete),this.elements.$reloadAction.on("click",(e=>{e.preventDefault(),$.when(this.loadAvailableTables()).done((()=>{this.loadDeletedElements()}))})),this.elements.$paginator.on("click","[data-action]",(e=>{e.preventDefault();const t=$(e.currentTarget);let a=!1;switch(t.data("action")){case"previous":this.paging.currentPage>1&&(this.paging.currentPage--,a=!0);break;case"next":this.paging.currentPage<this.paging.totalPages&&(this.paging.currentPage++,a=!0);break;case"page":this.paging.currentPage=parseInt(t.find("span").text(),10),a=!0}a&&this.loadDeletedElements()})),TYPO3.settings.Recycler.deleteDisable?this.elements.$massDelete.remove():this.elements.$massDelete.show(),new RegularEvent("multiRecordSelection:checkbox:state:changed",this.handleCheckboxStateChanged).bindTo(document),new RegularEvent("multiRecordSelection:action:massundo",this.undoRecord).bindTo(document),new RegularEvent("multiRecordSelection:action:massdelete",this.deleteRecord).bindTo(document)}initialize(){NProgress.configure({parent:".module-loading-indicator",showSpinner:!1}),this.getElements(),this.registerEvents(),TYPO3.settings.Recycler.depthSelection>0?this.elements.$depthSelector.val(TYPO3.settings.Recycler.depthSelection).trigger("change"):$.when(this.loadAvailableTables()).done((()=>{this.loadDeletedElements()}))}resetMassActionButtons(){this.markedRecordsForMassAction=[],this.elements.$massUndo.find("span.text").text(TYPO3.lang["button.undo"]),this.elements.$massDelete.find("span.text").text(TYPO3.lang["button.delete"]),document.dispatchEvent(new CustomEvent("multiRecordSelection:actions:hide"))}loadAvailableTables(){return $.ajax({url:TYPO3.settings.ajaxUrls.recycler,dataType:"json",data:{action:"getTables",startUid:TYPO3.settings.Recycler.startUid,depth:this.elements.$depthSelector.find("option:selected").val()},beforeSend:()=>{NProgress.start(),this.elements.$tableSelector.val(""),this.paging.currentPage=1},success:e=>{const t=[];this.elements.$tableSelector.children().remove(),$.each(e,((e,a)=>{const s=a[0],n=a[1],i=(a[2]?a[2]:TYPO3.lang.label_allrecordtypes)+" ("+n+")";t.push($("<option />").val(s).text(i))})),t.length>0&&(this.elements.$tableSelector.append(t),""!==TYPO3.settings.Recycler.tableSelection&&this.elements.$tableSelector.val(TYPO3.settings.Recycler.tableSelection))},complete:()=>{NProgress.done()}})}loadDeletedElements(){return $.ajax({url:TYPO3.settings.ajaxUrls.recycler,dataType:"json",data:{action:"getDeletedRecords",depth:this.elements.$depthSelector.find("option:selected").val(),startUid:TYPO3.settings.Recycler.startUid,table:this.elements.$tableSelector.find("option:selected").val(),filterTxt:this.elements.$searchTextField.val(),start:(this.paging.currentPage-1)*this.paging.itemsPerPage,limit:this.paging.itemsPerPage},beforeSend:()=>{NProgress.start(),this.resetMassActionButtons()},success:e=>{this.elements.$tableBody.html(e.rows),this.buildPaginator(e.totalItems)},complete:()=>{NProgress.done()}})}callAjaxAction(e,t,a,s=!1){let n={records:t,action:""},i=!1;if("undo"===e)n.action="undoRecords",n.recursive=s?1:0,i=!0;else{if("delete"!==e)return;n.action="deleteRecords"}return $.ajax({url:TYPO3.settings.ajaxUrls.recycler,type:"POST",dataType:"json",data:n,beforeSend:()=>{NProgress.start()},success:e=>{e.success?Notification.success("",e.message):Notification.error("",e.message),this.paging.currentPage=1,$.when(this.loadAvailableTables()).done((()=>{this.loadDeletedElements(),a&&this.resetMassActionButtons(),i&&Recycler.refreshPageTree()}))},complete:()=>{NProgress.done()}})}createMessage(e,t){return void 0===e?"":e.replace(/\{([0-9]+)\}/g,(function(e,a){return t[a]}))}buildPaginator(e){if(0===e)return void this.elements.$paginator.contents().remove();if(this.paging.totalItems=e,this.paging.totalPages=Math.ceil(e/this.paging.itemsPerPage),1===this.paging.totalPages)return void this.elements.$paginator.contents().remove();const t=$("<ul />",{class:"pagination"}),a=[],s=$("<li />",{class:"page-item"}).append($("<button />",{class:"page-link",type:"button","data-action":"previous"}).append($("<typo3-backend-icon />",{identifier:"actions-arrow-left-alt",size:"small"}))),n=$("<li />",{class:"page-item"}).append($("<button />",{class:"page-link",type:"button","data-action":"next"}).append($("<typo3-backend-icon />",{identifier:"actions-arrow-right-alt",size:"small"})));1===this.paging.currentPage&&s.disablePagingAction(),this.paging.currentPage===this.paging.totalPages&&n.disablePagingAction();for(let e=1;e<=this.paging.totalPages;e++){const t=$("<li />",{class:"page-item"+(this.paging.currentPage===e?" active":"")});t.append($("<button />",{class:"page-link",type:"button","data-action":"page"}).append($("<span />").text(e))),a.push(t)}t.append(s,a,n),this.elements.$paginator.html(t)}}$.fn.disablePagingAction=function(){$(this).addClass("disabled").find("button").prop("disabled",!0)};export default new Recycler; \ No newline at end of file -- GitLab