rsanchez
2017-03-19 280daa7f3f858ecfef9c91ffd5dea1007f021048
securis/src/main/webapp/src/app/forms/pack.form.component.ts
....@@ -8,7 +8,8 @@
88 import { IPageChangeEvent } from '@covalent/core';
99 import { Component, AfterViewInit } from '@angular/core';
1010 import { TdMediaService } from '@covalent/core';
11
-import { IComboOption } from './base';
11
+import { IComboOption, FormBase } from './base';
12
+import { ActivatedRoute, Router } from '@angular/router';
1213
1314
1415
....@@ -16,10 +17,8 @@
1617 selector: 'pack-form',
1718 templateUrl: 'src/app/forms/pack.form.html'
1819 })
19
-export class PackFormComponent implements AfterViewInit {
20
+export class PackFormComponent extends FormBase implements AfterViewInit {
2021
21
- form_title: string = 'Title';
22
- form_subtitle: string = '';
2322 organizations : IComboOption[];
2423 licensetypes : IComboOption[];
2524 data: any = {};
....@@ -44,18 +43,20 @@
4443 'value': '',
4544 }
4645 constructor(private http: Http,
47
- private toaster: ToastsManager,
46
+ toaster: ToastsManager,
4847 private licenseTypes: LicenseTypesService,
48
+ route: ActivatedRoute,
49
+ private router: Router,
4950 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'));
5253 }
5354
5455 public getFieldName(fieldId: string) : string {
5556 return this.fields[fieldId];
5657 }
5758
58
- private loadCombos(): void {
59
+ loadCombos(): void {
5960 this.http.get('organization')
6061 .map(response => response.json().map((org : any) => <IComboOption>{id: org.id, label: `(${org.code}) ${org.name}`}))
6162 .subscribe(
....@@ -70,15 +71,9 @@
7071 );
7172 }
7273
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`]);
8277 }
8378
8479 changeLicType(event: any) {
....@@ -99,16 +94,15 @@
9994 }
10095
10196 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
+
10898 }
10999
110100
111101 ngAfterViewInit(): void {
102
+ this.loadCombos();
103
+ super.prepareData('packId', {
104
+ status: PACK_STATUS.CREATED
105
+ });
112106 }
113107 }
114108