| .. | .. |
|---|
| 8 | 8 | import { IPageChangeEvent } from '@covalent/core'; |
|---|
| 9 | 9 | import { Component, AfterViewInit } from '@angular/core'; |
|---|
| 10 | 10 | import { TdMediaService } from '@covalent/core'; |
|---|
| 11 | | -import { IComboOption } from './base'; |
|---|
| 11 | +import { IComboOption, FormBase } from './base'; |
|---|
| 12 | +import { ActivatedRoute, Router } from '@angular/router'; |
|---|
| 12 | 13 | |
|---|
| 13 | 14 | |
|---|
| 14 | 15 | |
|---|
| .. | .. |
|---|
| 16 | 17 | selector: 'pack-form', |
|---|
| 17 | 18 | templateUrl: 'src/app/forms/pack.form.html' |
|---|
| 18 | 19 | }) |
|---|
| 19 | | -export class PackFormComponent implements AfterViewInit { |
|---|
| 20 | +export class PackFormComponent extends FormBase implements AfterViewInit { |
|---|
| 20 | 21 | |
|---|
| 21 | | - form_title: string = 'Title'; |
|---|
| 22 | | - form_subtitle: string = ''; |
|---|
| 23 | 22 | organizations : IComboOption[]; |
|---|
| 24 | 23 | licensetypes : IComboOption[]; |
|---|
| 25 | 24 | data: any = {}; |
|---|
| .. | .. |
|---|
| 44 | 43 | 'value': '', |
|---|
| 45 | 44 | } |
|---|
| 46 | 45 | constructor(private http: Http, |
|---|
| 47 | | - private toaster: ToastsManager, |
|---|
| 46 | + toaster: ToastsManager, |
|---|
| 48 | 47 | private licenseTypes: LicenseTypesService, |
|---|
| 48 | + route: ActivatedRoute, |
|---|
| 49 | + private router: Router, |
|---|
| 49 | 50 | private packs: PacksService, |
|---|
| 50 | | - private $L: LocaleService) { |
|---|
| 51 | | - Object.keys(this.fields).forEach(k => this.fields[k] = $L.get(`field.${k}`)); |
|---|
| 51 | + $L: LocaleService) { |
|---|
| 52 | + super($L, route, toaster, packs, $L.get('pack')); |
|---|
| 52 | 53 | } |
|---|
| 53 | 54 | |
|---|
| 54 | 55 | public getFieldName(fieldId: string) : string { |
|---|
| 55 | 56 | return this.fields[fieldId]; |
|---|
| 56 | 57 | } |
|---|
| 57 | 58 | |
|---|
| 58 | | - private loadCombos(): void { |
|---|
| 59 | + loadCombos(): void { |
|---|
| 59 | 60 | this.http.get('organization') |
|---|
| 60 | 61 | .map(response => response.json().map((org : any) => <IComboOption>{id: org.id, label: `(${org.code}) ${org.name}`})) |
|---|
| 61 | 62 | .subscribe( |
|---|
| .. | .. |
|---|
| 70 | 71 | ); |
|---|
| 71 | 72 | } |
|---|
| 72 | 73 | |
|---|
| 73 | | - save() { |
|---|
| 74 | | - var command = this.isNew ? this.packs.create(this.data) : this.packs.modify(this.data.id, this.data); |
|---|
| 75 | | - command.subscribe( |
|---|
| 76 | | - data => this.toaster.success(this.$L.get('Pack saved sucessfully')), |
|---|
| 77 | | - err => { |
|---|
| 78 | | - console.error(err); |
|---|
| 79 | | - this.toaster.success(this.$L.get('Error saving pack')); |
|---|
| 80 | | - } |
|---|
| 81 | | - ); |
|---|
| 74 | + |
|---|
| 75 | + goBack(): void { |
|---|
| 76 | + this.router.navigate([`packs`]); |
|---|
| 82 | 77 | } |
|---|
| 83 | 78 | |
|---|
| 84 | 79 | changeLicType(event: any) { |
|---|
| .. | .. |
|---|
| 99 | 94 | } |
|---|
| 100 | 95 | |
|---|
| 101 | 96 | ngOnInit(): void { |
|---|
| 102 | | - this.loadCombos(); |
|---|
| 103 | | - if (this.isNew) { |
|---|
| 104 | | - this.data.status = PACK_STATUS.CREATED; |
|---|
| 105 | | - } |
|---|
| 106 | | - this.form_title = this.$L.get('Pack data'); |
|---|
| 107 | | - this.form_subtitle = this.$L.get(this.isNew ? 'Create a new licenses pack': 'Modify the licenses pack data') ; |
|---|
| 97 | + |
|---|
| 108 | 98 | } |
|---|
| 109 | 99 | |
|---|
| 110 | 100 | |
|---|
| 111 | 101 | ngAfterViewInit(): void { |
|---|
| 102 | + this.loadCombos(); |
|---|
| 103 | + super.prepareData('packId', { |
|---|
| 104 | + status: PACK_STATUS.CREATED |
|---|
| 105 | + }); |
|---|
| 112 | 106 | } |
|---|
| 113 | 107 | } |
|---|
| 114 | 108 | |
|---|