2018-05-25 13:49:00 +00:00
|
|
|
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
|
|
|
|
|
|
|
|
import {ProductGroupService} from '../product-group.service';
|
|
|
|
import {ProductGroup} from '../product-group';
|
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
import {ToasterService} from '../../core/toaster.service';
|
|
|
|
import {FormBuilder, FormGroup} from '@angular/forms';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-product-group-detail',
|
|
|
|
templateUrl: './product-group-detail.component.html',
|
|
|
|
styleUrls: ['./product-group-detail.component.css']
|
|
|
|
})
|
|
|
|
export class ProductGroupDetailComponent implements OnInit, AfterViewInit {
|
2019-06-12 11:55:10 +00:00
|
|
|
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
|
2018-05-25 13:49:00 +00:00
|
|
|
form: FormGroup;
|
|
|
|
item: ProductGroup;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
|
|
|
private fb: FormBuilder,
|
|
|
|
private toaster: ToasterService,
|
|
|
|
private ser: ProductGroupService
|
|
|
|
) {
|
|
|
|
this.createForm();
|
|
|
|
}
|
|
|
|
|
|
|
|
createForm() {
|
|
|
|
this.form = this.fb.group({
|
|
|
|
name: ''
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.route.data
|
|
|
|
.subscribe((data: { item: ProductGroup }) => {
|
|
|
|
this.showItem(data.item);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
showItem(item: ProductGroup) {
|
|
|
|
this.item = item;
|
|
|
|
this.form.setValue({
|
|
|
|
name: this.item.name,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngAfterViewInit() {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.nameElement.nativeElement.focus();
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
save() {
|
|
|
|
this.ser.saveOrUpdate(this.getItem())
|
|
|
|
.subscribe(
|
|
|
|
(result) => {
|
|
|
|
this.toaster.show('Success', '');
|
|
|
|
this.router.navigateByUrl('/ProductGroups');
|
|
|
|
},
|
|
|
|
(error) => {
|
|
|
|
this.toaster.show('Danger', error.error);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
getItem(): ProductGroup {
|
|
|
|
const formModel = this.form.value;
|
|
|
|
this.item.name = formModel.name;
|
|
|
|
return this.item;
|
|
|
|
}
|
|
|
|
}
|