| | |
| | | import { DeviceVersion } from './../version.component'; |
| | | import { Component, OnInit } from '@angular/core'; |
| | | import { HttpClient } from '@angular/common/http'; |
| | | import { NzMessageService, NzModalSubject } from 'ng-zorro-antd'; |
| | | import { DateService } from '@core/services/date.service'; |
| | | import { FormGroup, FormBuilder, Validators } from '@angular/forms'; |
| | | |
| | | @Component({ |
| | | selector: 'app-add-or-edit', |
| | |
| | | styles: [] |
| | | }) |
| | | export class AddOrEditComponent implements OnInit { |
| | | |
| | | cols: DeviceVersion; |
| | | |
| | | constructor() { } |
| | | data: DeviceVersion; |
| | | isSaving = false; |
| | | validateForm: FormGroup; |
| | | constructor( |
| | | private subject: NzModalSubject, |
| | | private formBuilder: FormBuilder |
| | | ) { } |
| | | |
| | | ngOnInit() { |
| | | const validates: DeviceVersion = { |
| | | name: [this.data.name, [Validators.required] ], |
| | | version: [this.data.version == null ? 1 : this.data.version, [Validators.required] ], |
| | | createTime: [this.data.createTime, [Validators.required] ], |
| | | description: [this.data.description, [Validators.required] ] |
| | | }; |
| | | this.validateForm = this.formBuilder.group( |
| | | validates |
| | | ); |
| | | } |
| | | |
| | | close() { |
| | | this.subject.destroy(); |
| | | } |
| | | save($event, value, valid) { |
| | | $event.preventDefault(); |
| | | if (valid) { |
| | | for (const i in this.validateForm.controls) { |
| | | this.validateForm.controls[ i ].disable(); |
| | | } |
| | | this.isSaving = true; |
| | | this.data = value; |
| | | this.subject.next( this ); |
| | | }else { |
| | | for (const i in this.validateForm.controls) { |
| | | this.validateForm.controls[ i ].markAsDirty(); |
| | | } |
| | | } |
| | | } |
| | | validate() { |
| | | for (const i in this.validateForm.controls) { |
| | | this.validateForm.controls[ i ].markAsDirty(); |
| | | } |
| | | } |
| | | } |