From 38b0782c887f046426c31766901906c614d73140 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Tue, 14 Mar 2017 13:51:56 +0000
Subject: [PATCH] #3527 feature - Added pack form

---
 securis/src/main/webapp/src/app/forms/pack.form.component.ts |   69 ++++++++++++++++++++++++++++++----
 1 files changed, 61 insertions(+), 8 deletions(-)

diff --git a/securis/src/main/webapp/src/app/forms/pack.form.component.ts b/securis/src/main/webapp/src/app/forms/pack.form.component.ts
index 852dba3..53858be 100644
--- a/securis/src/main/webapp/src/app/forms/pack.form.component.ts
+++ b/securis/src/main/webapp/src/app/forms/pack.form.component.ts
@@ -1,11 +1,16 @@
 import { Http } from '@angular/http';
+import { ToastsManager } from 'ng2-toastr/ng2-toastr';
+
 import { PacksService } from '../resources/packs';
+import { LicenseTypesService } from '../resources/license_types';
 import { LocaleService } from '../common/i18n';
 import { TdDataTableService, TdDataTableSortingOrder, ITdDataTableSortChangeEvent, ITdDataTableColumn } from '@covalent/core';
 import { IPageChangeEvent } from '@covalent/core';
 import { Component, AfterViewInit } from '@angular/core';
 import { TdMediaService } from '@covalent/core';
 import { IComboOption } from './base';
+
+
 
 @Component({
   selector: 'pack-form',
@@ -19,11 +24,35 @@
   licensetypes : IComboOption[];
   data: any = {};
   isNew : boolean = true;
-
+  fields: any = {
+    'code': '',
+    'num_licenses': '',
+    'init_valid_date': '',
+    'end_valid_date': '',
+    'license_preactivation': '',
+    'license_type_id': '',
+    'organization_id': '',
+    'licensetype_code': '',
+    'organization_name': '',
+    'preactivation_valid_period': '',
+    'renew_valid_period': '',
+    'application_name': '',
+    'status': '',
+    'metadata': '',
+    'comments': '',
+    'key': '',
+    'value': '',
+  }
   constructor(private http: Http,
+              private toaster: ToastsManager,
+              private licenseTypes: LicenseTypesService,
               private packs: PacksService,
               private $L: LocaleService) {
-      
+      Object.keys(this.fields).forEach(k => this.fields[k] = $L.get(`field.${k}`));
+  }
+
+  public getFieldName(fieldId: string) : string {
+    return this.fields[fieldId];
   }
 
   private loadCombos(): void {
@@ -33,23 +62,47 @@
           data => this.organizations = (<IComboOption[]>data).sort((e1, e2) => e1.label.localeCompare(e2.label)),
           err => console.error('Error loading orgs')
         );
-      this.http.get('licensetype')
-        .map(response => response.json().map((lt : any) => <IComboOption>{id: lt.id, label: `(${lt.code}) ${lt.name}`}))
+      this.licenseTypes.get()
+        .map(list => list.map((lt : any) => <IComboOption>{id: lt.id, label: `(${lt.code}) ${lt.name}`}))
         .subscribe(
           data => this.licensetypes = (<IComboOption[]>data).sort((e1, e2) => e1.label.localeCompare(e2.label)),
           err => console.error('Error loading license types')
         );
   }
 
-  log(obj: any) {
-    console.log(obj)
+  save() {
+      var command = this.isNew ? this.packs.create(this.data) : this.packs.modify(this.data.id, this.data);
+      command.subscribe(
+          data => this.toaster.success(this.$L.get('Pack saved sucessfully')),
+          err => {
+            console.error(err);
+            this.toaster.success(this.$L.get('Error saving pack'));
+          }
+        );
   }
+  
+  changeLicType(event) {
+    this.licenseTypes.get(this.data.license_type_id)
+        .map(lt_data => lt_data.metadata)
+        .subscribe(
+          metadata => this.data.metadata = metadata,
+          err => {
+            console.error('Error loading license type metadata');
+            console.error(err);
+          }
+        );
+  }
+
+  changeOrg(event) {
+    console.log(event);
+    console.log(this.data.organization_id);
+  } 
   
   ngOnInit(): void {
     this.loadCombos();
-    this.data = {};
+    // this.data = {};
     this.form_title = this.$L.get('Pack data');
-    this.form_subtitle = this.$L.get('Create a new licenses pack');
+    this.form_subtitle = this.$L.get(this.isNew ? 'Create a new licenses pack': 'Modify the licenses pack data') ;
   }
 
 

--
Gitblit v1.3.2