]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/nav.component.ts
c477c116b9a507927e9f7d0ed51134695a234de4
[working/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 {AuthService} from '@eg/core/auth.service';
5 import {PcrudService} from '@eg/core/pcrud.service';
6 import {LocaleService} from '@eg/core/locale.service';
7 import {PrintService} from '@eg/share/print/print.service';
8
9 @Component({
10     selector: 'eg-staff-nav-bar',
11     styleUrls: ['nav.component.css'],
12     templateUrl: 'nav.component.html'
13 })
14
15 export class StaffNavComponent implements OnInit {
16
17     // Locales that have Angular staff translations
18     locales: any[];
19     currentLocale: any;
20
21     constructor(
22         private router: Router,
23         private auth: AuthService,
24         private pcrud: PcrudService,
25         private locale: LocaleService,
26         private printer: PrintService
27     ) {
28         this.locales = [];
29     }
30
31     ngOnInit() {
32
33         this.locale.supportedLocales().subscribe(
34             l => this.locales.push(l),
35             err => {},
36             () => {
37                 this.currentLocale = this.locales.filter(
38                     l => l.code() === this.locale.currentLocaleCode())[0];
39             }
40         );
41     }
42
43     user() {
44         return this.auth.user() ? this.auth.user().usrname() : '';
45     }
46
47     workstation() {
48         return this.auth.user() ? this.auth.workstation() : '';
49     }
50
51     setLocale(locale: any) {
52         this.locale.setLocale(locale.code());
53     }
54
55     opChangeActive(): boolean {
56         return this.auth.opChangeIsActive();
57     }
58
59     // Broadcast to all tabs that we're logging out.
60     // Redirect to the login page, which performs the remaining
61     // logout duties.
62     logout(): void {
63         this.auth.broadcastLogout();
64         this.router.navigate(['/staff/login']);
65     }
66
67     reprintLast() {
68         this.printer.reprintLast();
69     }
70 }
71
72