/** * @Component Name: CheckoutComponent * @Module: Checkout * @Module Functionality : To display the estimate/email connfirm * @Creation Date: August 12,2018 * @Author: sbaireddy * @Version: 1.0 */ import { Component, OnInit, ViewChild } from '@angular/core'; import { Router } from '@angular/router'; import * as Constants from '../shared/constants'; import { SharedService } from '../shared/shared.service'; import { UserService } from '../services/user.service'; import { CartService } from '../services/cart.service'; import { SurveyComponent } from '../shared/survey/survey.component'; import { User } from '../shared/modal/user'; import { Cart } from '../shared/modal/cart'; declare var $: any; @Component({ selector: 'estimate-cmp', moduleId: module.id, templateUrl: './estimate.component.html', styleUrls: ['./estimate.component.css'] }) export class EstimateComponent implements OnInit { private COMPONENT_NAME: string = 'EstimateComponent'; showSpinner: boolean = false; showFullSidebar: boolean = true; errorMessage: string; cart: Cart; user: User; // user profile storeId: number; @ViewChild('orderNotesModal') orderNotesModal: any; @ViewChild('clearAllModal') clearAllModal: any; @ViewChild('surveyModal') surveyModal: any; /** constructor */ constructor( public router: Router, public sharedService: SharedService, public cartService: CartService, public userService: UserService) { } /** * This function is used to initialize the directive/component after Angular * first displays the data-bound properties.It is invoked only once when the * directive is instantiated.Here it is initializing all the states, payment methods and card types * @returns void */ ngOnInit(): void { const METHOD_NAME: string = 'ngOnInit()'; console.log('AppComponent.ngOnInit()>>Start'); this.sharedService.updateErrorMessage(null); this.user = this.userService.getUser(); this.sharedService.storeId.subscribe((val: number) => { this.storeId = val; }); this.sharedService.spinnerStatus.subscribe((val: boolean) => { this.showSpinner = val; }); this.sharedService.showSidebarStatus.subscribe((val: boolean) => { this.showFullSidebar = val; }); this.sharedService.errorMessage.subscribe((val: string) => { this.errorMessage = val; }); this.cart = this.cartService.getCart(); console.log('AppComponent.ngOnInit()>>End'); } /** * This function is used to display or clear ordernotes based on actionName * @param {} actionName contains valid action performed by user. * @returns void */ onTitleAction(actionName): void { const METHOD_NAME: string = 'onTitleAction()'; if (actionName === Constants.ORDER_NOTES_MODAL) { this.showOrderNotesModal(); } else if (actionName === Constants.CLEAR_ALL_MODAL) { this.showClearAllModel(); } } /** * This function is used to display the order notes * using show after getting the cart from cart service. * @returns void */ showOrderNotesModal(): void { const METHOD_NAME: string = 'showOrderNotesModal()'; if (this.cartService.getCart()) { this.orderNotesModal.show(); } else { this.sharedService.showErrorMessage('_ERR_ORDER_NOTES', false); } } /** * This function is used to clear all data using show if the cart is not empty. * @returns void */ showClearAllModel(): void { const METHOD_NAME: string = 'showClearAllModel()'; if (this.cartService.getCart()) { this.clearAllModal.show(); } else { setTimeout(() => { this.sharedService.setAppDefault(); this.sharedService.clearSessionStorage(false); this.sharedService.showErrorMessage('_ERR_CLEAR_SESSION', false); this.router.navigate(['home/search']); }, 20); } } /** * This function is used to clear all status or session storage from shared service. * @returns void */ clearAllConfirm(): void { const METHOD_NAME: string = 'clearAllConfirm()'; setTimeout(() => { this.clearAllModal.hide(); this.sharedService.showClearAll(true); this.sharedService.showSpinner(true); // spinner this.sharedService.setAppDefault(); // this.sharedService.showMinicart(this.showMinicart =! this.showMinicart); this.sharedService.showSurveyModal(this.surveyModal, this.storeId, this.user.userId); this.sharedService.clearSessionStorage(false); }, 20); } }