Liferay.Loader.define("account-admin-web@2.0.54/account_users_admin/js/AccountUserEmailDomainValidator.es",["module","exports","require","frontend-js-web"],(function(e,i,t){window;{Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var a=t("frontend-js-web");class e extends a.PortletBase{created(e){this.accountEntryNames=e.accountEntryNames,this.blockedDomains=e.blockedDomains,this.validDomains=e.validDomains,this.viewValidDomainsURL=e.viewValidDomainsURL}attached(){const e=this.getForm_(this.ns("fm"));e?this.decorateEmailAddressField_(e):Liferay.once(this.ns("formReady"),(e=>{const i=this.getForm_(e.formName);i&&this.decorateEmailAddressField_(i)}),this)}addFieldMessage_(e){const i=document.createElement("div");i.className="form-text";const t=document.createElement("button");t.className="btn btn-link btn-unstyled link-secondary",t.innerText=Liferay.Language.get("view-valid-domains"),t.onclick=()=>{this.openDialog_(this.viewValidDomainsURL)},t.type="button",i.appendChild(t),e.placeAfter(i)}addFormFieldRules_(e,i){const t=e.get("fieldRules");e.set("fieldRules",t.concat(i))}decorateEmailAddressField_(e){const i=e.formValidator.getField(this.ns("emailAddress"));this.viewValidDomainsURL&&this.addFieldMessage_(i);const t=this.getEmailDomainFieldRule_();this.addFormFieldRules_(e,[t]),this.setWarningValidationStyle_(e,i,t.validatorName)}getEmailDomainFieldRule_(){const e=this.accountEntryNames,i=this.blockedDomains?this.blockedDomains.split(","):this.blockedDomains,t=this.validDomains?this.validDomains.split(","):this.validDomains,s="emailDomain";return{body(s,n){const o=s.substr(s.indexOf("@")+1);let d,r=!1;if(i&&i.includes(o)?(r=!0,d=(0,a.sub)(Liferay.Language.get("x-is-a-blocked-domain"),o)):t&&!t.includes(o)&&(r=!0,d=(0,a.sub)(Liferay.Language.get("x-is-not-a-valid-domain-for-the-following-accounts-x"),o,e)),r){const e=n.get("name"),i=this.get("fieldStrings");return i[e]||(i[e]={}),i[e].emailDomain=d,!1}return!0},custom:!0,fieldName:this.ns("emailAddress"),validatorName:s}}getForm_(e){var i;return null===(i=Liferay.Form)||void 0===i?void 0:i.get(e)}onSubmitError_(e,i,t,a){e.preventDefault();const s=e.validator.errors[t.get("name")];1===s.length&&s[0]===a&&(submitForm(i),e.halt())}openDialog_(e){(0,a.openWindow)({dialog:{destroyOnHide:!0,height:400,modal:!0,resizable:!1,width:600},title:Liferay.Language.get("valid-domains"),uri:e})}setWarningValidationStyle_(e,i,t){const a=e.formValidator;a.after("errorField",(e=>{if(e.validator.field===i&&e.validator.errors[0]===t){const e=a.findFieldContainer(i);e&&e.replaceClass("has-error","has-warning")}}));const s=a.resetFieldCss;a.resetFieldCss=function(e){if(s.apply(a,[e]),e!==i)return;const t=a.findFieldContainer(e);t&&t.removeClass("has-warning")},a.on("submitError",(a=>{this.onSubmitError_(a,e,i,t)}),this)}}var s=e;i.default=s}}));
//# sourceMappingURL=AccountUserEmailDomainValidator.es.js.map