/* * 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 r from"@typo3/backend/modal.js";import{html as d}from"lit";import m from"@typo3/core/ajax/ajax-request.js";import l from"@typo3/backend/notification.js";import n from"~labels/scheduler.messages";class p{constructor(){this.selector=".t3js-create-group",this.initialize()}initialize(){const o=document.querySelector(this.selector);o&&o.addEventListener("click",s=>{s.preventDefault();const e=d`
the whole record to add a custom color and description.
`;r.advanced({content:e,title:n.get("function.group.add"),size:r.sizes.small,buttons:[{trigger:()=>r.dismiss(),text:n.get("button.cancel"),btnClass:"btn-default",name:"cancel"},{trigger:()=>{r.currentModal.querySelector('form[name="scheduler-create-group"]').requestSubmit()},text:n.get("button.group.modalOk"),btnClass:"btn-primary",name:"ok"}]}).addEventListener("typo3-modal-shown",()=>{r.currentModal.querySelector('input[name="action[createGroup]"]').focus()})})}createGroup(o){o.preventDefault();const e=new FormData(o.target).get("action[createGroup]").toString(),t="NEW"+Math.random().toString(36).slice(2,7),c="&data[tx_scheduler_task_group]["+t+"][pid]=0&data[tx_scheduler_task_group]["+t+"][groupName]="+encodeURIComponent(e);return new m(TYPO3.settings.ajaxUrls.record_process).post(c,{headers:{"Content-Type":"application/x-www-form-urlencoded","X-Requested-With":"XMLHttpRequest"}}).then(async a=>await a.resolve()).then(a=>(a.hasErrors&&l.error(n.get("msg.group.notification.error.title"),n.get("msg.group.notification.error.message")+' "'+e+'"!'),a.messages.forEach(i=>{l.info(i.title,i.message)}),a)).catch(()=>{l.error(n.get("msg.group.notification.error.title"),n.get("msg.group.notification.error.message")+' "'+e+'"!')}).finally(()=>{if(document.querySelector("#task_group")){const i=document.forms[0],u=i.querySelector('[name="tx_scheduler[select_latest_group]"]');u.value="1",i.submit()}else window.location.reload();r.dismiss()})}editWholeRecord(o){o.preventDefault();const s=r.currentModal.querySelector('input[name="action[createGroup]"]'),e=s?s.value.trim():"",t=new URL(top.TYPO3.settings.FormEngine.moduleUrl,window.location.origin);t.searchParams.set("edit[tx_scheduler_task_group][0]","new"),e&&t.searchParams.set("defVals[tx_scheduler_task_group][groupName]",e),t.searchParams.set("returnUrl",window.location.href),r.dismiss(),window.location.href=t.toString()}}var g=new p;export{g as default};