initForm()

in ui/src/app/configuration/email-configuration/email-configuration.component.ts [75:180]


    initForm() {
        this.formReady = true;
        this.parentForm = this.fb.group({});
        this.parentForm.addControl(
            'smtpServerHost',
            new UntypedFormControl(
                this.mailConfig.smtpServerHost,
                Validators.required,
            ),
        );
        this.parentForm.addControl(
            'smtpServerPort',
            new UntypedFormControl(
                this.mailConfig.smtpServerPort,
                Validators.required,
            ),
        );
        this.parentForm.addControl(
            'usesAuthentication',
            new UntypedFormControl(this.mailConfig.usesAuthentication),
        );
        this.parentForm.addControl(
            'smtpUsername',
            new UntypedFormControl(this.mailConfig.smtpUsername),
        );
        this.parentForm.addControl(
            'smtpPassword',
            new UntypedFormControl(this.mailConfig.smtpPassword),
        );
        this.parentForm.addControl(
            'usesProxy',
            new UntypedFormControl(this.mailConfig.usesProxy),
        );
        this.parentForm.addControl(
            'proxyHost',
            new UntypedFormControl(this.mailConfig.proxyHost),
        );
        this.parentForm.addControl(
            'proxyPort',
            new UntypedFormControl(this.mailConfig.proxyPort),
        );
        this.parentForm.addControl(
            'usesProxyAuthentication',
            new UntypedFormControl(this.mailConfig.usesProxyAuthentication),
        );
        this.parentForm.addControl(
            'proxyUsername',
            new UntypedFormControl(this.mailConfig.proxyUser),
        );
        this.parentForm.addControl(
            'proxyPassword',
            new UntypedFormControl(this.mailConfig.proxyPassword),
        );
        this.parentForm.addControl(
            'senderAddress',
            new UntypedFormControl(this.mailConfig.senderAddress, [
                Validators.required,
                Validators.email,
            ]),
        );
        this.parentForm.addControl(
            'senderName',
            new UntypedFormControl(this.mailConfig.senderName),
        );
        this.parentForm.addControl(
            'transport',
            new UntypedFormControl(
                this.mailConfig.transportStrategy,
                Validators.required,
            ),
        );
        this.parentForm.addControl(
            'defaultRecipient',
            new UntypedFormControl(this.defaultRecipient, Validators.email),
        );

        this.parentForm.valueChanges.subscribe(v => {
            this.mailConfig.smtpServerHost = v.smtpServerHost;
            this.mailConfig.smtpServerPort = v.smtpServerPort;
            this.mailConfig.usesAuthentication = v.usesAuthentication;
            this.mailConfig.transportStrategy = v.transport;
            if (this.mailConfig.usesAuthentication) {
                this.mailConfig.smtpUsername = v.smtpUsername;
                if (this.mailConfig.smtpPassword !== v.smtpPassword) {
                    this.mailConfig.smtpPassword = v.smtpPassword;
                    this.mailConfig.smtpPassEncrypted = false;
                }
            }
            this.mailConfig.usesProxy = v.usesProxy;
            if (this.mailConfig.usesProxy) {
                this.mailConfig.proxyHost = v.proxyHost;
                this.mailConfig.proxyPort = v.proxyPort;
            }
            this.mailConfig.usesProxyAuthentication = v.usesProxyAuthentication;
            if (this.mailConfig.usesProxyAuthentication) {
                this.mailConfig.proxyUser = v.proxyUsername;
                if (this.mailConfig.proxyPassword !== v.proxyPassword) {
                    this.mailConfig.proxyPassword = v.proxyPassword;
                    this.mailConfig.proxyPassEncrypted = false;
                }
            }
            this.mailConfig.senderAddress = v.senderAddress;
            this.mailConfig.senderName = v.senderName;
            this.defaultRecipient = v.defaultRecipient;
        });
    }