import { Component, EventEmitter, Injector, Output, ViewChild } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { ModalDirective } from 'ngx-bootstrap'; import { DomSanitizer } from '@angular/platform-browser'; import { FormGroup } from '@angular/forms'; import { FileUploader } from 'ng2-file-upload'; import { CreateOrEditRackAreaDto } from './rackarea.model'; import { SelfHttp } from '@app/shared/common/utils/selfHttp.service'; import { RackTypeLookupTableModalComponent } from '@app/shared/lookup/rackTypeLookup/rackType-lookup-table-modal.component'; @Component({ selector: 'createOrEditRackAreaModal', templateUrl: './create-or-edit-rackarea-modal.component.html' }) export class CreateOrEditRackAreaModalComponent extends AppComponentBase { @ViewChild('createOrEditModal') modal: ModalDirective; @ViewChild('rackTypeLookupTableModal') rackTypeLookupTableModal: RackTypeLookupTableModalComponent; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; saving = false; createOrEditRackAreaDto: CreateOrEditRackAreaDto = new CreateOrEditRackAreaDto(); public uploader: FileUploader; rackArea: string; rackType: string; description: string; isEdit = false; constructor( injector: Injector, public sanitizer: DomSanitizer, public selfHttp: SelfHttp) { super(injector); } show(rackType?, rackArea?): void { const self = this; self.active = true; if (rackArea && rackType) { this.isEdit = true; this.rackArea = rackArea; this.rackType = rackType; this.selfHttp.get('api/RackAreaManage/RackAreaGetEdit', { RackType: this.rackType, RackArea: this.rackArea }, res => { this.createOrEditRackAreaDto.RackType = res.result[0].RACKTYPE; this.createOrEditRackAreaDto.RackArea = res.result[0].RACKAREA; this.createOrEditRackAreaDto.Description = res.result[0].DESCRIPTION; this.createOrEditRackAreaDto.SourceRackType = res.result[0].RACKTYPE; this.createOrEditRackAreaDto.SourceRackArea = res.result[0].RACKAREA; }); } self.modal.show(); } onShown(): void { } openSelectRackTypeModal() { this.rackTypeLookupTableModal.rackType = this.rackType; this.rackTypeLookupTableModal.show(); } setRackTypeNull() { this.rackType = ''; } getNewRackType() { this.rackType = this.rackTypeLookupTableModal.rackType; } save(): void { this.createOrEditRackAreaDto.UserId = this.appSession.getShownLoginName(); this.createOrEditRackAreaDto.RackType = this.rackType; this.selfHttp.post('api/RackAreaManage/CreateOrEditRackArea', this.createOrEditRackAreaDto, res => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }); } close(): void { this.rackArea = ''; this.rackType = ''; this.active = false; this.createOrEditRackAreaDto = new CreateOrEditRackAreaDto(); this.isEdit = false; this.modal.hide(); } }