import { Component, DoCheck, EventEmitter, Input, Inject, Output, SimpleChanges, ViewChild } from '@angular/core'; import { FormControl } from "@angular/forms"; import { Profile_CONSTANTS } from '../shared/profile.constants'; @Component({ selector: 'rss-edit-dialog', templateUrl: './edit-dialog.component.html', styleUrls: ['./edit-dialog.component.scss'] }) export class EditDialogComponent{ @Input('editDialogConfig') dialogConfig: any; @Output() onDialogCancel: EventEmitter = new EventEmitter(); @Output() onDialogUpdate: EventEmitter = new EventEmitter(); @ViewChild('editItemRef') editItemRef; public editedName = new FormControl(); public setEditCollectionFocus= false; constructor(@Inject(Profile_CONSTANTS) public constants) { this.editedName = new FormControl(); } ngOnInit() { setTimeout(() => { this.setEditCollectionFocus= true; }, 0); } public onEditCancel(event) { this.onDialogCancel.emit(true); event.stopPropagation(); } public onEditSubmit(event) { this.dialogConfig.message = ""; if (this.editedName.value) if (this.dialogConfig.lstCollection && this.isCollectionExists()) this.dialogConfig.message = this.constants.collection.messages.alreadyExists; else { this.onDialogUpdate.emit(this.editedName.value); } event.stopPropagation(); } public isCollectionExists = () => { let collection: any; let bCollectionExists = false; collection = this.dialogConfig.lstCollection.filter(item => (item.name.toLowerCase() === this.editedName.value.toLowerCase())); if (collection !== null && collection !== undefined && collection.length > 0) { bCollectionExists = true; } else { bCollectionExists = false; } return bCollectionExists; } public stopPropagation = (event) => { event.stopPropagation(); } }