//Importing the libraries import { Component, OnInit } from '@angular/core'; import { DialogService, DynamicDialogConfig, DynamicDialogRef } from 'primeng/api'; //Importing the components import { ContactLoadtemplatePreviewComponent } from '../contact-loadtemplate-preview/contact-loadtemplate-preview.component'; //Importing the core classes import { IEmailTemplateCategories } from '../../../shared/core/IEmailTemplateCategories'; import { IEmailTemplate } from '../../../shared/core/IEmailTemplate'; //Importing the service classes import { EmailsService } from '../../../shared/service/emails.service'; @Component({ selector: 'app-contact-load-template', templateUrl: './contact-load-template.component.html', styleUrls: ['./contact-load-template.component.scss'], providers:[DialogService] }) export class ContactLoadTemplateComponent implements OnInit { emailTemplateCategories: IEmailTemplateCategories[] emailTemplates: IEmailTemplate[] emailTemplateDetails: IEmailTemplate categoryName: string templateName: string isSelectCategory: boolean = true isSelectTemplate: boolean = false message: string = "" //For hidden inputs to keep category and template id hiddenInputForCategory: number = 0 hiddenInputForTemplate: number = 0 //For email template subject emailSubject: string //For email content emailContent: string constructor( public dialogService: DialogService, public emailService: EmailsService, public config: DynamicDialogConfig, public ref: DynamicDialogRef ) { } /** ngOnInit() starts*/ ngOnInit() { this.emailService.getEmailTemplateCategories().subscribe( (data: IEmailTemplateCategories[]) =>{ this.emailTemplateCategories = data; //console.log(this.emailTemplateCategories); }); } /** Ends - ngOnInit() */ loadTemplatesByCategoryId(templateCategoryId: number){ this.emailService.getEmailTemplateByCategoryId(templateCategoryId).subscribe( (data: IEmailTemplate[]) =>{ this.emailTemplates = data; this.hiddenInputForCategory = templateCategoryId; //console.log(this.emailTemplates); }); } TemplatePreview(templateId: number){ //this.emailTemplateDetails = null; this.emailService.GetEmailTemplateDetailsByTemplateId(templateId).subscribe( (data: IEmailTemplate) =>{ this.emailTemplateDetails = data; //console.log(this.emailTemplateDetails); this.categoryName = this.emailTemplateDetails[0].TemplateCategory.Name; this.templateName = this.emailTemplateDetails[0].Title; //popup const ref = this.dialogService.open(ContactLoadtemplatePreviewComponent, { data: { emailTemplateDetails: this.emailTemplateDetails }, header:'Preview: ' + this.categoryName + ' > ' + this.templateName, width: '50%' }); ref.onClose.subscribe(() => { ref.close(); }); }); } SelectTemplate(template: any){ this.hiddenInputForTemplate = template.Id; this.emailSubject = template.Subject; this.emailContent = template.TemplateContent; } Select(){ if(this.hiddenInputForCategory != 0 && this.hiddenInputForTemplate != 0){ this.isSelectTemplate = true; this.message = ""; this.ref.close(); } else{ this.isSelectTemplate = false; this.message = "Please Select An Email Template...." } } }