rsanchez
2017-03-14 38b0782c887f046426c31766901906c614d73140
securis/src/main/webapp/src/app/forms/pack.form.component.ts
....@@ -1,11 +1,16 @@
11 import { Http } from '@angular/http';
2
+import { ToastsManager } from 'ng2-toastr/ng2-toastr';
3
+
24 import { PacksService } from '../resources/packs';
5
+import { LicenseTypesService } from '../resources/license_types';
36 import { LocaleService } from '../common/i18n';
47 import { TdDataTableService, TdDataTableSortingOrder, ITdDataTableSortChangeEvent, ITdDataTableColumn } from '@covalent/core';
58 import { IPageChangeEvent } from '@covalent/core';
69 import { Component, AfterViewInit } from '@angular/core';
710 import { TdMediaService } from '@covalent/core';
811 import { IComboOption } from './base';
12
+
13
+
914
1015 @Component({
1116 selector: 'pack-form',
....@@ -19,11 +24,35 @@
1924 licensetypes : IComboOption[];
2025 data: any = {};
2126 isNew : boolean = true;
22
-
27
+ fields: any = {
28
+ 'code': '',
29
+ 'num_licenses': '',
30
+ 'init_valid_date': '',
31
+ 'end_valid_date': '',
32
+ 'license_preactivation': '',
33
+ 'license_type_id': '',
34
+ 'organization_id': '',
35
+ 'licensetype_code': '',
36
+ 'organization_name': '',
37
+ 'preactivation_valid_period': '',
38
+ 'renew_valid_period': '',
39
+ 'application_name': '',
40
+ 'status': '',
41
+ 'metadata': '',
42
+ 'comments': '',
43
+ 'key': '',
44
+ 'value': '',
45
+ }
2346 constructor(private http: Http,
47
+ private toaster: ToastsManager,
48
+ private licenseTypes: LicenseTypesService,
2449 private packs: PacksService,
2550 private $L: LocaleService) {
26
-
51
+ Object.keys(this.fields).forEach(k => this.fields[k] = $L.get(`field.${k}`));
52
+ }
53
+
54
+ public getFieldName(fieldId: string) : string {
55
+ return this.fields[fieldId];
2756 }
2857
2958 private loadCombos(): void {
....@@ -33,23 +62,47 @@
3362 data => this.organizations = (<IComboOption[]>data).sort((e1, e2) => e1.label.localeCompare(e2.label)),
3463 err => console.error('Error loading orgs')
3564 );
36
- this.http.get('licensetype')
37
- .map(response => response.json().map((lt : any) => <IComboOption>{id: lt.id, label: `(${lt.code}) ${lt.name}`}))
65
+ this.licenseTypes.get()
66
+ .map(list => list.map((lt : any) => <IComboOption>{id: lt.id, label: `(${lt.code}) ${lt.name}`}))
3867 .subscribe(
3968 data => this.licensetypes = (<IComboOption[]>data).sort((e1, e2) => e1.label.localeCompare(e2.label)),
4069 err => console.error('Error loading license types')
4170 );
4271 }
4372
44
- log(obj: any) {
45
- console.log(obj)
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
+ );
4682 }
83
+
84
+ changeLicType(event) {
85
+ this.licenseTypes.get(this.data.license_type_id)
86
+ .map(lt_data => lt_data.metadata)
87
+ .subscribe(
88
+ metadata => this.data.metadata = metadata,
89
+ err => {
90
+ console.error('Error loading license type metadata');
91
+ console.error(err);
92
+ }
93
+ );
94
+ }
95
+
96
+ changeOrg(event) {
97
+ console.log(event);
98
+ console.log(this.data.organization_id);
99
+ }
47100
48101 ngOnInit(): void {
49102 this.loadCombos();
50
- this.data = {};
103
+ // this.data = {};
51104 this.form_title = this.$L.get('Pack data');
52
- this.form_subtitle = this.$L.get('Create a new licenses pack');
105
+ this.form_subtitle = this.$L.get(this.isNew ? 'Create a new licenses pack': 'Modify the licenses pack data') ;
53106 }
54107
55108