xsnippet logotype

xsnippet

#362692, Untitled [ Text only ]

by Guest
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
private fillDefaultValues(model: DynamicFormControlModel[]): void {
        try {
            for (let i = 0; i < model.length; i++) {
                const controlModel: DynamicFormControlModel = model[i];

                if (controlModel instanceof DynamicFormGroupModel) {
                    const formGroupModel: DynamicFormGroupModel = controlModel as DynamicFormGroupModel;
                    this.fillDefaultValues(formGroupModel.group);
                }

                if (controlModel instanceof DynamicInputModel) {
                    const inputModel: DynamicInputModel = controlModel as DynamicInputModel;

                    if (inputModel.inputType === DYNAMIC_FORM_CONTROL_INPUT_TYPE_DATETIME) {
                        const valueDate = inputModel.dateFromAgo ? moment().set('year', moment().year() - inputModel.dateFromAgo) : moment();
                        inputModel.valueUpdates.next(valueDate.format(this.formatDate));
                    } else if (inputModel.inputType === 'address') {
                        this.googleLookupManager.setGoogleLookup(inputModel);
                        inputModel.inputType = 'text';
                    } else if (inputModel.name === DYNAMIC_FORM_CONTROL_INPUT_NAME_CALLER) {
                        this.talkingToService.talkingToPerson.takeWhile(() => this.isAlive).subscribe((data: string) => {
                            inputModel.valueUpdates.next(data);
                        });
                    }
                }

                if (controlModel instanceof DynamicTextAreaModel) {
                    if (controlModel.name === DYNAMIC_FORM_CONTROL_INPUT_NAME_NOTES) {
                        const talkingToRegex: RegExp = /^Talking To: .*;/g;
                        this.talkingToService.talkingToPerson.takeWhile(() => this.isAlive).subscribe((data: string) => {
                            let value: string = controlModel.value as string || '';
                            const talkingToString: string = `Talking To: ${data}; `;

                            if (!data) {
                                value = value.replace(talkingToRegex, '');
                            } else if (talkingToRegex.test(value)) {
                                value = value.replace(talkingToRegex, talkingToString);
                            } else {
                                value = `${talkingToString}${value}`;
                            }

                            controlModel.valueUpdates.next(value.trim());
                        });
                    }
                }
            }
        } catch (e) {
            console.log(e);
        }
    }