Files

14 lines
5.5 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{property as p,state as f,customElement as b}from"lit/decorators.js";import{LitElement as g,html as a,nothing as u}from"lit";import{classMap as v}from"lit/directives/class-map.js";var d=function(c,t,n,o){var i=arguments.length,e=i<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,n):o,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")e=Reflect.decorate(c,t,n,o);else for(var r=c.length-1;r>=0;r--)(s=c[r])&&(e=(i<3?s(e):i>3?s(t,n,e):s(t,n))||e);return i>3&&e&&Object.defineProperty(t,n,e),e};let l=class extends g{constructor(){super(...arguments),this.configurationIsWritable=!1,this.data=null,this.addLanguagesActive=!1}createRenderRoot(){return this}render(){return a`<div><h2>Active languages</h2><div class=table-fit><table class="table table-striped"><thead><tr><th><div class=btn-group>${this.globalActions()}</div></th><th>Locale</th><th>Dependencies</th><th>Last update</th></tr></thead><tbody>${this.renderLanguages()}</tbody></table></div></div>`}globalActions(){const t={btn:!0,"btn-default":!0,"update-all":!0,disabled:!this.hasActiveLanguages()};return a`${this.configurationIsWritable?a`<button class="btn btn-default t3js-languagePacks-addLanguage-toggle" @click=${()=>this.addLanguagesActive=!this.addLanguagesActive}><typo3-backend-icon identifier=${this.addLanguagesActive?"actions-minus":"actions-plus"} size=small></typo3-backend-icon>Add language</button>`:u} <button class=${v(t)} ?disabled=${!this.hasActiveLanguages()} @click=${()=>this.dispatchEvent(new CustomEvent("download-packs"))}><typo3-backend-icon identifier=actions-download size=small></typo3-backend-icon>Update all</button>`}renderLanguageActions(t){const n=[],{iso:o}=t,i={detail:{iso:o}};return t.active?(this.configurationIsWritable&&n.push(a`<button class="btn btn-default" title=Deactivate @click=${()=>this.dispatchEvent(new CustomEvent("deactivate-language",i))}><typo3-backend-icon identifier=actions-minus size=small></typo3-backend-icon></button>`),n.push(a`<button class="btn btn-default" title="Download language packs" @click=${()=>this.dispatchEvent(new CustomEvent("download-packs",i))}><typo3-backend-icon identifier=actions-download size=small></typo3-backend-icon></button>`)):this.configurationIsWritable&&n.push(a`<button class="btn btn-default" title=Activate @click=${()=>this.dispatchEvent(new CustomEvent("activate-language",i))}><typo3-backend-icon identifier=actions-plus size=small></typo3-backend-icon></button>`),n}renderLanguages(){return this.data.languages.filter(t=>this.addLanguagesActive?!t.active:t.active).map(t=>a`<tr class=${v({"t3-languagePacks-inactive":!t.active})}><td><div class=btn-group>${this.renderLanguageActions(t)}</div><span class=ms-2>${t.name}</span></td><td>${t.iso}</td><td>${t.dependencies.join(", ")}</td><td>${t.lastUpdate===null?"":t.lastUpdate}</td></tr>`)}hasActiveLanguages(){return Array.isArray(this.data.activeLanguages)&&this.data.activeLanguages.length}};d([p({type:Boolean})],l.prototype,"configurationIsWritable",void 0),d([p({type:Object})],l.prototype,"data",void 0),d([f()],l.prototype,"addLanguagesActive",void 0),l=d([b("typo3-install-language-matrix")],l);let h=class extends g{constructor(){super(...arguments),this.data=null}createRenderRoot(){return this}render(){return this.data.extensions.length===0?a`<typo3-install-infobox severity=0 subject="Language packs have been found for every installed extension." content="To download the latest changes, use the refresh button in the list above."></typo3-install-infobox>`:a`<div><h2>Translation status</h2><div class=table-fit><table class="table table-striped"><thead><tr><th>Extension</th><th>Key</th>${this.headerActions()}</tr></thead><tbody>${this.renderExtensions()}</tbody></table></div></div>`}headerActions(){return this.data.activeLanguages.map(t=>a`<th><button class="btn btn-default" title="Download and update all language packs" @click=${()=>this.dispatchEvent(new CustomEvent("download-packs",{detail:{iso:t}}))}><typo3-backend-icon identifier=actions-download size=small></typo3-backend-icon>${t}</button></th>`)}renderExtensions(){return this.data.extensions.map(t=>a`<tr><td>${t.icon?a`<img src=${t.icon} alt=${t.title} style=max-height:16px;max-width:16px>`:u} ${t.title}</td><td>${t.key}</td>${this.renderExtensionActions(t)}</tr>`)}renderExtensionActions(t){const n=[];return this.data.activeLanguages.forEach(o=>{let i=u;t.packs.forEach(e=>{if(e.iso!==o)return;let s;e.exists!==!0?e.lastUpdate!==null?s="No language pack available for "+e.iso+" when tried at "+e.lastUpdate+". Click to re-try.":s="Language pack not downloaded. Click to download":e.lastUpdate===null?s="Downloaded. Click to renew":s="Language pack downloaded at "+e.lastUpdate+". Click to renew";const r={detail:{iso:e.iso,extension:t.key}};i=a`<td><button class="btn btn-default" title=${s} @click=${()=>this.dispatchEvent(new CustomEvent("download-packs",r))}><typo3-backend-icon identifier=actions-download size=small></typo3-backend-icon>${o}</button></td>`}),i===u&&(i=a`<td></td>`),n.push(i)}),n}};d([p({type:Object})],h.prototype,"data",void 0),h=d([b("typo3-install-extension-matrix")],h);export{h as ExtensionMatrixElement,l as LanguageMatrixElement};