diff options
author | Romulus Tsai 蔡仲明 <urakagi@gmail.com> | 2020-05-08 09:35:11 +0800 |
---|---|---|
committer | Romulus Tsai 蔡仲明 <urakagi@gmail.com> | 2020-05-08 09:35:11 +0800 |
commit | cfcc73724fcd394150d1b815d0a7a4c466e216b5 (patch) | |
tree | a9648255f14cd8b0e1ad8eee1f8d42337a0668bc /client/lib/keyboard.js | |
parent | a3658993128bdddd5d40f792c19281dc5eac51f5 (diff) | |
parent | 533bc045d06269dba2f42cdfe61817a1b3407974 (diff) | |
download | wekan-cfcc73724fcd394150d1b815d0a7a4c466e216b5.tar.gz wekan-cfcc73724fcd394150d1b815d0a7a4c466e216b5.tar.bz2 wekan-cfcc73724fcd394150d1b815d0a7a4c466e216b5.zip |
Merge branch 'master' of https://github.com/wekan/wekan
Diffstat (limited to 'client/lib/keyboard.js')
-rwxr-xr-x | client/lib/keyboard.js | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/client/lib/keyboard.js b/client/lib/keyboard.js index d3f974be..e861e416 100755 --- a/client/lib/keyboard.js +++ b/client/lib/keyboard.js @@ -1,6 +1,16 @@ // XXX There is no reason to define these shortcuts globally, they should be // attached to a template (most of them will go in the `board` template). +function getHoveredCardId() { + const card = $('.js-minicard:hover').get(0); + if (!card) return null; + return Blaze.getData(card)._id; +} + +function getSelectedCardId() { + return Session.get('selectedCard') || getHoveredCardId(); +} + Mousetrap.bind('?', () => { FlowRouter.go('shortcuts'); }); @@ -50,9 +60,9 @@ Mousetrap.bind(['down', 'up'], (evt, key) => { } }); -// XXX This shortcut should also work when hovering over a card in board view Mousetrap.bind('space', evt => { - if (!Session.get('currentCard')) { + const cardId = getSelectedCardId(); + if (!cardId) { return; } @@ -62,7 +72,7 @@ Mousetrap.bind('space', evt => { } if (Meteor.user().isBoardMember()) { - const card = Cards.findOne(Session.get('currentCard')); + const card = Cards.findOne(cardId); card.toggleMember(currentUserId); // We should prevent scrolling in card when spacebar is clicked // This should do it according to Mousetrap docs, but it doesn't @@ -70,22 +80,46 @@ Mousetrap.bind('space', evt => { } }); +Mousetrap.bind('c', evt => { + const cardId = getSelectedCardId(); + if (!cardId) { + return; + } + + const currentUserId = Meteor.userId(); + if (currentUserId === null) { + return; + } + + if ( + Meteor.user().isBoardMember() && + !Meteor.user().isCommentOnly() && + !Meteor.user().isWorker() + ) { + const card = Cards.findOne(cardId); + card.archive(); + // We should prevent scrolling in card when spacebar is clicked + // This should do it according to Mousetrap docs, but it doesn't + evt.preventDefault(); + } +}); + Template.keyboardShortcuts.helpers({ mapping: [ { - keys: ['W'], + keys: ['w'], action: 'shortcut-toggle-sidebar', }, { - keys: ['Q'], + keys: ['q'], action: 'shortcut-filter-my-cards', }, { - keys: ['F'], + keys: ['f'], action: 'shortcut-toggle-filterbar', }, { - keys: ['X'], + keys: ['x'], action: 'shortcut-clear-filters', }, { @@ -104,5 +138,9 @@ Template.keyboardShortcuts.helpers({ keys: ['SPACE'], action: 'shortcut-assign-self', }, + { + keys: ['c'], + action: 'archive-card', + }, ], }); |