Feature: Added hotkeys in vouchers for selecting date (f2), save (ctrl+s) and post (ctrl+p)

This commit is contained in:
Amritanshu
2019-05-07 14:59:51 +05:30
parent 017c828474
commit 120b9544f8
21 changed files with 172 additions and 25 deletions
+25 -2
View File
@@ -1,4 +1,4 @@
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {AfterViewInit, Component, ElementRef, OnInit, OnDestroy, ViewChild} from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms';
import {MatAutocompleteSelectedEvent, MatDialog} from '@angular/material';
import {ActivatedRoute, Router} from '@angular/router';
@@ -16,14 +16,16 @@ import {ToasterService} from '../core/toaster.service';
import {debounceTime, distinctUntilChanged, map, startWith, switchMap} from 'rxjs/operators';
import {PaymentDialogComponent} from './payment-dialog.component';
import {ImageDialogComponent} from '../shared/image-dialog/image-dialog.component';
import {Hotkey, HotkeysService} from "angular2-hotkeys";
@Component({
selector: 'app-payment',
templateUrl: './payment.component.html',
styleUrls: ['./payment.component.css']
})
export class PaymentComponent implements OnInit, AfterViewInit {
export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
@ViewChild('accountElement') accountElement: ElementRef;
@ViewChild('dateElement') dateElement: ElementRef;
public journalObservable = new BehaviorSubject<Journal[]>([]);
dataSource: PaymentDataSource;
form: FormGroup;
@@ -42,6 +44,7 @@ export class PaymentComponent implements OnInit, AfterViewInit {
private router: Router,
private fb: FormBuilder,
private dialog: MatDialog,
private hotkeys: HotkeysService,
private toaster: ToasterService,
private auth: AuthService,
private ser: VoucherService,
@@ -59,12 +62,32 @@ export class PaymentComponent implements OnInit, AfterViewInit {
this.paymentAccounts = data.paymentAccounts;
this.loadVoucher(data.voucher);
});
this.hotkeys.add(new Hotkey('f2', (event: KeyboardEvent): boolean => {
setTimeout(() => {
this.dateElement.nativeElement.focus();
}, 0);
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
this.hotkeys.add(new Hotkey('ctrl+s', (event: KeyboardEvent): boolean => {
if (this.canSave())
this.save();
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
this.hotkeys.add(new Hotkey('ctrl+p', (event: KeyboardEvent): boolean => {
if (this.voucher.id && !this.voucher.posted && this.auth.user.perms.indexOf('Post Vouchers') !== -1)
this.post();
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
}
ngAfterViewInit() {
this.focusAccount();
}
ngOnDestroy() {
this.hotkeys.reset();
}
loadVoucher(voucher: Voucher) {
this.voucher = voucher;
this.paymentJournal = this.voucher.journals.filter(x => x.debit === -1)[0];