Tarea #653 Crear shortcuts
This commit is contained in:
parent
ec960eab76
commit
899f9b3fe5
|
@ -0,0 +1,6 @@
|
|||
[
|
||||
{key: r, sref: claim.index},
|
||||
{key: c, sref: client.index},
|
||||
{key: a, sref: item.index},
|
||||
{key: t, sref: ticket.index},
|
||||
]
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue