(()=>{"use strict";function e(e,t){for(const[s,n]of Object.entries(t)){const t=new RegExp(`%\\(${s}\\)s`,"g");e=e.replace(t,n)}return e}function t(e){const t=e.target.closest("form");if(t){for(const e of t.querySelectorAll(".aldryn-forms-required-msg, .aldryn-forms-submit-msg"))e.parentNode.removeChild(e);for(const e of t.querySelectorAll("[type=submit]"))e.disabled=!1,e.readOnly=!1}}function s(e,t){e.target.blur();for(const s of e.target.querySelectorAll("[type=submit]"))s.disabled=!0,s.readOnly=!0,t&&s.insertAdjacentHTML("afterend",'<div class="text-danger aldryn-forms aldryn-forms-submit-msg">'+gettext("Please wait. Submitting form...")+"</div>")}function n(t){let s=!0;for(const t of this.getElementsByClassName("form-required")){const n=t.querySelectorAll("input[type=checkbox]:checked").length;n<parseInt(t.dataset.required_min)&&(s=!1,t.insertAdjacentHTML("afterend",'<div class="text-danger aldryn-forms aldryn-forms-required-msg">'+e(gettext("You have to choose at least %(value)s options (chosen %(chosen)s)."),{value:t.dataset.required_min,chosen:n})+"</div>"))}if(s)for(const e of this.querySelectorAll("[type=submit]"))e.insertAdjacentHTML("afterend",'<div class="text-danger aldryn-forms aldryn-forms-submit-msg">'+gettext("Please wait. Submitting form...")+"</div>");else{t.preventDefault();for(const e of this.querySelectorAll("[type=submit]"))e.insertAdjacentHTML("afterend",'<div class="text-danger aldryn-forms aldryn-forms-submit-msg">'+gettext("Correct the errors first, please.")+"</div>")}}function i(e){const t=e.parentNode.querySelector("ul.upload-file-names");if(null===t)return;t.innerHTML="",function(e){const t=e.closest("form");for(const e of t.querySelectorAll("[type=submit]"))e.disabled=!1;for(const e of t.getElementsByClassName("aldryn-forms-submit-msg"))e.remove()}(e);const s=e.accept.length?e.accept.split(","):[];let n=[],i=[],l=[],r=!0,o=null;if(null!==e.dataset.max_size){o=0;for(let t=0;t<e.files.length;t++)o+=e.files[t].size}if(null!==e.dataset.max_size&&o>e.dataset.max_size){r=!1;const e=document.createElement("li");e.classList.add("text-danger"),e.appendChild(document.createTextNode(gettext("The total file size has exceeded the specified limit."))),t.appendChild(e)}if(e.accept.length)for(let e=0;e<s.length;e++)if("."===s[e][0])n.push(s[e]);else{const t=s[e].split("/");"*"===t[1]?l.push(t[0]):i.push(s[e])}for(let o=0;o<e.files.length;o++){const a=document.createElement("li"),d=e.files[o].name,c=document.createElement("span");c.appendChild(document.createTextNode(d+" ")),a.appendChild(c);let f=[];o>=e.dataset.max_files&&f.push(gettext("This file exceeds the uploaded files limit."));let m=!s.length;if(!m&&n){const e=d.toLowerCase().match(/\.\w+$/);null!==e&&n.includes(e[0])&&(m=!0)}if(!m&&i&&i.includes(e.files[o].type)&&(m=!0),!m&&l){const t=e.files[o].type.split("/");l.includes(t[0])&&(m=!0)}if(m||f.push(gettext("The file type is not among the accpeted types.")),f.length){r=!1,c.title=f.join(" "),c.classList.add("fail-upload");const e=document.createElement("img");e.src="/static/admin/img/icon-alert.svg",e.width=16,e.height=16,c.insertBefore(e,c.firstChild)}t.appendChild(a)}r||function(e){const t=e.closest("form");for(const e of t.querySelectorAll("[type=submit]"))e.disabled=!0,e.insertAdjacentHTML("afterend",'<div class="text-danger aldryn-forms aldryn-forms-submit-msg">'+gettext("Correct the errors first, please.")+"</div>")}(e)}"function"!=typeof gettext&&(window.gettext=e=>e),document.addEventListener("DOMContentLoaded",(()=>{for(const e of document.getElementsByTagName("form"))if(e.getAttribute("novalidate"))e.classList.contains("skip-disable-submit")||e.addEventListener("submit",(e=>s(e,!0)));else if(e.classList.contains("skip-disable-submit")||e.addEventListener("submit",(e=>s(e,!1))),!e.getAttribute("novalidate-checkbox-groups")){e.addEventListener("submit",n);for(const s of e.querySelectorAll(".form-required input[type=checkbox]"))s.addEventListener("click",t)}!function(){for(const e of document.querySelectorAll("input[type=file]"))if(void 0!==e.dataset.enable_js){const t=document.createElement("div");t.classList.add("upload-file-frame"),e.parentNode.insertBefore(t,e),e.parentElement.removeChild(e),t.appendChild(e);const s=document.createElement("ul");s.classList.add("upload-file-names"),t.appendChild(s),e.addEventListener("change",(e=>i(e.target)),!1),i(e)}}()}))})();
//# sourceMappingURL=main.js.map