Liferay.Loader.define("account-admin-web@2.0.82/account_users_admin/js/AccountUserEmailDomainValidator.es",["module","exports","require","frontend-js-web"],(function(e,i,a){window;{Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var t=a("frontend-js-web");class AccountUserEmailDomainValidator extends t.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 a=document.createElement("button");a.className="btn btn-link btn-unstyled link-secondary",a.innerText=Liferay.Language.get("view-valid-domains"),a.onclick=()=>{this.openDialog_(this.viewValidDomainsURL)},a.type="button",i.appendChild(a),e.placeAfter(i)}addFormFieldRules_(e,i){const a=e.get("fieldRules");e.set("fieldRules",a.concat(i))}decorateEmailAddressField_(e){const i=e.formValidator.getField(this.ns("emailAddress"));this.viewValidDomainsURL&&this.addFieldMessage_(i);const a=this.getEmailDomainFieldRule_();this.addFormFieldRules_(e,[a]),this.setWarningValidationStyle_(e,i,a.validatorName)}getEmailDomainFieldRule_(){const e=this.accountEntryNames,i=this.blockedDomains?this.blockedDomains.split(","):this.blockedDomains,a=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,t.sub)(Liferay.Language.get("x-is-a-blocked-domain"),o)):a&&!a.includes(o)&&(r=!0,d=(0,t.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,a,t){e.preventDefault();const s=e.validator.errors[a.get("name")];1===s.length&&s[0]===t&&(submitForm(i),e.halt())}openDialog_(e){(0,t.openWindow)({dialog:{destroyOnHide:!0,height:400,modal:!0,resizable:!1,width:600},title:Liferay.Language.get("valid-domains"),uri:e})}setWarningValidationStyle_(e,i,a){const t=e.formValidator;t.after("errorField",(e=>{if(e.validator.field===i&&e.validator.errors[0]===a){const e=t.findFieldContainer(i);e&&e.replaceClass("has-error","has-warning")}}));const s=t.resetFieldCss;t.resetFieldCss=function(e){if(s.apply(t,[e]),e!==i)return;const a=t.findFieldContainer(e);a&&a.removeClass("has-warning")},t.on("submitError",(t=>{this.onSubmitError_(t,e,i,a)}),this)}}var s=AccountUserEmailDomainValidator;i.default=s}}));
//# sourceMappingURL=AccountUserEmailDomainValidator.es.js.map