Current File : /home/pacjaorg/.trash/media.1/com_associations/js/associations-edit.min.js |
/**
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/Joomla=window.Joomla||{},((e,n)=>{e.hideAssociation=(s,t)=>{n.querySelectorAll("#associations .control-group").forEach(i=>{const a=i.querySelector(".control-label label");a&&a.getAttribute("for").replace(/_name$/,"")===`${s}_associations_${t.replace("-","_")}`&&i.classList.add("hidden")})},e.showAssociationMessage=()=>{const s=n.getElementById("associations");if(s){const t=n.createElement("joomla-alert");t.innerText=e.Text._("JGLOBAL_ASSOC_NOT_POSSIBLE"),s.insertAdjacentElement("afterbegin",t)}n.querySelectorAll("#associations .control-group").forEach(t=>{t.classList.add("hidden")})},e.injectAssociations=(s,t)=>{let i;s.success?(s.data.length!==0&&Object.keys(s.data).forEach(a=>{i=t+a.replace("-","_"),window[i](s.data[a].id,s.data[a].title,s.data[a].catid,null,null,a)}),s.message&&e.renderMessages({notice:[s.message]})):e.renderMessages({warning:[e.Text._("JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED")]})},e.propagateAssociation=(s,t)=>{const i=n.getElementById(`${s}_id`).value,a=n.getElementById("jform_language"),c=a.options[a.selectedIndex].value,o={task:"ajax.fetchAssociations",format:"json",assocId:i,excludeLang:c};o[e.getOptions("csrf.token","")]=1;const l=Object.keys(o).reduce((r,d)=>(r.push(`${d}=${encodeURIComponent(o[d])}`),r),[]).join("&"),g=`${n.forms.adminForm.action}&${l}`;return e.request({url:g,method:"GET",data:JSON.stringify(o),headers:{"Content-Type":"application/json"},onSuccess:r=>{e.injectAssociations(JSON.parse(r),t)},onError:()=>{e.renderMessages({warning:[e.Text._("JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED")]})}}),!1},n.addEventListener("DOMContentLoaded",()=>{const s=e.getOptions("system.associations.edit"),t=s.formControl||"jform",i=n.getElementById(`${t}_language`);parseInt(s.hidden,10)===1?e.showAssociationMessage():i&&e.hideAssociation(t,i.value),i&&i.addEventListener("change",({target:a})=>{e.removeMessages();let c=!1;n.querySelectorAll("#associations .control-group").forEach(l=>{const r=l.querySelector(".control-label label").getAttribute("for").replace("_name","").replace("jform_associations_","");l.classList.remove("hidden"),!c&&n.getElementById(`${t}_associations_${r}_id`).value!==""&&(c=!0);let d=n.getElementById(`${t}_associations_${r}_clear`);d=d||l.querySelector('[data-button-action="clear"]'),d.click()}),c&&e.renderMessages({warning:[e.Text._("JGLOBAL_ASSOCIATIONS_RESET_WARNING")]});const o=a.value;o==="*"?e.showAssociationMessage():e.hideAssociation(t,o)})})})(Joomla,document);