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 { SelfHttp } from '@app/shared/common/utils/selfHttp.service'; import { CreateOrEditWaferAreaDto } from './waferarea.model'; import { WaferHttp } from '@app/shared/common/utils/waferhttp.service'; @Component({ selector: 'createOrEditWaferAreaModal', templateUrl: './create-or-edit-waferarea-modal.component.html' }) export class CreateOrEditWaferAreaModalComponent extends AppComponentBase { @ViewChild('createOrEditModal') modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; saving = false; createOrEditWaferAreaDto: CreateOrEditWaferAreaDto = new CreateOrEditWaferAreaDto(); public uploader: FileUploader; code: string; isEdit = false; isAllowEdit = true; constructor( injector: Injector, public sanitizer: DomSanitizer, public waferHttp: WaferHttp) { super(injector); } show(code?): void { const self = this; self.active = true; if (code) { this.code = code; this.waferHttp.get('api/WaferTraceAreaManage/getDataForEdit', { Code: this.code }, res => { let result = JSON.parse(res); this.createOrEditWaferAreaDto.Code = result.result[0].AREACODE; this.createOrEditWaferAreaDto.Description = result.result[0].AREANAME; this.createOrEditWaferAreaDto.Id = result.result[0].ID; this.createOrEditWaferAreaDto.ProdLine = result.result[0].ASSYPLANT; }); this.checkIsUsed(); } this.isAllowEdit = false; self.modal.show(); } onShown(): void { document.getElementById('Code').focus(); } save(): void { this.createOrEditWaferAreaDto.UserName = this.appSession.getShownLoginName(); this.waferHttp.post('api/WaferTraceAreaManage/CreateOrEditWaferArea', this.createOrEditWaferAreaDto, res => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }); } close(): void { this.code = ''; this.active = false; this.createOrEditWaferAreaDto = new CreateOrEditWaferAreaDto(); this.isEdit = false; this.modal.hide(); } checkIsUsed() { this.waferHttp.get('api/WaferTraceAreaManage/CheckIsUsed', { Code: this.code }, res => { let result = JSON.parse(res); this.isAllowEdit = result; console.log(this.isAllowEdit); }); } }