shortcuts

This commit is contained in:
Yuri Kuznetsov
2022-07-31 17:31:40 +03:00
parent e67a1b67ed
commit 3dd82aa61e
8 changed files with 115 additions and 11 deletions
@@ -36,11 +36,12 @@
"list":{
"buttons":[
{
"label":"Compose",
"action":"composeEmail",
"style":"danger",
"acl":"create",
"className": "btn-s-wide"
"label": "Compose",
"action": "composeEmail",
"style": "danger",
"acl": "create",
"className": "btn-s-wide",
"title": "Ctrl+Space"
}
],
"dropdown":[
+1 -1
View File
@@ -1,5 +1,5 @@
<header id="header">{{{header}}}</header>
<div id="content" class="container content">
<div id="main">{{{main}}}</div>
<div id="main" tabindex="-1">{{{main}}}</div>
</div>
<footer id="footer">{{{footer}}}</footer>
+18
View File
@@ -208,5 +208,23 @@ define('views/email/list', 'views/list', function (Dep) {
}
},
/**
* @protected
* @param {JQueryKeyEventObject} e
*/
handleShortcutKeyCtrlSpace: function (e) {
if (e.target.tagName === 'TEXTAREA' || e.target.tagName === 'INPUT') {
return;
}
if (!this.getAcl().checkScope(this.scope, 'create')) {
return;
}
e.preventDefault();
e.stopPropagation();
this.actionComposeEmail();
},
});
});
+2
View File
@@ -225,6 +225,8 @@ define('views/list-with-categories', ['views/list'], function (Dep) {
if (!this.isExpanded && !this.hasView('nestedCategories')) {
this.loadNestedCategories();
}
this.$el.focus();
},
actionExpand: function () {
+42
View File
@@ -155,6 +155,15 @@ function (Dep, /** typeof module:search-manager.Class */SearchManager) {
*/
defaultViewMode: 'list',
/**
* @inheritDoc
*/
shortcutKeys: {
'Control+Space': function (e) {
this.handleShortcutKeyCtrlSpace(e);
},
},
/**
* @inheritDoc
*/
@@ -286,6 +295,7 @@ function (Dep, /** typeof module:search-manager.Class */SearchManager) {
style: 'default',
acl: 'create',
aclScope: this.entityType || this.scope,
title: 'Ctrl+Space',
});
return;
@@ -299,6 +309,7 @@ function (Dep, /** typeof module:search-manager.Class */SearchManager) {
style: 'default',
acl: 'create',
aclScope: this.entityType || this.scope,
title: 'Ctrl+Space',
});
},
@@ -466,6 +477,8 @@ function (Dep, /** typeof module:search-manager.Class */SearchManager) {
if (!this.hasView('list')) {
this.loadList();
}
this.$el.focus();
},
/**
@@ -716,5 +729,34 @@ function (Dep, /** typeof module:search-manager.Class */SearchManager) {
isActualForReuse: function () {
return this.collection.isFetched;
},
/**
* @protected
* @param {JQueryKeyEventObject} e
*/
handleShortcutKeyCtrlSpace: function (e) {
if (!this.createButton) {
return;
}
if (e.target.tagName === 'TEXTAREA' || e.target.tagName === 'INPUT') {
return;
}
if (!this.getAcl().checkScope(this.scope, 'create')) {
return;
}
e.preventDefault();
e.stopPropagation();
if (this.quickCreate) {
this.actionQuickCreate();
return;
}
this.actionCreate();
},
});
});
+39
View File
@@ -90,6 +90,14 @@ define('views/main', ['view'], function (Dep) {
*/
$headerActionsContainer: null,
/**
* A shortcut-key => action map.
*
* @protected
* @type {?Object.<string,string|function (JQueryKeyEventObject): void>}
*/
shortcutKeys: null,
/**
* @inheritDoc
*/
@@ -162,6 +170,37 @@ define('views/main', ['view'], function (Dep) {
});
this.on('after:render', () => this.adjustButtons());
if (this.shortcutKeys) {
this.shortcutKeys = Espo.Utils.cloneDeep(this.shortcutKeys);
}
},
setupFinal: function () {
if (this.shortcutKeys) {
this.events['keydown.main'] = e => {
let key = Espo.Utils.getKeyFromKeyEvent(e);
if (typeof this.shortcutKeys[key] === 'function') {
this.shortcutKeys[key].call(this, e);
return;
}
let actionName = this.shortcutKeys[key];
if (!actionName) {
return;
}
e.preventDefault();
e.stopPropagation();
let methodName = 'action' + Espo.Utils.upperCaseFirst(actionName);
this[methodName]();
};
}
},
/**
+3 -5
View File
@@ -1494,8 +1494,6 @@ function (Dep, ViewRecordHelper, ActionItemSetup) {
if (this.shortcutKeys) {
this.shortcutKeys = Espo.Utils.cloneDeep(this.shortcutKeys);
}
Bull.View.prototype.init.call(this);
},
isDropdownItemListEmpty: function () {
@@ -1930,10 +1928,10 @@ function (Dep, ViewRecordHelper, ActionItemSetup) {
this[methodName]();
};
}
if (!this.options.focusForCreate) {
this.once('after:render', () => this.focusOnFirstDiv());
}
if (!this.options.focusForCreate) {
this.once('after:render', () => this.focusOnFirstDiv());
}
},
+4
View File
@@ -13,3 +13,7 @@ body > footer > p a:active,
body > footer > p a:visited {
color: var(--site-footer-color);
}
#content > #main[tabindex="-1"] {
outline: none;
}