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 { CreateOrEditRackIdDto } from './rackid.model'; import { SelfHttp } from '@app/shared/common/utils/selfHttp.service'; import { RackTypeLookupTableModalComponent } from '@app/shared/lookup/rackTypeLookup/rackType-lookup-table-modal.component'; import { RackAreaLookupTableModalComponent } from '@app/shared/lookup/rackAreaLookup/rackArea-lookup-table-modal.component'; @Component({ selector: 'createOrEditRackIdModal', templateUrl: './create-or-edit-rackid-modal.component.html' }) export class CreateOrEditRackIdModalComponent extends AppComponentBase { @ViewChild('createOrEditModal') modal: ModalDirective; @ViewChild('rackTypeLookupTableModal') rackTypeLookupTableModal: RackTypeLookupTableModalComponent; @ViewChild('rackAreaLookupTableModal') rackAreaLookupTableModal: RackAreaLookupTableModalComponent; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; saving = false; createOrEditRackIdDto: CreateOrEditRackIdDto = new CreateOrEditRackIdDto(); public uploader: FileUploader; rackArea: string; rackType: string; rackId: string; isEdit = false; isabled = false; constructor( injector: Injector, public sanitizer: DomSanitizer, public selfHttp: SelfHttp) { super(injector); } show(rackType?, rackArea?, rackId?): void { const self = this; self.active = true; if (rackArea && rackType && rackId) { this.rackArea = rackArea; this.rackType = rackType; this.rackId = rackId; this.isEdit = true; this.selfHttp.get('api/RackIdManage/RackIdGetEdit', { RackType: this.rackType, RackArea: this.rackArea, RackId: this.rackId }, res => { this.createOrEditRackIdDto.RackType = res.result[0].RACKTYPE; this.createOrEditRackIdDto.RackArea = res.result[0].RACKAREA; this.createOrEditRackIdDto.RackId = res.result[0].RACKID; this.createOrEditRackIdDto.Description = res.result[0].DESCRIPTION; this.createOrEditRackIdDto.Qty = res.result[0].QTY; this.createOrEditRackIdDto.Package = res.result[0].PACKAGE; this.createOrEditRackIdDto.SourceRackType = res.result[0].RACKTYPE; this.createOrEditRackIdDto.SourceRackArea = res.result[0].RACKAREA; this.createOrEditRackIdDto.SourceRackId = res.result[0].RACKID; this.createOrEditRackIdDto.CapacityType = res.result[0].CAPACITYTYPE; }); this.selfHttp.get('api/RackIdManage/CheckIsUsed', { RackType: this.rackType, RackArea: this.rackArea, RackId: this.rackId }, res => { this.isabled = res; console.log(this.isabled); }); } this.isabled = false; self.modal.show(); } onShown(): void { } openSelectRackTypeModal() { this.rackTypeLookupTableModal.rackType = this.rackType; this.rackTypeLookupTableModal.show(); } openSelectRackAreaModal() { this.rackAreaLookupTableModal.filterRackType = this.rackType; this.rackAreaLookupTableModal.rackArea = this.rackArea; this.rackAreaLookupTableModal.show(); } setRackTypeNull() { this.rackType = ''; this.rackArea = ''; } setRackAreaNull() { this.rackArea = ''; } getNewRackType() { this.rackType = this.rackTypeLookupTableModal.rackType; } getNewRackArea() { this.rackType = this.rackAreaLookupTableModal.rackType; this.rackArea = this.rackAreaLookupTableModal.rackArea; } saveAndContinue(): void { this.createOrEditRackIdDto.UserId = this.appSession.getShownLoginName(); this.createOrEditRackIdDto.RackType = this.rackType; this.createOrEditRackIdDto.RackArea = this.rackArea; this.selfHttp.post('api/RackIdManage/CreateOrEditRackId', this.createOrEditRackIdDto, res => { this.notify.info(this.l('SavedSuccessfully')); this.modalSave.emit(null); this.createOrEditRackIdDto = new CreateOrEditRackIdDto(); }); } save(): void { this.createOrEditRackIdDto.UserId = this.appSession.getShownLoginName(); this.createOrEditRackIdDto.RackType = this.rackType; this.createOrEditRackIdDto.RackArea = this.rackArea; this.selfHttp.post('api/RackIdManage/CreateOrEditRackId', this.createOrEditRackIdDto, res => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }); } batchSave(): void { this.createOrEditRackIdDto.UserId = this.appSession.getShownLoginName(); this.createOrEditRackIdDto.RackType = this.rackType; this.createOrEditRackIdDto.RackArea = this.rackArea; this.selfHttp.post('api/RackIdManage/BatchCreate', this.createOrEditRackIdDto, res => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }); } close(): void { this.rackArea = ''; this.rackType = ''; this.active = false; this.createOrEditRackIdDto = new CreateOrEditRackIdDto(); this.isEdit = false; this.modal.hide(); } }