14 lines
6.0 KiB
JavaScript
14 lines
6.0 KiB
JavaScript
/*
|
|
* This file is part of the TYPO3 CMS project.
|
|
*
|
|
* It is free software; you can redistribute it and/or modify it under
|
|
* the terms of the GNU General Public License, either version 2
|
|
* of the License, or any later version.
|
|
*
|
|
* For the full copyright and license information, please read the
|
|
* LICENSE.txt file that was distributed with this source code.
|
|
*
|
|
* The TYPO3 project - inspiring people to share!
|
|
*/
|
|
import{SeverityEnum as C}from"@typo3/backend/enum/severity.js";import c from"@typo3/core/ajax/ajax-request.js";import s from"@typo3/backend/notification.js";import U from"@typo3/backend/modal.js";import d from"@typo3/backend/hashing/md5.js";import{fileListOpenElementBrowser as w}from"@typo3/filelist/file-list.js";import{FileListActionUtility as f,FileListActionEvent as m}from"@typo3/filelist/file-list-actions.js";import a from"~labels/core.core";import u from"~labels/core.common";class l{static getReturnUrl(){return encodeURIComponent(top.list_frame.document.location.pathname+top.list_frame.document.location.search)}static triggerFileDownload(r,t,e=!1){const n=document.createElement("a");n.href=r,n.download=t,document.body.appendChild(n),n.click(),e&&URL.revokeObjectURL(r),document.body.removeChild(n),s.success(a.get("file_download.success"),"",2)}static renameFile(r,t,e){(async()=>{await import("@typo3/filelist/file-list-rename-handler.js");const n=f.createResourceFromContextDataset(e),o={event:null,trigger:null,action:m.rename,resources:[n],url:null,originalAction:null};document.dispatchEvent(new CustomEvent(m.rename,{detail:o}))})()}static replaceFile(r,t,e){(async()=>{await import("@typo3/filelist/file-list-replace-handler.js");const n=f.createResourceFromContextDataset(e),o={event:null,trigger:null,action:m.rename,resources:[n],url:null,originalAction:null};document.dispatchEvent(new CustomEvent(m.replace,{detail:o}))})()}static editFile(r,t,e){const n=e.actionUrl;top.TYPO3.Backend.ContentContainer.setUrl(n+"&target="+encodeURIComponent(t)+"&returnUrl="+l.getReturnUrl())}static editMetadata(r,t,e){const n=f.createResourceFromContextDataset(e);n.metaUid&&top.TYPO3.Backend.ContentContainer.setUrl(top.TYPO3.settings.FormEngine.moduleUrl+"&edit[sys_file_metadata]["+n.metaUid+"]=edit&module="+encodeURIComponent(top.TYPO3.ModuleMenu.App.getCurrentModule())+"&returnUrl="+l.getReturnUrl())}static openInfoPopUp(r,t){r==="sys_file_storage"?top.TYPO3.InfoWindow.showItem(r,t):top.TYPO3.InfoWindow.showItem("_FILE",t)}static createFolder(r,t,e){top.TYPO3.Backend.ContentContainer.get().document.dispatchEvent(new CustomEvent(w,{detail:{actionUrl:e.actionUrl,identifier:e.identifier,mode:e.mode}}))}static createFile(r,t,e){top.TYPO3.Backend.ContentContainer.get().document.dispatchEvent(new CustomEvent(w,{detail:{actionUrl:e.actionUrl,identifier:e.identifier,mode:e.mode}}))}static downloadFile(r,t,e){l.triggerFileDownload(e.url,e.name)}static downloadFolder(r,t,e){s.info(a.get("file_download.prepare"),"",2);const n=e.actionUrl;new c(n).post({items:[t]}).then(async o=>{let i=o.response.headers.get("Content-Disposition");if(!i){const g=await o.resolve();g.success===!1&&g.status==="noFiles"?s.warning(a.get("file_download.noFiles"),a.get("file_download.noFiles.message"),10):s.error(a.get("file_download.error"));return}i=i.substring(i.indexOf(" filename=")+10);const p=await o.raw().arrayBuffer(),b=new Blob([p],{type:o.raw().headers.get("Content-Type")});l.triggerFileDownload(URL.createObjectURL(b),i,!0)}).catch(()=>{s.error(a.get("file_download.error"))})}static createFilemount(r,t){t.split(":").length===2&&top.TYPO3.Backend.ContentContainer.setUrl(top.TYPO3.settings.FormEngine.moduleUrl+"&edit[sys_filemounts][0]=new&defVals[sys_filemounts][identifier]="+encodeURIComponent(t)+"&returnUrl="+l.getReturnUrl())}static deleteFile(r,t,e){const n=()=>{top.TYPO3.Backend.ContentContainer.setUrl(top.TYPO3.settings.FileCommit.moduleUrl+"&data[delete][0][data]="+encodeURIComponent(t)+"&data[delete][0][redirect]="+l.getReturnUrl())};if(!e.title){n();return}const o=U.confirm(e.title,e.message,C.warning,[{text:e.buttonCloseText||u.get("cancel"),active:!0,btnClass:"btn-default",name:"cancel"},{text:e.buttonOkText||u.get("delete")||"Delete",btnClass:"btn-warning",name:"delete"}]);o.addEventListener("button.clicked",i=>{i.target.name==="delete"&&n(),o.hideModal()})}static copyFile(r,t){const e=d.hash(t),n=TYPO3.settings.ajaxUrls.contextmenu_clipboard,o={CB:{el:{["_FILE%7C"+e]:t},setCopyMode:"1"}};new c(n).withQueryArguments(o).get().finally(()=>{top.TYPO3.Backend.ContentContainer.refresh()})}static copyReleaseFile(r,t){const e=d.hash(t),n=TYPO3.settings.ajaxUrls.contextmenu_clipboard,o={CB:{el:{["_FILE%7C"+e]:"0"},setCopyMode:"1"}};new c(n).withQueryArguments(o).get().finally(()=>{top.TYPO3.Backend.ContentContainer.refresh()})}static cutFile(r,t){const e=d.hash(t),n=TYPO3.settings.ajaxUrls.contextmenu_clipboard,o={CB:{el:{["_FILE%7C"+e]:t}}};new c(n).withQueryArguments(o).get().finally(()=>{top.TYPO3.Backend.ContentContainer.refresh()})}static cutReleaseFile(r,t){const e=d.hash(t),n=TYPO3.settings.ajaxUrls.contextmenu_clipboard,o={CB:{el:{["_FILE%7C"+e]:"0"}}};new c(n).withQueryArguments(o).get().finally(()=>{top.TYPO3.Backend.ContentContainer.refresh()})}static pasteFileInto(r,t,e){const n=()=>{top.TYPO3.Backend.ContentContainer.setUrl(top.TYPO3.settings.FileCommit.moduleUrl+"&CB[paste]=FILE|"+encodeURIComponent(t)+"&CB[pad]=normal&redirect="+l.getReturnUrl())};if(!e.title){n();return}const o=U.confirm(e.title,e.message,C.warning,[{text:e.buttonCloseText||u.get("cancel"),active:!0,btnClass:"btn-default",name:"cancel"},{text:e.buttonOkText||u.get("ok"),btnClass:"btn-warning",name:"ok"}]);o.addEventListener("button.clicked",i=>{i.target.name==="ok"&&n(),o.hideModal()})}static updateOnlineMedia(r,t,e){if(!e.actionUrl||!e.filecontextUid||e.filecontextType!=="file")return;const n={resource:{type:e.filecontextType,uid:e.filecontextUid}};new c(e.actionUrl).post(n).then(()=>{s.success(a.get("online_media.update.success"))}).catch(()=>{s.error(a.get("online_media.update.error"))}).finally(()=>{window.location.reload()})}}export{l as default};
|