]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/nav.component.ts
LP1615805 No inputs after submit in patron search (AngularJS)
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / nav.component.ts
1 import {Component, OnInit, ViewChild} from '@angular/core';
2 import {ActivatedRoute, Router} from '@angular/router';
3 import {Location} from '@angular/common';
4 import {OrgService} from '@eg/core/org.service';
5 import {AuthService} from '@eg/core/auth.service';
6 import {PcrudService} from '@eg/core/pcrud.service';
7 import {LocaleService} from '@eg/core/locale.service';
8 import {PrintService} from '@eg/share/print/print.service';
9
10 @Component({
11     selector: 'eg-staff-nav-bar',
12     styleUrls: ['nav.component.css'],
13     templateUrl: 'nav.component.html'
14 })
15
16 export class StaffNavComponent implements OnInit {
17
18     // Locales that have Angular staff translations
19     locales: any[];
20     currentLocale: any;
21
22     // When active, show a link to the experimental Angular staff catalog
23     showAngularCatalog: boolean;
24
25     constructor(
26         private router: Router,
27         private org: OrgService,
28         private auth: AuthService,
29         private pcrud: PcrudService,
30         private locale: LocaleService,
31         private printer: PrintService
32     ) {
33         this.locales = [];
34     }
35
36     ngOnInit() {
37
38         this.locale.supportedLocales().subscribe(
39             l => this.locales.push(l),
40             err => {},
41             () => {
42                 this.currentLocale = this.locales.filter(
43                     l => l.code() === this.locale.currentLocaleCode())[0];
44             }
45         );
46
47         // NOTE: this can eventually go away.
48         // Avoid attempts to fetch org settings if the user has not yet
49         // logged in (e.g. this is the login page).
50         if (this.user()) {
51             this.org.settings('ui.staff.angular_catalog.enabled')
52             .then(settings => this.showAngularCatalog =
53                 Boolean(settings['ui.staff.angular_catalog.enabled']));
54         }
55     }
56
57     user() {
58         return this.auth.user() ? this.auth.user().usrname() : '';
59     }
60
61     workstation() {
62         return this.auth.user() ? this.auth.workstation() : '';
63     }
64
65     setLocale(locale: any) {
66         this.locale.setLocale(locale.code());
67     }
68
69     opChangeActive(): boolean {
70         return this.auth.opChangeIsActive();
71     }
72
73     // Broadcast to all tabs that we're logging out.
74     // Redirect to the login page, which performs the remaining
75     // logout duties.
76     logout(): void {
77         this.auth.broadcastLogout();
78         this.router.navigate(['/staff/login']);
79     }
80
81     reprintLast() {
82         this.printer.reprintLast();
83     }
84 }
85
86