Liferay.Loader.define("journal-web@5.0.108/js/article/Template",["module","exports","require","frontend-js-web"],(function(e,t,n){window;Object.defineProperty(t,"__esModule",{value:!0}),t.default=function _default({currentURL:e,ddmTemplateId:t,editDDMTemplateURL:n,namespace:d,previewArticleContentTemplateURL:l,selectDDMTemplateURL:c}){const m=[],namespaceId=e=>"".concat(d).concat(e),changeDDMTemplate=n=>{n&&n.ddmtemplateid===Number(t)||(0,a.openConfirmModal)({message:Liferay.Language.get("editing-the-current-template-deletes-all-unsaved-content"),onConfirm:t=>{if(t){const t=n&&n.ddmtemplateid||-1,d=(0,a.addParams)("".concat(namespaceId("ddmTemplateId"),"=").concat(t),e),l=document.getElementById(namespaceId("fm1"));l&&((0,a.setFormValues)(l,{ddmTemplateId:t,ddmTemplateKey:n&&n.ddmtemplatekey||"",ddmTemplateName:n&&n.name||""}),l.action=d,l.submit())}}})},r=document.getElementById(namespaceId("previewWithTemplate"));if(r){const previewWithTemplateButtonClick=()=>{const e=new URL(l);e.searchParams.append(namespaceId("ddmTemplateId"),t),e.searchParams.append(namespaceId("languageId"),function getCurrentLanguage(e){const t=Liferay.component("".concat(e,"titleMapAsXML"));if(t)return t.getSelectedLanguageId();return themeDisplay.getLanguageId()}(d)),(0,a.openSelectionModal)({iframeBodyCssClass:"",onSelect:e=>changeDDMTemplate(e),selectEventName:namespaceId("preview"),title:Liferay.Language.get("title"),url:e.href})};r.addEventListener("click",previewWithTemplateButtonClick),m.push({detach:()=>{r.removeEventListener("click",previewWithTemplateButtonClick)}})}const i=document.getElementById(namespaceId("clearDDMTemplate"));if(i){const clearDDMTemplateButtonClick=()=>{changeDDMTemplate(null)};i.addEventListener("click",clearDDMTemplateButtonClick),m.push({detach:()=>{i.removeEventListener("click",clearDDMTemplateButtonClick)}})}const o=document.getElementById(namespaceId("editDDMTemplate"));o&&(o.addEventListener("click",(()=>{(0,a.openConfirmModal)({message:Liferay.Language.get("editing-the-current-template-deletes-all-unsaved-content"),onConfirm:e=>e&&(0,a.navigate)(n)})})),m.push({detach:()=>{o.removeEventListener("click",o)}}));const s=document.getElementById(namespaceId("selectDDMTemplate"));s&&(s.addEventListener("click",(()=>{(0,a.openSelectionModal)({onSelect:e=>changeDDMTemplate(JSON.parse(e.value)),selectEventName:"selectDDMTemplate",title:Liferay.Language.get("templates"),url:c})})),m.push({detach:()=>{s.removeEventListener("click",s)}}));return{dispose:()=>{m.forEach((e=>e.detach()))}}};var a=n("frontend-js-web")}));
//# sourceMappingURL=Template.js.map