[BUGFIX] Use event target for extension update action 56/61956/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Fri, 11 Oct 2019 12:36:25 +0000 (14:36 +0200)
committerDaniel Goerz <daniel.goerz@posteo.de>
Sun, 13 Oct 2019 16:27:56 +0000 (18:27 +0200)
Since TypeScript is in place, the previously used `$(this)` doesn't work
anymore due to the binding of `this` to either a class or a method.
Instead, the event target is now used to get the href attribute from the
trigger button.

Resolves: #89399
Related: #88040
Releases: master
Change-Id: I2cebd9318cd5903a8f4e011612af078eefa80e85
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61956
Tested-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Build/Sources/TypeScript/extensionmanager/Resources/Public/TypeScript/Main.ts
typo3/sysext/extensionmanager/Resources/Public/JavaScript/Main.js

index 6ed0fb2..b624f7e 100644 (file)
@@ -135,7 +135,7 @@ class ExtensionManager {
       }).on('click', 'a[data-action=update-extension]', (e: JQueryEventObject): void => {
         e.preventDefault();
         $.ajax({
-          url: $(this).attr('href'),
+          url: $(e.currentTarget).attr('href'),
           dataType: 'json',
           beforeSend: (): void => {
             NProgress.start();
index 621f612..a568486 100644 (file)
@@ -10,4 +10,4 @@
  *
  * The TYPO3 project - inspiring people to share!
  */
-define(["require","exports","jquery","nprogress","TYPO3/CMS/Backend/Modal","TYPO3/CMS/Backend/Tooltip","TYPO3/CMS/Backend/Severity","TYPO3/CMS/Core/SecurityUtility","./Repository","./Update","./UploadForm","datatables","TYPO3/CMS/Backend/Input/Clearable"],function(e,t,n,a,o,i,r,s,l,c,d){"use strict";const p=new s;var u;!function(e){e.extensionlist="#typo3-extension-list",e.searchField="#Tx_Extensionmanager_extensionkey"}(u||(u={}));class m{constructor(){this.bindExtensionListActions=(()=>{n(".removeExtension").not(".transformed").each((e,t)=>{const a=n(t);a.data("href",a.attr("href")),a.attr("href","#"),a.addClass("transformed"),a.click(()=>{o.confirm(TYPO3.lang["extensionList.removalConfirmation.title"],TYPO3.lang["extensionList.removalConfirmation.question"],r.error,[{text:TYPO3.lang["button.cancel"],active:!0,btnClass:"btn-default",trigger:()=>{o.dismiss()}},{text:TYPO3.lang["button.remove"],btnClass:"btn-danger",trigger:()=>{this.removeExtensionFromDisk(a),o.dismiss()}}])})})}),n(()=>{n.fn.dataTableExt.oSort["extension-asc"]=((e,t)=>m.extensionCompare(e,t)),n.fn.dataTableExt.oSort["extension-desc"]=((e,t)=>{return-1*m.extensionCompare(e,t)}),n.fn.dataTableExt.oSort["version-asc"]=((e,t)=>{return-1*m.versionCompare(e,t)}),n.fn.dataTableExt.oSort["version-desc"]=((e,t)=>m.versionCompare(e,t)),this.Update=new c,this.UploadForm=new d,this.Repository=new l;const e=this.manageExtensionListing();let t;n(document).on("click",".onClickMaskExtensionManager",()=>{a.start()}).on("click","a[data-action=update-extension]",e=>{e.preventDefault(),n.ajax({url:n(this).attr("href"),dataType:"json",beforeSend:()=>{a.start()},success:this.updateExtension})}).on("change","input[name=unlockDependencyIgnoreButton]",e=>{n(".t3js-dependencies").toggleClass("disabled",!n(e.currentTarget).prop("checked"))}),null!==(t=document.querySelector(u.searchField))&&t.clearable({onClear:()=>{e.search("").draw()}}),n(document).on("click",".t3-button-action-installdistribution",()=>{a.start()}),this.Repository.initDom(),this.Update.initializeEvents(),this.UploadForm.initializeEvents(),i.initialize("#typo3-extension-list [title]",{delay:{show:500,hide:100},trigger:"hover",container:"body"})})}static getUrlVars(){let e=[],t=window.location.href.slice(window.location.href.indexOf("?")+1).split("&");for(let n of t){const[t,a]=n.split("=");e.push(t),e[t]=a}return e}static versionCompare(e,t){if(e===t)return 0;const n=e.split("."),a=t.split("."),o=Math.min(n.length,a.length);for(let e=0;e<o;e++){if(parseInt(n[e],10)>parseInt(a[e],10))return 1;if(parseInt(n[e],10)<parseInt(a[e],10))return-1}return n.length>a.length?1:n.length<a.length?-1:0}static extensionCompare(e,t){const n=document.createElement("div");n.innerHTML=e;const a=n.textContent||n.innerText||e;n.innerHTML=t;const o=n.textContent||n.innerText||t;return a.trim().localeCompare(o.trim())}manageExtensionListing(){const e=n(u.searchField),t=n(u.extensionlist).DataTable({paging:!1,dom:"lrtip",lengthChange:!1,pageLength:15,stateSave:!0,drawCallback:this.bindExtensionListActions,columns:[null,null,{type:"extension"},null,{type:"version"},{orderable:!1},null,null]});e.parents("form").on("submit",()=>!1);const a=m.getUrlVars(),o=a.search?a.search:t.search();return e.val(o),e.on("input",e=>{t.search(n(e.currentTarget).val()).draw()}),t}removeExtensionFromDisk(e){n.ajax({url:e.data("href"),beforeSend:()=>{a.start()},success:()=>{location.reload()},complete:()=>{a.done()}})}updateExtension(e){let t=0;const i=n("<form>");n.each(e.updateComments,(e,a)=>{const o=n("<input>").attr({type:"radio",name:"version"}).val(e);0===t&&o.attr("checked","checked"),i.append([n("<h3>").append([o," "+p.encodeHtml(e)]),n("<div>").append(a.replace(/(\r\n|\n\r|\r|\n)/g,"\n").split(/\n/).map(e=>p.encodeHtml(e)).join("<br>"))]),t++});const s=n("<div>").append([n("<h1>").text(TYPO3.lang["extensionList.updateConfirmation.title"]),n("<h2>").text(TYPO3.lang["extensionList.updateConfirmation.message"]),i]);a.done(),o.confirm(TYPO3.lang["extensionList.updateConfirmation.questionVersionComments"],s,r.warning,[{text:TYPO3.lang["button.cancel"],active:!0,btnClass:"btn-default",trigger:()=>{o.dismiss()}},{text:TYPO3.lang["button.updateExtension"],btnClass:"btn-warning",trigger:()=>{n.ajax({url:e.url,data:{tx_extensionmanager_tools_extensionmanagerextensionmanager:{version:n("input:radio[name=version]:checked",o.currentModal).val()}},dataType:"json",beforeSend:()=>{a.start()},complete:()=>{location.reload()}}),o.dismiss()}}])}}let g=new m;return void 0===TYPO3.ExtensionManager&&(TYPO3.ExtensionManager=g),g});
\ No newline at end of file
+define(["require","exports","jquery","nprogress","TYPO3/CMS/Backend/Modal","TYPO3/CMS/Backend/Tooltip","TYPO3/CMS/Backend/Severity","TYPO3/CMS/Core/SecurityUtility","./Repository","./Update","./UploadForm","datatables","TYPO3/CMS/Backend/Input/Clearable"],function(e,t,n,a,o,i,r,s,l,c,d){"use strict";const p=new s;var u;!function(e){e.extensionlist="#typo3-extension-list",e.searchField="#Tx_Extensionmanager_extensionkey"}(u||(u={}));class m{constructor(){this.bindExtensionListActions=(()=>{n(".removeExtension").not(".transformed").each((e,t)=>{const a=n(t);a.data("href",a.attr("href")),a.attr("href","#"),a.addClass("transformed"),a.click(()=>{o.confirm(TYPO3.lang["extensionList.removalConfirmation.title"],TYPO3.lang["extensionList.removalConfirmation.question"],r.error,[{text:TYPO3.lang["button.cancel"],active:!0,btnClass:"btn-default",trigger:()=>{o.dismiss()}},{text:TYPO3.lang["button.remove"],btnClass:"btn-danger",trigger:()=>{this.removeExtensionFromDisk(a),o.dismiss()}}])})})}),n(()=>{n.fn.dataTableExt.oSort["extension-asc"]=((e,t)=>m.extensionCompare(e,t)),n.fn.dataTableExt.oSort["extension-desc"]=((e,t)=>{return-1*m.extensionCompare(e,t)}),n.fn.dataTableExt.oSort["version-asc"]=((e,t)=>{return-1*m.versionCompare(e,t)}),n.fn.dataTableExt.oSort["version-desc"]=((e,t)=>m.versionCompare(e,t)),this.Update=new c,this.UploadForm=new d,this.Repository=new l;const e=this.manageExtensionListing();let t;n(document).on("click",".onClickMaskExtensionManager",()=>{a.start()}).on("click","a[data-action=update-extension]",e=>{e.preventDefault(),n.ajax({url:n(e.currentTarget).attr("href"),dataType:"json",beforeSend:()=>{a.start()},success:this.updateExtension})}).on("change","input[name=unlockDependencyIgnoreButton]",e=>{n(".t3js-dependencies").toggleClass("disabled",!n(e.currentTarget).prop("checked"))}),null!==(t=document.querySelector(u.searchField))&&t.clearable({onClear:()=>{e.search("").draw()}}),n(document).on("click",".t3-button-action-installdistribution",()=>{a.start()}),this.Repository.initDom(),this.Update.initializeEvents(),this.UploadForm.initializeEvents(),i.initialize("#typo3-extension-list [title]",{delay:{show:500,hide:100},trigger:"hover",container:"body"})})}static getUrlVars(){let e=[],t=window.location.href.slice(window.location.href.indexOf("?")+1).split("&");for(let n of t){const[t,a]=n.split("=");e.push(t),e[t]=a}return e}static versionCompare(e,t){if(e===t)return 0;const n=e.split("."),a=t.split("."),o=Math.min(n.length,a.length);for(let e=0;e<o;e++){if(parseInt(n[e],10)>parseInt(a[e],10))return 1;if(parseInt(n[e],10)<parseInt(a[e],10))return-1}return n.length>a.length?1:n.length<a.length?-1:0}static extensionCompare(e,t){const n=document.createElement("div");n.innerHTML=e;const a=n.textContent||n.innerText||e;n.innerHTML=t;const o=n.textContent||n.innerText||t;return a.trim().localeCompare(o.trim())}manageExtensionListing(){const e=n(u.searchField),t=n(u.extensionlist).DataTable({paging:!1,dom:"lrtip",lengthChange:!1,pageLength:15,stateSave:!0,drawCallback:this.bindExtensionListActions,columns:[null,null,{type:"extension"},null,{type:"version"},{orderable:!1},null,null]});e.parents("form").on("submit",()=>!1);const a=m.getUrlVars(),o=a.search?a.search:t.search();return e.val(o),e.on("input",e=>{t.search(n(e.currentTarget).val()).draw()}),t}removeExtensionFromDisk(e){n.ajax({url:e.data("href"),beforeSend:()=>{a.start()},success:()=>{location.reload()},complete:()=>{a.done()}})}updateExtension(e){let t=0;const i=n("<form>");n.each(e.updateComments,(e,a)=>{const o=n("<input>").attr({type:"radio",name:"version"}).val(e);0===t&&o.attr("checked","checked"),i.append([n("<h3>").append([o," "+p.encodeHtml(e)]),n("<div>").append(a.replace(/(\r\n|\n\r|\r|\n)/g,"\n").split(/\n/).map(e=>p.encodeHtml(e)).join("<br>"))]),t++});const s=n("<div>").append([n("<h1>").text(TYPO3.lang["extensionList.updateConfirmation.title"]),n("<h2>").text(TYPO3.lang["extensionList.updateConfirmation.message"]),i]);a.done(),o.confirm(TYPO3.lang["extensionList.updateConfirmation.questionVersionComments"],s,r.warning,[{text:TYPO3.lang["button.cancel"],active:!0,btnClass:"btn-default",trigger:()=>{o.dismiss()}},{text:TYPO3.lang["button.updateExtension"],btnClass:"btn-warning",trigger:()=>{n.ajax({url:e.url,data:{tx_extensionmanager_tools_extensionmanagerextensionmanager:{version:n("input:radio[name=version]:checked",o.currentModal).val()}},dataType:"json",beforeSend:()=>{a.start()},complete:()=>{location.reload()}}),o.dismiss()}}])}}let g=new m;return void 0===TYPO3.ExtensionManager&&(TYPO3.ExtensionManager=g),g});
\ No newline at end of file