diff --git a/client/salix/src/global-keybindings.yml b/client/salix/src/global-keybindings.yml new file mode 100644 index 000000000..dd625ea2f --- /dev/null +++ b/client/salix/src/global-keybindings.yml @@ -0,0 +1,6 @@ +[ + {key: r, sref: claim.index}, + {key: c, sref: client.index}, + {key: a, sref: item.index}, + {key: t, sref: ticket.index}, +] \ No newline at end of file diff --git a/client/salix/src/module.js b/client/salix/src/module.js index daa515e66..eba676b7c 100644 --- a/client/salix/src/module.js +++ b/client/salix/src/module.js @@ -1,13 +1,14 @@ import {ng} from 'vendor'; import 'core'; +import keybindings from './global-keybindings.yml'; export const appName = 'salix'; const ngModule = ng.module('salix', ['vnCore']); export default ngModule; -run.$inject = ['$window', '$rootScope', 'vnApp', '$state']; -export function run($window, $rootScope, vnApp, $state) { +run.$inject = ['$window', '$rootScope', 'vnApp', '$state', '$document']; +export function run($window, $rootScope, vnApp, $state, $document) { $window.validations = {}; vnApp.name = appName; @@ -17,6 +18,33 @@ export function run($window, $rootScope, vnApp, $state) { if (error.type === 3) // ABORTED_TRANSITION window.myAppErrorLog.push(error); }); + + for (const binding in keybindings) { + if (!keybindings[binding].key || !keybindings[binding].sref) + throw new Error('Binding not formed correctly'); + + $document.on("keyup", function(e) { + if (e.defaultPrevented) return; + + let shortcut = { + altKey: true, + ctrlKey: true, + key: keybindings[binding].key + }; + + let correctShortcut = true; + + for (const key in shortcut) { + correctShortcut = correctShortcut && shortcut[key] == e[key]; + } + + if (correctShortcut) { + $state.go(keybindings[binding].sref); + e.preventDefault(); + e.stopImmediatePropagation(); + } + }); + } } ngModule.run(run);