[BUGFIX] Use AjaxDataHandler to delete records from context menu 54/61954/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Fri, 11 Oct 2019 10:27:37 +0000 (12:27 +0200)
committerDaniel Goerz <daniel.goerz@posteo.de>
Sun, 13 Oct 2019 16:33:07 +0000 (18:33 +0200)
The AjaxDataHandler is now used to invoke record deletion. This way, any
messages are passed to the response and may get rendered as
notifications.

Resolves: #88377
Releases: master, 9.5
Change-Id: I60c05a5272fec07a42cc186b1273915e0e0521db
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61954
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Jörg Bösche <typo3@joergboesche.de>
Tested-by: Jan Stockfisch <typo3@jan-stockfisch.de>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Jörg Bösche <typo3@joergboesche.de>
Reviewed-by: Jan Stockfisch <typo3@jan-stockfisch.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Build/Sources/TypeScript/backend/Resources/Public/TypeScript/ContextMenuActions.ts
typo3/sysext/backend/Resources/Public/JavaScript/ContextMenuActions.js

index f0e1bdb..e160051 100644 (file)
@@ -13,6 +13,7 @@
 
 import {SeverityEnum} from './Enum/Severity';
 import * as $ from 'jquery';
+import AjaxDataHandler = require('./AjaxDataHandler');
 import InfoWindow = require('./InfoWindow');
 import Modal = require('./Modal');
 import ModuleMenu = require('./ModuleMenu');
@@ -226,21 +227,16 @@ class ContextMenuActions {
 
     $modal.on('button.clicked', (e: JQueryEventObject): void => {
       if (e.target.getAttribute('name') === 'delete') {
-        const targetUrl = top.TYPO3.settings.RecordCommit.moduleUrl
-          + '&cmd[' + table + '][' + uid + '][delete]=1';
-
-        $.ajax({
-          url: targetUrl,
-          success: (): void => {
-            if (table === 'pages' && Viewport.NavigationContainer.PageTree) {
-              if (uid === top.fsMod.recentIds.web) {
-                let node = Viewport.NavigationContainer.PageTree.getFirstNode();
-                Viewport.NavigationContainer.PageTree.selectNode(node);
-              }
-
-              Viewport.NavigationContainer.PageTree.refreshTree();
+        const xhr = AjaxDataHandler.process('cmd[' + table + '][' + uid + '][delete]=1');
+        xhr.done((): void => {
+          if (table === 'pages' && Viewport.NavigationContainer.PageTree) {
+            if (uid === top.fsMod.recentIds.web) {
+              let node = Viewport.NavigationContainer.PageTree.getFirstNode();
+              Viewport.NavigationContainer.PageTree.selectNode(node);
             }
-          },
+
+            Viewport.NavigationContainer.PageTree.refreshTree();
+          }
         });
       }
       Modal.dismiss();
index de7f83b..2fafa83 100644 (file)
@@ -10,4 +10,4 @@
  *
  * The TYPO3 project - inspiring people to share!
  */
-define(["require","exports","./Enum/Severity","jquery","./InfoWindow","./Modal","./ModuleMenu","./Viewport","TYPO3/CMS/Backend/Notification"],function(e,t,n,a,r,o,i,s,l){"use strict";class c{static getReturnUrl(){return encodeURIComponent(top.list_frame.document.location.pathname+top.list_frame.document.location.search)}static editRecord(e,t){let n="",r=a(this).data("pages-language-uid");r&&(n="&overrideVals[pages][sys_language_uid]="+r),s.ContentContainer.setUrl(top.TYPO3.settings.FormEngine.moduleUrl+"&edit["+e+"]["+t+"]=edit"+n+"&returnUrl="+c.getReturnUrl())}static viewRecord(){const e=a(this).data("preview-url");if(e){window.open(e,"newTYPO3frontendWindow").focus()}}static openInfoPopUp(e,t){r.showItem(e,t)}static mountAsTreeRoot(e,t){"pages"===e&&s.NavigationContainer.PageTree.setTemporaryMountPoint(t)}static newPageWizard(e,t){s.ContentContainer.setUrl(top.TYPO3.settings.NewRecord.moduleUrl+"&id="+t+"&pagesOnly=1&returnUrl="+c.getReturnUrl())}static newContentWizard(){const e=a(this);let t=e.data("new-wizard-url");t&&(t+="&returnUrl="+c.getReturnUrl(),o.advanced({title:e.data("title"),type:o.types.ajax,size:o.sizes.medium,content:t,severity:n.SeverityEnum.notice}))}static newRecord(e,t){s.ContentContainer.setUrl(top.TYPO3.settings.FormEngine.moduleUrl+"&edit["+e+"][-"+t+"]=new&returnUrl="+c.getReturnUrl())}static openHistoryPopUp(e,t){s.ContentContainer.setUrl(top.TYPO3.settings.RecordHistory.moduleUrl+"&element="+e+":"+t+"&returnUrl="+c.getReturnUrl())}static openListModule(e,t){const n="pages"===e?t:a(this).data("page-uid");i.App.showModule("web_list","id="+n)}static pagesSort(){const e=a(this).data("pages-sort-url");e&&s.ContentContainer.setUrl(e)}static pagesNewMultiple(){const e=a(this).data("pages-new-multiple-url");e&&s.ContentContainer.setUrl(e)}static disableRecord(e,t){s.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+"&data["+e+"]["+t+"][hidden]=1&redirect="+c.getReturnUrl()).done(()=>{s.NavigationContainer.PageTree.refreshTree()})}static enableRecord(e,t){s.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+"&data["+e+"]["+t+"][hidden]=0&redirect="+c.getReturnUrl()).done(()=>{s.NavigationContainer.PageTree.refreshTree()})}static showInMenus(e,t){s.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+"&data["+e+"]["+t+"][nav_hide]=0&redirect="+c.getReturnUrl()).done(()=>{s.NavigationContainer.PageTree.refreshTree()})}static hideInMenus(e,t){s.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+"&data["+e+"]["+t+"][nav_hide]=1&redirect="+c.getReturnUrl()).done(()=>{s.NavigationContainer.PageTree.refreshTree()})}static deleteRecord(e,t){const r=a(this);o.confirm(r.data("title"),r.data("message"),n.SeverityEnum.warning,[{text:a(this).data("button-close-text")||TYPO3.lang["button.cancel"]||"Cancel",active:!0,btnClass:"btn-default",name:"cancel"},{text:a(this).data("button-ok-text")||TYPO3.lang["button.delete"]||"Delete",btnClass:"btn-warning",name:"delete"}]).on("button.clicked",n=>{if("delete"===n.target.getAttribute("name")){const n=top.TYPO3.settings.RecordCommit.moduleUrl+"&cmd["+e+"]["+t+"][delete]=1";a.ajax({url:n,success:()=>{if("pages"===e&&s.NavigationContainer.PageTree){if(t===top.fsMod.recentIds.web){let e=s.NavigationContainer.PageTree.getFirstNode();s.NavigationContainer.PageTree.selectNode(e)}s.NavigationContainer.PageTree.refreshTree()}}})}o.dismiss()})}static copy(e,t){const n=TYPO3.settings.ajaxUrls.contextmenu_clipboard+"&CB[el]["+e+"%7C"+t+"]=1&CB[setCopyMode]=1";a.ajax(n).always(()=>{c.triggerRefresh(s.ContentContainer.get().location.href)})}static clipboardRelease(e,t){const n=TYPO3.settings.ajaxUrls.contextmenu_clipboard+"&CB[el]["+e+"%7C"+t+"]=0";a.ajax(n).always(()=>{c.triggerRefresh(s.ContentContainer.get().location.href)})}static cut(e,t){const n=TYPO3.settings.ajaxUrls.contextmenu_clipboard+"&CB[el]["+e+"%7C"+t+"]=1&CB[setCopyMode]=0";a.ajax(n).always(()=>{c.triggerRefresh(s.ContentContainer.get().location.href)})}static triggerRefresh(e){e.includes("record%2Fedit")||s.ContentContainer.refresh()}static clearCache(e,t){a.ajax({url:TYPO3.settings.ajaxUrls.web_list_clearpagecache+"&id="+t,cache:!1,dataType:"json",success:e=>{!0===e.success?l.success(e.title,e.message,1):l.error(e.title,e.message,1)},error:()=>{l.error("Clearing page caches went wrong on the server side.")}})}static pasteAfter(e,t){c.pasteInto.bind(a(this))(e,-t)}static pasteInto(e,t){const r=a(this),i=()=>{const n="&CB[paste]="+e+"%7C"+t+"&CB[pad]=normal&redirect="+c.getReturnUrl();s.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+n).done(()=>{"pages"===e&&s.NavigationContainer.PageTree&&s.NavigationContainer.PageTree.refreshTree()})};r.data("title")?o.confirm(r.data("title"),r.data("message"),n.SeverityEnum.warning,[{text:a(this).data("button-close-text")||TYPO3.lang["button.cancel"]||"Cancel",active:!0,btnClass:"btn-default",name:"cancel"},{text:a(this).data("button-ok-text")||TYPO3.lang["button.ok"]||"OK",btnClass:"btn-warning",name:"ok"}]).on("button.clicked",e=>{"ok"===e.target.getAttribute("name")&&i(),o.dismiss()}):i()}}return c});
\ No newline at end of file
+define(["require","exports","./Enum/Severity","jquery","./AjaxDataHandler","./InfoWindow","./Modal","./ModuleMenu","./Viewport","TYPO3/CMS/Backend/Notification"],function(e,t,n,a,r,o,i,s,l,c){"use strict";class d{static getReturnUrl(){return encodeURIComponent(top.list_frame.document.location.pathname+top.list_frame.document.location.search)}static editRecord(e,t){let n="",r=a(this).data("pages-language-uid");r&&(n="&overrideVals[pages][sys_language_uid]="+r),l.ContentContainer.setUrl(top.TYPO3.settings.FormEngine.moduleUrl+"&edit["+e+"]["+t+"]=edit"+n+"&returnUrl="+d.getReturnUrl())}static viewRecord(){const e=a(this).data("preview-url");if(e){window.open(e,"newTYPO3frontendWindow").focus()}}static openInfoPopUp(e,t){o.showItem(e,t)}static mountAsTreeRoot(e,t){"pages"===e&&l.NavigationContainer.PageTree.setTemporaryMountPoint(t)}static newPageWizard(e,t){l.ContentContainer.setUrl(top.TYPO3.settings.NewRecord.moduleUrl+"&id="+t+"&pagesOnly=1&returnUrl="+d.getReturnUrl())}static newContentWizard(){const e=a(this);let t=e.data("new-wizard-url");t&&(t+="&returnUrl="+d.getReturnUrl(),i.advanced({title:e.data("title"),type:i.types.ajax,size:i.sizes.medium,content:t,severity:n.SeverityEnum.notice}))}static newRecord(e,t){l.ContentContainer.setUrl(top.TYPO3.settings.FormEngine.moduleUrl+"&edit["+e+"][-"+t+"]=new&returnUrl="+d.getReturnUrl())}static openHistoryPopUp(e,t){l.ContentContainer.setUrl(top.TYPO3.settings.RecordHistory.moduleUrl+"&element="+e+":"+t+"&returnUrl="+d.getReturnUrl())}static openListModule(e,t){const n="pages"===e?t:a(this).data("page-uid");s.App.showModule("web_list","id="+n)}static pagesSort(){const e=a(this).data("pages-sort-url");e&&l.ContentContainer.setUrl(e)}static pagesNewMultiple(){const e=a(this).data("pages-new-multiple-url");e&&l.ContentContainer.setUrl(e)}static disableRecord(e,t){l.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+"&data["+e+"]["+t+"][hidden]=1&redirect="+d.getReturnUrl()).done(()=>{l.NavigationContainer.PageTree.refreshTree()})}static enableRecord(e,t){l.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+"&data["+e+"]["+t+"][hidden]=0&redirect="+d.getReturnUrl()).done(()=>{l.NavigationContainer.PageTree.refreshTree()})}static showInMenus(e,t){l.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+"&data["+e+"]["+t+"][nav_hide]=0&redirect="+d.getReturnUrl()).done(()=>{l.NavigationContainer.PageTree.refreshTree()})}static hideInMenus(e,t){l.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+"&data["+e+"]["+t+"][nav_hide]=1&redirect="+d.getReturnUrl()).done(()=>{l.NavigationContainer.PageTree.refreshTree()})}static deleteRecord(e,t){const o=a(this);i.confirm(o.data("title"),o.data("message"),n.SeverityEnum.warning,[{text:a(this).data("button-close-text")||TYPO3.lang["button.cancel"]||"Cancel",active:!0,btnClass:"btn-default",name:"cancel"},{text:a(this).data("button-ok-text")||TYPO3.lang["button.delete"]||"Delete",btnClass:"btn-warning",name:"delete"}]).on("button.clicked",n=>{if("delete"===n.target.getAttribute("name")){r.process("cmd["+e+"]["+t+"][delete]=1").done(()=>{if("pages"===e&&l.NavigationContainer.PageTree){if(t===top.fsMod.recentIds.web){let e=l.NavigationContainer.PageTree.getFirstNode();l.NavigationContainer.PageTree.selectNode(e)}l.NavigationContainer.PageTree.refreshTree()}})}i.dismiss()})}static copy(e,t){const n=TYPO3.settings.ajaxUrls.contextmenu_clipboard+"&CB[el]["+e+"%7C"+t+"]=1&CB[setCopyMode]=1";a.ajax(n).always(()=>{d.triggerRefresh(l.ContentContainer.get().location.href)})}static clipboardRelease(e,t){const n=TYPO3.settings.ajaxUrls.contextmenu_clipboard+"&CB[el]["+e+"%7C"+t+"]=0";a.ajax(n).always(()=>{d.triggerRefresh(l.ContentContainer.get().location.href)})}static cut(e,t){const n=TYPO3.settings.ajaxUrls.contextmenu_clipboard+"&CB[el]["+e+"%7C"+t+"]=1&CB[setCopyMode]=0";a.ajax(n).always(()=>{d.triggerRefresh(l.ContentContainer.get().location.href)})}static triggerRefresh(e){e.includes("record%2Fedit")||l.ContentContainer.refresh()}static clearCache(e,t){a.ajax({url:TYPO3.settings.ajaxUrls.web_list_clearpagecache+"&id="+t,cache:!1,dataType:"json",success:e=>{!0===e.success?c.success(e.title,e.message,1):c.error(e.title,e.message,1)},error:()=>{c.error("Clearing page caches went wrong on the server side.")}})}static pasteAfter(e,t){d.pasteInto.bind(a(this))(e,-t)}static pasteInto(e,t){const r=a(this),o=()=>{const n="&CB[paste]="+e+"%7C"+t+"&CB[pad]=normal&redirect="+d.getReturnUrl();l.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+n).done(()=>{"pages"===e&&l.NavigationContainer.PageTree&&l.NavigationContainer.PageTree.refreshTree()})};r.data("title")?i.confirm(r.data("title"),r.data("message"),n.SeverityEnum.warning,[{text:a(this).data("button-close-text")||TYPO3.lang["button.cancel"]||"Cancel",active:!0,btnClass:"btn-default",name:"cancel"},{text:a(this).data("button-ok-text")||TYPO3.lang["button.ok"]||"OK",btnClass:"btn-warning",name:"ok"}]).on("button.clicked",e=>{"ok"===e.target.getAttribute("name")&&o(),i.dismiss()}):o()}}return d});
\ No newline at end of file