Files
cms-install/Resources/Public/JavaScript/router.js
T

14 lines
9.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{html as f}from"lit";import o from"@typo3/core/ajax/ajax-request.js";import c from"@typo3/backend/modal.js";import{InfoBox as s}from"@typo3/install/renderable/info-box.js";import l from"@typo3/install/renderable/severity.js";import"@typo3/backend/element/spinner-element.js";import r from"@typo3/core/event/regular-event.js";import"@typo3/backend/element/progress-bar-element.js";import{ScaffoldState as h}from"@typo3/backend/viewport/scaffold-state.js";import"@typo3/backend/element/sidebar-toggle-element.js";import"bootstrap";class m{constructor(){this.rootSelector=".t3js-body",this.contentSelector=".t3js-module-body-container"}setContent(e){const t=this.rootContainer.querySelector(this.contentSelector);typeof e=="string"&&(e=document.createRange().createContextualFragment(e)),t.replaceChildren(e)}initialize(){this.rootContainer=document.querySelector(this.rootSelector),this.context=this.rootContainer.dataset.context??"",this.controller=this.rootContainer.dataset.controller??"",this.registerInstallToolRoutes(),new r("click",e=>{e.preventDefault(),this.logout()}).delegateTo(document,".t3js-login-lockInstallTool"),new r("click",e=>{e.preventDefault(),this.login()}).delegateTo(document,".t3js-login-login"),new r("keydown",e=>{e.key==="Enter"&&(e.preventDefault(),this.login())}).delegateTo(document,"#t3-install-form-password"),new r("click",(e,t)=>{e.preventDefault();const a=t.dataset.import,n=t.dataset.inline;if(typeof n<"u"&&parseInt(n,10)===1)import(a).then(({default:i})=>{i.initialize(t)});else{const i=t.closest(".card").querySelector(".card-title").innerHTML,u=t.dataset.modalSize||c.sizes.large;c.advanced({type:c.types.default,title:i,size:u,content:f`<div class=modal-loading><typo3-backend-spinner size=large></typo3-backend-spinner></div>`,additionalCssClasses:["install-tool-modal"],staticBackdrop:!0,callback:g=>{import(a).then(({default:p})=>{p.initialize(g)})}})}}).delegateTo(document,".card .btn"),this.context==="backend"?this.executeSilentConfigurationUpdate():this.preAccessCheck()}registerInstallToolRoutes(){typeof TYPO3.settings>"u"&&(TYPO3.settings={ajaxUrls:{icons:window.location.origin+window.location.pathname+"?__typo3_install&install[controller]=icon&install[action]=getIcon"}})}getUrl(e,t,a){const n=new URL(location.href,window.origin);if(n.searchParams.set("__typo3_install",""),n.searchParams.set("install[controller]",t??this.controller),n.searchParams.set("install[context]",this.context),e!==void 0&&n.searchParams.set("install[action]",e),a!==void 0)for(const[d,i]of Object.entries(a))n.searchParams.set(d,i);return n.toString()}executeSilentConfigurationUpdate(){this.updateLoadingInfo("Checking session and executing silent configuration update"),new o(this.getUrl("executeSilentConfigurationUpdate","layout")).get({cache:"no-cache"}).then(async e=>{(await e.resolve()).success===!0?this.executeSilentTemplateFileUpdate():this.executeSilentConfigurationUpdate()},e=>{this.handleAjaxError(e)})}executeSilentTemplateFileUpdate(){this.updateLoadingInfo("Checking session and executing silent template file update"),new o(this.getUrl("executeSilentTemplateFileUpdate","layout")).get({cache:"no-cache"}).then(async e=>{(await e.resolve()).success===!0?this.executeSilentExtensionConfigurationSynchronization():this.executeSilentTemplateFileUpdate()},e=>{this.handleAjaxError(e)})}executeSilentExtensionConfigurationSynchronization(){this.updateLoadingInfo("Executing silent extension configuration synchronization"),new o(this.getUrl("executeSilentExtensionConfigurationSynchronization","layout")).get({cache:"no-cache"}).then(async e=>{(await e.resolve()).success===!0?this.loadMainLayout():this.setContent(s.create(l.error,"Something went wrong"))},e=>{this.handleAjaxError(e)})}loadMainLayout(){this.updateLoadingInfo("Loading main layout"),new o(this.getUrl("mainLayout","layout",{"install[module]":this.controller})).get({cache:"no-cache"}).then(async e=>{const t=await e.resolve();t.success===!0&&t.html!=="undefined"&&t.html.length>0?(this.rootContainer.innerHTML=t.html,this.context!=="backend"&&(this.rootContainer.querySelector('[data-installroute-controller="'+this.controller+'"]').classList.add("modulemenu-action-active"),this.registerScaffoldEvents()),this.loadCards()):this.rootContainer.replaceChildren(s.create(l.error,"Something went wrong"))},e=>{this.handleAjaxError(e)})}async handleAjaxError(e,t){if(e.response?.status===403)this.context==="backend"?this.rootContainer.replaceChildren(s.create(l.error,"The Install Tool session expired. Please reload the backend and try again.")):this.checkEnableInstallToolFile();else{const n='<div class="t3js-infobox callout callout-sm callout-danger"><div class="callout-content"><div class="callout-title">Something went wrong</div><div class="callout-body"><p>Please use <b><a href="'+this.getUrl(void 0,"upgrade")+`">Check for broken extensions</a></b> to see if a loaded extension breaks this part of the Install Tool and unload it.</p><p>The box below may additionally reveal further details on what went wrong depending on your debug settings. It may help to temporarily switch to debug mode using <b>Settings > Configuration Presets > Debug settings.</b></p><p>If this error happens at an early state and no full exception back trace is shown, it may also help to manually increase debugging output in <strong>%config-dir%/system/settings.php</strong>:<code>['BE']['debug'] => true</code>, <code>['SYS']['devIPmask'] => '*'</code>, <code>['SYS']['displayErrors'] => 1</code>,<code>['SYS']['exceptionalErrors'] => 12290</code></p></div></div></div><div class="panel-group" role="tablist" aria-multiselectable="true"><div class="panel panel-default"><h3 class="panel-heading" role="tab" id="heading-error"><div class="panel-heading-row"><button type="button" data-bs-toggle="collapse" data-bs-parent="#accordion" data-bs-target="#collapse-error" aria-expanded="true" aria-controls="collapse-error" class="panel-button collapsed"><div class="panel-title"><strong>Ajax error</strong></div><span class="caret"></span></button></div></h3><div id="collapse-error" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-error"><div class="panel-body">`+(e.response?await e.response.text():e.message)+"</div></div></div></div>";typeof t<"u"?t.innerHTML=n:this.rootContainer.innerHTML=n}}checkEnableInstallToolFile(){new o(this.getUrl("checkEnableInstallToolFile")).get({cache:"no-cache"}).then(async e=>{(await e.resolve()).success===!0?this.checkLogin():this.showEnableInstallTool()},e=>{this.handleAjaxError(e)})}showEnableInstallTool(){new o(this.getUrl("showEnableInstallToolFile")).get({cache:"no-cache"}).then(async e=>{const t=await e.resolve();t.success===!0&&(this.rootContainer.innerHTML=t.html)},e=>{this.handleAjaxError(e)})}checkLogin(){new o(this.getUrl("checkLogin")).get({cache:"no-cache"}).then(async e=>{(await e.resolve()).success===!0?this.loadMainLayout():this.showLogin()},e=>{this.handleAjaxError(e)})}showLogin(){new o(this.getUrl("showLogin")).get({cache:"no-cache"}).then(async e=>{const t=await e.resolve();t.success===!0&&(this.rootContainer.innerHTML=t.html)},e=>{this.handleAjaxError(e)})}login(){const e=document.querySelector(".t3js-login-output");e.innerHTML="",new o(this.getUrl()).post({install:{action:"login",token:document.querySelector("[data-login-token]").dataset.loginToken,password:document.querySelector(".t3-install-form-input-text").value}}).then(async t=>{const a=await t.resolve();a.success===!0?this.executeSilentConfigurationUpdate():a.status.forEach(n=>{e.replaceChildren(s.create(n.severity,n.title,n.message))})},t=>{this.handleAjaxError(t)})}logout(){new o(this.getUrl("logout")).get({cache:"no-cache"}).then(async e=>{(await e.resolve()).success===!0&&this.showEnableInstallTool()},e=>{this.handleAjaxError(e)})}loadCards(){new o(this.getUrl("cards")).get({cache:"no-cache"}).then(async e=>{const t=await e.resolve();t.success===!0&&t.html!=="undefined"&&t.html.length>0?this.setContent(t.html):this.setContent(s.create(l.error,"Something went wrong"))},e=>{this.handleAjaxError(e)})}registerScaffoldEvents(){h.initialize(),document.querySelectorAll("[data-installroute-controller]").forEach(e=>{e.addEventListener("click",()=>{h.toggleSidebarFlyout(!1)})})}updateLoadingInfo(e){const t=this.rootContainer.querySelector("#t3js-ui-block-detail");t!==void 0&&t instanceof HTMLElement&&(t.innerText=e)}preAccessCheck(){this.updateLoadingInfo("Execute pre access check"),new o(this.getUrl("preAccessCheck","layout")).get({cache:"no-cache"}).then(async e=>{const t=await e.resolve();t.installToolLocked?this.checkEnableInstallToolFile():t.isAuthorized?this.executeSilentConfigurationUpdate():this.showLogin()},e=>{this.handleAjaxError(e)})}}var y=new m;export{y as default};