| .. | .. |
|---|
| 9 | 9 | import { TdMediaService } from '@covalent/core'; |
|---|
| 10 | 10 | import { FormBase, IComboOption } from './base'; |
|---|
| 11 | 11 | import { ActivatedRoute, Router } from '@angular/router'; |
|---|
| 12 | +import { UsersService } from "../resources/users"; |
|---|
| 12 | 13 | |
|---|
| 13 | 14 | var app_example = { |
|---|
| 14 | 15 | code: 'CICS', |
|---|
| .. | .. |
|---|
| 30 | 31 | }) |
|---|
| 31 | 32 | export class OrganizationFormComponent extends FormBase { |
|---|
| 32 | 33 | |
|---|
| 34 | + parentOrganizations: any[]; |
|---|
| 35 | + usernames: string[] = []; |
|---|
| 36 | + |
|---|
| 33 | 37 | constructor(private http: Http, |
|---|
| 34 | 38 | private licenseTypes: LicenseTypesService, |
|---|
| 35 | 39 | private organizations: OrganizationsService, |
|---|
| 40 | + private users: UsersService, |
|---|
| 36 | 41 | router: Router, |
|---|
| 37 | 42 | toaster: ToastsManager, |
|---|
| 38 | 43 | route: ActivatedRoute, |
|---|
| .. | .. |
|---|
| 41 | 46 | super($L, router, route, toaster, organizations, $L.get('organization'), dialogs); |
|---|
| 42 | 47 | } |
|---|
| 43 | 48 | |
|---|
| 44 | | - |
|---|
| 49 | + loadCombos() : void { |
|---|
| 50 | + this.organizations.get() |
|---|
| 51 | + .map(list => list.map((org : any) => <IComboOption>{id: org.id, label: `(${org.code}) ${org.name}`})) |
|---|
| 52 | + .subscribe( |
|---|
| 53 | + data => this.parentOrganizations = (<IComboOption[]>data).sort((e1, e2) => e1.label.localeCompare(e2.label)), |
|---|
| 54 | + err => console.error('Error loading organizations') |
|---|
| 55 | + ); |
|---|
| 56 | + this.users.get() |
|---|
| 57 | + .map(list => list |
|---|
| 58 | + .filter((user : any) => user.username !== '_client') |
|---|
| 59 | + .map((u : any) => u.username)) |
|---|
| 60 | + .subscribe( |
|---|
| 61 | + data => this.usernames = (<string[]>data).sort((u1, u2) => u1.localeCompare(u2)), |
|---|
| 62 | + err => console.error('Error loading users') |
|---|
| 63 | + ); |
|---|
| 64 | + } |
|---|
| 65 | + |
|---|
| 66 | + |
|---|
| 45 | 67 | goBack(): void { |
|---|
| 46 | 68 | this.router.navigate([`organizations`]); |
|---|
| 47 | 69 | } |
|---|
| 48 | 70 | |
|---|
| 49 | 71 | init() : void { |
|---|
| 72 | + this.loadCombos(); |
|---|
| 50 | 73 | super.setFirstFocus(); |
|---|
| 51 | 74 | super.reset(); |
|---|
| 52 | | - super.prepareInitialData('organizationId'); |
|---|
| 75 | + super.prepareInitialData('organizationId', {users_ids: []}); |
|---|
| 53 | 76 | } |
|---|
| 54 | 77 | |
|---|
| 55 | 78 | ngAfterViewInit(): void { |
|---|