(js,css) Improve keyboard shortcuts

- Defined some hotkeys in all modules;
- Added generation of cheat sheet.
This commit is contained in:
Francis Lachapelle
2016-09-27 15:19:24 -04:00
parent 13dd21bebb
commit 57a735753f
21 changed files with 630 additions and 74 deletions
@@ -6,9 +6,9 @@
/**
* @ngInject
*/
CalendarController.$inject = ['$scope', '$rootScope', '$state', '$stateParams', 'Calendar', 'Component', 'Preferences', 'stateEventsBlocks'];
function CalendarController($scope, $rootScope, $state, $stateParams, Calendar, Component, Preferences, stateEventsBlocks) {
var vm = this, deregisterCalendarsList;
CalendarController.$inject = ['$scope', '$rootScope', '$state', '$stateParams', 'sgHotkeys', 'Calendar', 'Component', 'Preferences', 'stateEventsBlocks'];
function CalendarController($scope, $rootScope, $state, $stateParams, sgHotkeys, Calendar, Component, Preferences, stateEventsBlocks) {
var vm = this, deregisterCalendarsList, hotkeys = [];
// Make the toolbar state of all-day events persistent
if (angular.isUndefined(CalendarController.expandedAllDays))
@@ -21,6 +21,9 @@
vm.changeDate = changeDate;
vm.changeView = changeView;
_registerHotkeys(hotkeys);
Preferences.ready().then(function() {
_formatDate(vm.selectedDate);
});
@@ -28,8 +31,84 @@
// Refresh current view when the list of calendars is modified
deregisterCalendarsList = $rootScope.$on('calendars:list', updateView);
// Destroy event listener when the controller is being deactivated
$scope.$on('$destroy', deregisterCalendarsList);
$scope.$on('$destroy', function() {
// Destroy event listener when the controller is being deactivated
deregisterCalendarsList();
// Deregister hotkeys
_.forEach(hotkeys, function(key) {
sgHotkeys.deregisterHotkey(key);
});
});
function _registerHotkeys(keys) {
keys.push(sgHotkeys.createHotkey({
key: l('hotkey_today'),
description: l('Today'),
callback: changeDate,
args: new Date()
}));
keys.push(sgHotkeys.createHotkey({
key: l('hotkey_dayview'),
description: l('Day'),
callback: changeView,
args: 'day'
}));
keys.push(sgHotkeys.createHotkey({
key: l('hotkey_weekview'),
description: l('Week'),
callback: changeView,
args: 'week'
}));
keys.push(sgHotkeys.createHotkey({
key: l('hotkey_monthview'),
description: l('Month'),
callback: changeView,
args: 'month'
}));
keys.push(sgHotkeys.createHotkey({
key: l('hotkey_multicolumndayview'),
description: l('Multicolumn Day View'),
callback: changeView,
args: 'multicolumnday'
}));
keys.push(sgHotkeys.createHotkey({
key: 'left',
description: l('Move backward'),
callback: _goToPeriod,
args: -1
}));
keys.push(sgHotkeys.createHotkey({
key: 'right',
description: l('Move forward'),
callback: _goToPeriod,
args: +1
}));
// Register the hotkeys
_.forEach(keys, function(key) {
sgHotkeys.registerHotkey(key);
});
}
function _goToPeriod($event, direction) {
var date;
if ($stateParams.view == 'week') {
date = vm.selectedDate.beginOfWeek(Preferences.defaults.SOGoFirstDayOfWeek).addDays(7 * direction);
}
else if ($stateParams.view == 'month') {
date = vm.selectedDate;
date.setDate(1);
date.setMonth(date.getMonth() + direction);
}
else {
date = vm.selectedDate.addDays(direction);
}
changeDate($event, date);
}
function _formatDate(date) {
if ($stateParams.view == 'month') {
@@ -75,7 +154,7 @@
}
// Change calendar's view
function changeView(view) {
function changeView($event, view) {
$state.go('calendars.view', { view: view });
}
}
@@ -6,9 +6,9 @@
/**
* @ngInject
*/
CalendarListController.$inject = ['$rootScope', '$timeout', '$state', '$mdDialog', 'Dialog', 'Preferences', 'Calendar', 'Component'];
function CalendarListController($rootScope, $timeout, $state, $mdDialog, Dialog, Preferences, Calendar, Component) {
var vm = this;
CalendarListController.$inject = ['$rootScope', '$scope', '$timeout', '$state', '$mdDialog', 'sgHotkeys', 'sgFocus', 'Dialog', 'Preferences', 'Calendar', 'Component'];
function CalendarListController($rootScope, $scope, $timeout, $state, $mdDialog, sgHotkeys, focus, Dialog, Preferences, Calendar, Component) {
var vm = this, hotkeys = [];
vm.component = Component;
vm.componentType = 'events';
@@ -16,6 +16,7 @@
vm.selectComponentType = selectComponentType;
vm.unselectComponents = unselectComponents;
vm.selectAll = selectAll;
vm.searchMode = searchMode;
vm.toggleComponentSelection = toggleComponentSelection;
vm.confirmDeleteSelectedComponents = confirmDeleteSelectedComponents;
vm.openEvent = openEvent;
@@ -30,6 +31,9 @@
vm.cancelSearch = cancelSearch;
vm.mode = { search: false, multiple: 0 };
_registerHotkeys(hotkeys);
// Select list based on user's settings
Preferences.ready().then(function() {
var type = 'events';
@@ -48,6 +52,39 @@
// Update the component being dragged
$rootScope.$on('calendar:dragend', updateComponentFromGhost);
$scope.$on('$destroy', function() {
// Deregister hotkeys
_.forEach(hotkeys, function(key) {
sgHotkeys.deregisterHotkey(key);
});
});
function _registerHotkeys(keys) {
keys.push(sgHotkeys.createHotkey({
key: l('hotkey_search'),
description: l('Search'),
callback: searchMode
}));
keys.push(sgHotkeys.createHotkey({
key: l('hotkey_create_event'),
description: l('Create a new event'),
callback: newComponent,
args: 'appointment'
}));
keys.push(sgHotkeys.createHotkey({
key: l('hotkey_create_task'),
description: l('Create a new task'),
callback: newComponent,
args: 'task'
}));
// Register the hotkeys
_.forEach(keys, function(key) {
sgHotkeys.registerHotkey(key);
});
}
// Switch between components tabs
function selectComponentType(type, options) {
if (options && options.reload || vm.componentType != type) {
@@ -80,6 +117,11 @@
$event.stopPropagation();
}
function searchMode() {
vm.mode.search = true;
focus('search');
}
function confirmDeleteSelectedComponents() {
Dialog.confirm(l('Warning'),
l('Are you sure you want to delete the selected components?'),
@@ -317,7 +359,7 @@
Component.$filter(vm.componentType, { value: '' });
}
}
angular
.module('SOGo.SchedulerUI')
.controller('CalendarListController', CalendarListController);