Files

14 lines
3.3 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{nothing as c,html as o}from"lit";import{live as d}from"lit/directives/live.js";import{unsafeHTML as h}from"lit/directives/unsafe-html.js";import{Task as u,TaskStatus as p}from"@lit/task";import m from"@typo3/core/ajax/ajax-request.js";import i from"~labels/backend.wizards.localization";class l{constructor(e){this.context=e,this.key="mode",this.title=i.get("step.modes.title"),this.autoAdvance=!0,this.hasDispatchedAutoAdvance=!1,this.selectedMode=null,this.task=new u(this.context.wizard,{task:async([a,s,t,r])=>{if(t==null||r==null)return[];try{return await(await new m(TYPO3.settings.ajaxUrls.wizard_localization_get_modes).withQueryArguments({recordType:a,recordUid:s,targetLanguage:t,sourceLanguage:r}).get()).resolve()}catch(n){return console.warn("Failed to fetch localization modes:",n),[]}},args:()=>[this.context.recordType,this.context.recordUid,this.context.getStoreData("targetLanguage"),this.context.getStoreData("sourceLanguage")],autoRun:!1})}isComplete(){return this.getValue()!==null}render(){return this.task.status===p.INITIAL&&this.task.run(),this.task.render({complete:e=>{if(this.getValue()==null){const t=this.context.getStoreData("localizationMode");t!=null&&this.setValue(t)}let a=!1;if(this.getValue()==null&&e.length>0&&(this.setValue(e[0].key),e.length===1&&(a=!0)),a&&!this.hasDispatchedAutoAdvance)return this.hasDispatchedAutoAdvance=!0,this.context.dispatchAutoAdvance(),this.context.wizard.renderLoader();let s=c;return e.length===0?s=o`<div class=text-center><p>${i.get("step.modes.none_available")}</p></div>`:s=o`<p>${i.get("step.modes.description")}</p><div class=form-check-card-container>${e.map(t=>o`<div class="form-check form-check-type-card"><input class=form-check-input type=radio name=localizationMode id=mode-${t.key} value=${t.key} .checked=${d(this.getValue()===t.key)} @change=${()=>this.setValue(t.key)}> <label class=form-check-label for=mode-${t.key}><span class=form-check-label-header> <typo3-backend-icon identifier=${t.iconIdentifier} size=medium></typo3-backend-icon> ${t.label} </span> <span class=form-check-label-body>${h(t.description)} </span></label></div>`)}</div>`,o`<div class=localization-mode-selection><h2 class=h4>${i.get("step.modes.headline")}</h2>${s}</div>`},error:e=>this.context.wizard.renderError(i.get("step.modes.error.message"),e),pending:()=>this.context.wizard.renderLoader()})}reset(){this.setValue(null),this.context.clearStoreData("localizationMode")}getValue(){return this.selectedMode}setValue(e){this.selectedMode=e}beforeAdvance(){this.context.setStoreData("localizationMode",this.getValue())}getSummaryData(){const e=this.context.getStoreData("localizationMode");if(!e||!this.task.value)return[];const a=this.task.value.find(s=>s.key===e);return a?[{label:i.get("step.modes.summary.title"),value:o`<typo3-backend-icon identifier=${a.iconIdentifier} size=small class=me-1></typo3-backend-icon>${a.label}`}]:[]}}export{l as ModeStep,l as default};