From 60c65f2110f65221bc3a71b2887667e78c53c53e Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Wed, 22 Mar 2017 17:44:16 +0000
Subject: [PATCH] #3527 fix - Added pack/license actions and a lot of bugfixing

---
 securis/src/main/webapp/src/app/forms/user.form.component.ts |   61 ++++++++++++++++++++++++++++--
 1 files changed, 56 insertions(+), 5 deletions(-)

diff --git a/securis/src/main/webapp/src/app/forms/user.form.component.ts b/securis/src/main/webapp/src/app/forms/user.form.component.ts
index a709db6..c579366 100644
--- a/securis/src/main/webapp/src/app/forms/user.form.component.ts
+++ b/securis/src/main/webapp/src/app/forms/user.form.component.ts
@@ -9,6 +9,7 @@
 import { TdMediaService } from '@covalent/core';
 import { FormBase, IComboOption } from './base';
 import { ActivatedRoute, Router } from '@angular/router';
+import { OrganizationsService } from "../resources/organizations";
 
 var user_example = { 
     username: 'rym',
@@ -27,10 +28,14 @@
   templateUrl: 'src/app/forms/user.form.html'
 })
 export class UserFormComponent extends FormBase {
-
+  allOrganizations: IComboOption[];
+  orgNames: string[] = [];
+  allRoles: any[] = [{"id":1, "code": "advance", "label":"Advance"}, {"id":2, "code": "admin","label":"Admin"}];
+  user_orgs: string[] = [];
+  user_roles: any = {};
   constructor(private http: Http,
               private users: UsersService,
-              private applications: ApplicationsService,
+              private organizations: OrganizationsService,
               router: Router,
               toaster: ToastsManager,
               route: ActivatedRoute,              
@@ -39,16 +44,62 @@
     super($L, router, route, toaster, users, $L.get('user'), dialogs);
   }
 
- 
+  save() : void {
+    this.data.organizations_ids = [];
+    this.data.roles = [];
+    this.user_orgs.forEach(orgName => {
+      var selectedOrg = this.allOrganizations.find(org => org.label === orgName);
+      this.data.organizations_ids.push(selectedOrg.id);
+    });
+    this.user_roles.advance && this.data.roles.push(1);
+    this.user_roles.admin && this.data.roles.push(2);
+    super.save('username');
+  }
+
+  canBeDeleted() {
+    return this.data && this.data.username !== 'admin' && this.data.username !== '_client';
+  }
+
+  loadCombos() : void {
+      this.organizations.get()
+        .map(list => list.map((org : any) => <IComboOption>{id: org.id, label: org.name}))
+        .subscribe(
+          data => {
+            this.allOrganizations = (<IComboOption[]>data).sort((e1, e2) => e1.label.localeCompare(e2.label));
+            this.orgNames = this.allOrganizations.map(org => org.label);
+            this._loadOrgs();
+          },
+          err => console.error('Error loading organizations')
+        );
+  }
+
   goBack(): void {
     this.router.navigate([`users`]);
   }
-
+  _loadOrgs() {
+    if (this.data && this.data.organizations_ids && this.allOrganizations && this.allOrganizations.length > 0) { 
+      this.data.organizations_ids.forEach((orgId : number) => {
+          var selectedOrg = this.allOrganizations.find(org => org.id === orgId);
+          this.user_orgs.push(selectedOrg.label);
+      });
+    }
+  }
   init() : void {
+    this.loadCombos();
+    this.user_orgs = [];
+    this.user_roles = {};
     super.setFirstFocus();
     super.reset();
     super.prepareInitialData('username', {
-      metadata: []
+      organizations_ids: [],
+      roles: []
+    }, (data) => {
+       this._loadOrgs();
+        data.roles.forEach((roleId : number) => {
+            var selectedRole = this.allRoles.find(r => r.id === roleId);
+            this.user_roles[selectedRole.code] = true;
+        });        
+
     });
   }
  

--
Gitblit v1.3.2