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

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 {BatchService} from '../purchase-return/batch.service';
import {IssueGridService} from './issue-grid.service';
import {CostCentre} from '../cost-centre/cost-centre';
import {IssueGridDataSource} from './issue-grid-datasource';
import {Hotkey, HotkeysService} from "angular2-hotkeys";
@Component({
selector: 'app-issue',
templateUrl: './issue.component.html',
styleUrls: ['./issue.component.css']
})
export class IssueComponent implements OnInit, AfterViewInit {
export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
@ViewChild('batchElement') batchElement: ElementRef;
@ViewChild('dateElement') dateElement: ElementRef;
public inventoryObservable = new BehaviorSubject<Inventory[]>([]);
public gridObservable = new BehaviorSubject<any[]>([]);
dataSource: IssueDataSource;
@ -45,6 +47,7 @@ export class IssueComponent implements OnInit, AfterViewInit {
private router: Router,
private fb: FormBuilder,
private dialog: MatDialog,
private hotkeys: HotkeysService,
private toaster: ToasterService,
private auth: AuthService,
private ser: VoucherService,
@ -63,12 +66,27 @@ export class IssueComponent implements OnInit, AfterViewInit {
this.costCentres = data.costCentres;
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']));
}
ngAfterViewInit() {
this.focusBatch();
}
ngOnDestroy() {
this.hotkeys.reset();
}
loadVoucher(voucher: Voucher) {
this.voucher = voucher;
this.sourceJournal = this.voucher.journals.filter(x => x.debit === -1)[0];