diff --git a/app/View/Elements/global_menu.ctp b/app/View/Elements/global_menu.ctp index 60feef643..1935e0c87 100755 --- a/app/View/Elements/global_menu.ctp +++ b/app/View/Elements/global_menu.ctp @@ -526,4 +526,3 @@ - diff --git a/app/View/Events/index.ctp b/app/View/Events/index.ctp index cacdfb804..f54efefbe 100644 --- a/app/View/Events/index.ctp +++ b/app/View/Events/index.ctp @@ -127,6 +127,5 @@ echo $this->Html->css('distribution-graph'); echo $this->Html->script('network-distribution-graph'); ?> - element('/genericElements/SideMenu/side_menu', array('menuList' => 'event-collection', 'menuItem' => 'index')); diff --git a/app/View/Events/view.ctp b/app/View/Events/view.ctp index b52438a09..361adec22 100644 --- a/app/View/Events/view.ctp +++ b/app/View/Events/view.ctp @@ -580,4 +580,3 @@ $(function () { }); }); - diff --git a/app/View/Layouts/default.ctp b/app/View/Layouts/default.ctp index cea81bbc7..ae7fbd82f 100644 --- a/app/View/Layouts/default.ctp +++ b/app/View/Layouts/default.ctp @@ -33,7 +33,7 @@ )); ?> - +
@@ -71,7 +71,8 @@ 'bootstrap-datepicker', 'bootstrap-colorpicker', 'misp', - 'keyboard-shortcuts' + 'keyboard-shortcuts-definition', + 'keyboard-shortcuts', ) )); echo $this->element('footer'); diff --git a/app/webroot/js/keyboard-shortcuts-definition.js b/app/webroot/js/keyboard-shortcuts-definition.js new file mode 100644 index 000000000..bd6acbe3f --- /dev/null +++ b/app/webroot/js/keyboard-shortcuts-definition.js @@ -0,0 +1,61 @@ +function getShortcutsDefinition() { + var shortcuts = [ + { + "key": "l", + "description": "Go to event list", + "action": function () { + document.location.href = baseurl + '/events/index'; + } + }, + { + "key": "e", + "description": "Go to add event page", + "action": function () { + document.location.href = baseurl + '/events/add'; + } + } + ]; + + var $body = $(document.body); + if ($body.data('controller') === 'events' && $body.data('action') === 'view') { + shortcuts.push({ + "key": "t", + "description": "Open the tag selection modal", + "action": function () { + $('.addTagButton').first().click(); + } + }); + shortcuts.push({ + "key": "f", + "description": "Open the freetext import modal", + "action": function () { + $('#freetext-button').click(); + } + }); + shortcuts.push({ + "key": "a", + "description": "Add an attribute", + "action": function () { + $('#create-button').click(); + } + }); + shortcuts.push({ + "key": "s", + "description": "Focus the filter attribute bar", + "action": function () { + $('#quickFilterField').focus(); + } + }); + } + + if ($body.data('controller') === 'events' && $body.data('action') === 'index') { + shortcuts.push({ + "key": "s", + "description": "Focus the filter events bar", + "action": function () { + $('#quickFilterField').focus(); + } + }); + } + return shortcuts; +} diff --git a/app/webroot/js/keyboard-shortcuts.js b/app/webroot/js/keyboard-shortcuts.js index 56db0de2d..f2432e2a9 100644 --- a/app/webroot/js/keyboard-shortcuts.js +++ b/app/webroot/js/keyboard-shortcuts.js @@ -21,13 +21,7 @@ let keyboardShortcutsManager = { init() { /* Codacy comment to notify that baseurl is a read-only global variable. */ /* global baseurl */ - let shortcutURIs = []; - for(let keyboardShortcutElement of $('.keyboardShortcutsConfig')) { - shortcutURIs.push(keyboardShortcutElement.value); - this.ajaxGet(baseurl + keyboardShortcutElement.value).then((response) => { - this.mapKeyboardShortcuts(JSON.parse(response)); - }); - } + this.mapKeyboardShortcuts(getShortcutsDefinition()); this.setKeyboardListener(); }, @@ -61,7 +55,7 @@ let keyboardShortcutsManager = { * @param {} config The shortcut JSON list: [{key: string, description: string, action: string(eval-able JS code)}] */ mapKeyboardShortcuts(config) { - for(let shortcut of config.shortcuts) { + for(let shortcut of config) { this.shortcutKeys.set(shortcut.key, shortcut); } this.addShortcutListToHTML(); @@ -76,39 +70,14 @@ let keyboardShortcutsManager = { window.onkeyup = (keyboardEvent) => { if(this.shortcutKeys.has(keyboardEvent.key)) { let activeElement = document.activeElement.tagName; - if( !this.ESCAPED_TAG_NAMES.includes(activeElement)) { - eval(this.shortcutKeys.get(keyboardEvent.key).action); + if(!this.ESCAPED_TAG_NAMES.includes(activeElement)) { + this.shortcutKeys.get(keyboardEvent.key).action(); } } else if(this.NAVIGATION_KEYS.includes(keyboardEvent.key)) { window.dispatchEvent(new CustomEvent(this.EVENTS[keyboardEvent.key], {detail: keyboardEvent})); } } }, - - /** - * Queries the given URL with a GET request and returns a Promise - * that resolves when the response arrives. - * @param string url The URL to fetch. - */ - ajaxGet(url) { - return new Promise(function(resolve, reject) { - let req = new XMLHttpRequest(); - req.open("GET", url); - req.onload = function() { - if (req.status === 200) { - resolve(req.response); - } else { - reject(new Error(req.statusText)); - } - }; - - req.onerror = function() { - reject(new Error("Network error")); - }; - - req.send(); - }); - } } // Inits the keyboard shortcut manager's main routine and the click event on the keyboard shortcut triangle at the bottom of the screen. diff --git a/app/webroot/shortcuts/event_index.json b/app/webroot/shortcuts/event_index.json deleted file mode 100644 index 15e6fa1cb..000000000 --- a/app/webroot/shortcuts/event_index.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "shortcuts": [ - { - "key": "s", - "description": "Focus the filter events bar", - "action": "$('#quickFilterField').focus()" - } - ] -} \ No newline at end of file diff --git a/app/webroot/shortcuts/event_view.json b/app/webroot/shortcuts/event_view.json deleted file mode 100644 index c411c8802..000000000 --- a/app/webroot/shortcuts/event_view.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "shortcuts": [ - { - "key": "t", - "description": "Open the tag selection modal", - "action": "$('.addTagButton').first().click()" - }, - { - "key": "f", - "description": "Open the freetext import modal", - "action": "$('#freetext-button').click()" - }, - { - "key": "a", - "description": "Add an attribute", - "action": "$('#create-button').click()" - }, - { - "key": "s", - "description": "Focus the filter attribute bar", - "action": "$('#quickFilterField').focus()" - } - ] -} diff --git a/app/webroot/shortcuts/global_menu.json b/app/webroot/shortcuts/global_menu.json deleted file mode 100644 index 6ee3ca893..000000000 --- a/app/webroot/shortcuts/global_menu.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "shortcuts": [ - { - "key": "l", - "description": "Go to event list", - "action": "document.location.href = baseurl + '/events/index'" - }, - { - "key": "e", - "description": "Go to add event page", - "action": "document.location.href = baseurl + '/events/add'" - } - ] -} -