Current File : /home/pacjaorg/www/kmm/media/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,a)=>{e.hideAssociation=(s,n)=>{[].slice.call(a.querySelectorAll("#associations .control-group")).forEach(i=>{const o=i.querySelector(".control-label label");o&&o.getAttribute("for").replace(/_name$/,"")===`${s}_associations_${n.replace("-","_")}`&&i.classList.add("hidden")})},e.showAssociationMessage=()=>{const s=[].slice.call(a.querySelectorAll("#associations .control-group")),n=a.getElementById("associations");if(n){const t=a.createElement("joomla-alert");t.innerText=e.Text._("JGLOBAL_ASSOC_NOT_POSSIBLE"),n.insertAdjacentElement("afterbegin",t)}s.forEach(t=>{t.classList.add("hidden")})},e.injectAssociations=(s,n)=>{let t;s.success?(s.data.length!==0&&[].slice.call(Object.keys(s.data)).forEach(i=>{t=n+i.replace("-","_"),window[t](s.data[i].id,s.data[i].title,s.data[i].catid,null,null,i)}),s.message&&e.renderMessages({notice:[s.message]})):e.renderMessages({warning:[e.Text._("JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED")]})},e.propagateAssociation=(s,n)=>{const t=a.getElementById(`${s}_id`).value,i=a.getElementById("jform_language"),o=i.options[i.selectedIndex].value,c={task:"ajax.fetchAssociations",format:"json",assocId:t,excludeLang:o};c[e.getOptions("csrf.token","")]=1;const d=Object.keys(c).reduce((r,l)=>(r.push(`${l}=${encodeURIComponent(c[l])}`),r),[]).join("&"),g=`${a.forms.adminForm.action}&${d}`;return e.request({url:g,method:"GET",data:JSON.stringify(c),headers:{"Content-Type":"application/json"},onSuccess:r=>{e.injectAssociations(JSON.parse(r),n)},onError:()=>{e.renderMessages({warning:[e.Text._("JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED")]})}}),!1},a.addEventListener("DOMContentLoaded",()=>{const s=e.getOptions("system.associations.edit"),n=s.formControl||"jform",t=a.getElementById(`${n}_language`);parseInt(s.hidden,10)===1?e.showAssociationMessage():t&&e.hideAssociation(n,t.value),t&&t.addEventListener("change",({target:i})=>{e.removeMessages();let o=!1;[].slice.call(a.querySelectorAll("#associations .control-group")).forEach(g=>{const l=g.querySelector(".control-label label").getAttribute("for").replace("_name","").replace("jform_associations_","");g.classList.remove("hidden"),!o&&a.getElementById(`${n}_associations_${l}_id`).value!==""&&(o=!0);const f=a.getElementById(`${n}_associations_${l}_clear`);f.onclick?f.onclick():f.click&&f.click()}),o&&e.renderMessages({warning:[e.Text._("JGLOBAL_ASSOCIATIONS_RESET_WARNING")]});const d=i.value;d==="*"?e.showAssociationMessage():e.hideAssociation(n,d)})})})(Joomla,document);