Untitled
unknown
plain_text
2 years ago
7.9 kB
5
Indexable
import { Component, Input, OnInit, ViewEncapsulation } from '@angular/core'; import { FormBuilder } from '@angular/forms'; import { ComponentsRoute } from 'src/app/enums/components-route.enum'; import { ErrorMessage } from 'src/app/enums/error-messages.enum'; import { FormControlsName } from 'src/app/enums/form-control-names.enum'; import { RedirectService } from 'src/app/services/redirect.service'; import { NameValidatorFunction } from 'src/app/utils/name-validator-function.util'; import SessionStorageUtil from 'src/app/utils/session-storage.util'; import { MapTo } from '@adobe/cq-angular-editable-components'; import { QuotationService } from 'src/app/services/quotation.service'; import { AbstractFunnelWithForm } from 'src/app/models/common/abstract/funnel-with-form'; import { Estimation } from 'src/app/models/residential/estimation'; import { TagCommanderMapperService } from 'src/app/services/tag-commander-mapper'; import { ModalUpsellingFotovoltaicoComponent } from 'src/app/components/funnel-common/simulation/modal-upselling-fotovoltaico/modal-upselling-fotovoltaico.component'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { TagCommanderService } from 'ngx-tag-commander'; import { TypeHouse } from 'src/app/enums/type-house.enum'; const TypeHouseEditConfig = { emptyLabel: 'TypeHouse Component', isEmpty: cqModel => !cqModel || !cqModel.message || cqModel.message.trim().length < 1 }; const MAIN_TITLE = 'HAI UNA CASA INDIPENDENTE'; const SECOND_TITLE = 'O SEI IN UN CONDOMINIO?'; const INDIP_TITLE = "Casa indipendente"; const CONDO_TITLE = "Condominio"; const DATO_IMPORTANTE_TITLE = "Perchè è importante questo dato?"; const SPIEGAZIONE_TITLE = "Sapere se vivi in una casa indipendente o in un condominio ci aiuterà a suggeriti l'offerta più adeguata alle tue esigenze."; const CONTINUA_TITLE = "Continua"; @Component({ selector: 'app-type-house', templateUrl: './type-house.component.html', encapsulation: ViewEncapsulation.None }) export class TypeHouseComponent extends AbstractFunnelWithForm implements OnInit { @Input() navBarDesc: string; @Input() mainTitle: string; @Input() secondTitle: string; @Input() indipTitle: string; @Input() condoTitle: string; @Input() datoImportanteTitle: string; @Input() spiegazioneTitle: string; @Input() continuaTitle: string; @Input() fvTitle: string; @Input() fvSubTitle1: string; @Input() fvSubTitle2: string; @Input() fvTextBenefit: string; @Input() fvTextSxBottom: string; @Input() fvCtaPreventivo: string; @Input() fvTextDxBottom: string; @Input() fvBgDxBottom: string; @Input() fvCtaVerifica: string; @Input() fvCustomStyle: string; @Input() fvKoTitle : string; @Input() fvKoSubTitle : string; @Input() fvKoSxText : string; @Input() fvKoSxButton : string; @Input() fvKoDxText : string; @Input() fvKoDxButton : string; @Input() fvOkTitle : string; @Input() fvOkSubTitle1 : string; @Input() fvOkSubTitle2 : string; @Input() fvOkSubTitle3 : string; @Input() fvOkbuttonSx : string; @Input() fvOkbuttonDx : string; showContactous = false useDefault: boolean; isError: boolean = false; constructor(public quotationService: QuotationService, private redirectService: RedirectService, private fb: FormBuilder, private tcMapper: TagCommanderMapperService, private modalService: NgbModal, private tcService: TagCommanderService,) { super(fb, quotationService); this.redirectService.checkCorrectComponentRoute(ComponentsRoute.TYPE_HOUSE); } ngOnInit() { !this.mainTitle && (this.mainTitle = MAIN_TITLE); !this.secondTitle && (this.secondTitle = SECOND_TITLE); !this.indipTitle && (this.indipTitle = INDIP_TITLE) !this.condoTitle && (this.condoTitle = CONDO_TITLE) if (!this.datoImportanteTitle && !this.spiegazioneTitle) { this.showContactous = true } !this.datoImportanteTitle && (this.datoImportanteTitle = DATO_IMPORTANTE_TITLE) !this.spiegazioneTitle && (this.spiegazioneTitle = SPIEGAZIONE_TITLE) !this.continuaTitle && (this.continuaTitle = CONTINUA_TITLE) if (!this.quotationService.quotation.estimation) { this.quotationService.quotation.estimation = {} as Estimation; } this.addFormControl(this.typeHouseFormControlName, this.quotationService.quotation?.estimation?.tipoCasa || '', NameValidatorFunction.getNamedValidationRequired(), null, ErrorMessage.CAMPO_OBBLIGATORIO); } onSubmit(e) { setTimeout(() => { if (!this.formControlsHaveError().length) { if (!this.quotationService.estimation) { this.quotationService.estimation = {}; } this.quotationService.quotation.estimation.tipoCasa = this.getFormControl(this.typeHouseFormControlName).value; this.tcService.setTcVar('order_house_type', this.getFormControl(this.typeHouseFormControlName).value == TypeHouse.INDIPENDENTE ? 'casa' : TypeHouse.CONDOMINIO); SessionStorageUtil.saveQuotation(this.quotationService.quotation); if (this.quotationService.isFunnelPathResidential()) { if (this.getFormControl(this.typeHouseFormControlName).value == TypeHouse.INDIPENDENTE) { const activeModal = this.modalService.open(ModalUpsellingFotovoltaicoComponent); activeModal.componentInstance.title = this.fvTitle; activeModal.componentInstance.sub_title_1 = this.fvSubTitle1; activeModal.componentInstance.sub_title_2 = this.fvSubTitle2; activeModal.componentInstance.text_benefit = this.fvTextBenefit; activeModal.componentInstance.text_sx_bottom = this.fvTextSxBottom; activeModal.componentInstance.cta_preventivo = this.fvCtaPreventivo; activeModal.componentInstance.text_dx_bottom = this.fvTextDxBottom; activeModal.componentInstance.bg_dx_bottom = this.fvBgDxBottom; activeModal.componentInstance.cta_verifica = this.fvCtaVerifica; activeModal.componentInstance.custom_style = this.fvCustomStyle; activeModal.componentInstance.fvKoTitle = this.fvKoTitle; activeModal.componentInstance.fvKoSubTitle = this.fvKoSubTitle; activeModal.componentInstance.fvKoSxText = this.fvKoSxText; activeModal.componentInstance.fvKoSxButton = this.fvKoSxButton; activeModal.componentInstance.fvKoDxText = this.fvKoDxText; activeModal.componentInstance.fvKoDxButton = this.fvKoDxButton; activeModal.componentInstance.fvOkTitle = this.fvOkTitle; activeModal.componentInstance.fvOkSubTitle1 = this.fvOkSubTitle1; activeModal.componentInstance.fvOkSubTitle2 = this.fvOkSubTitle2; activeModal.componentInstance.fvOkSubTitle3 = this.fvOkSubTitle3; activeModal.componentInstance.fvOkbuttonSx = this.fvOkbuttonSx; activeModal.componentInstance.fvOkbuttonDx = this.fvOkbuttonDx; e.preventDefault(); e.stopPropagation(); } else { this.redirectService.redirectTo(ComponentsRoute.CONTRACT_ELE_CHOICE); } } else if (this.quotationService.isFunnelPathPlacetRes()) { this.redirectService.redirectTo(ComponentsRoute.CONTRACT_GAS_HOLDER); } } }, 100); } get typeHouseFormControlName() { return FormControlsName.TYPE_HOUSE; } checkErrors() { if (this.getErrorsByFormControlName(this.typeHouseFormControlName)) { this.isError = true; setTimeout(() => { this.isError = false; }, 500); } else { this.isError = false; } } } MapTo('sorgenia-fe/components/typehouse')(TypeHouseComponent, TypeHouseEditConfig);
Editor is loading...