Skip to content

Commit cc17ff2

Browse files
author
gibus
committed
Add user config option to disable keyboard shortcuts
1 parent e251e33 commit cc17ff2

File tree

3 files changed

+116
-101
lines changed

3 files changed

+116
-101
lines changed

lib/RT/Config.pm

+9
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,15 @@ our %META;
437437
Description => 'Enable URL shortener', #loc
438438
},
439439
},
440+
KeyBoardShortcuts => {
441+
Section => 'General', #loc
442+
Overridable => 1,
443+
SortOrder => 13,
444+
Widget => '/Widgets/Form/Boolean',
445+
WidgetArguments => {
446+
Description => 'Enable keyboards shortcuts', #loc
447+
},
448+
},
440449

441450
# User overridable options for RT at a glance
442451
HomePageRefreshInterval => {

share/html/Elements/JavascriptConfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
my $Config = {};
5050
$Config->{$_} = RT->Config->Get( $_, $session{CurrentUser} )
5151
for qw(rtname WebPath MessageBoxRichText MessageBoxRichTextHeight
52-
MaxAttachmentSize WebDefaultStylesheet QuoteSelectedText );
52+
MaxAttachmentSize WebDefaultStylesheet QuoteSelectedText KeyBoardShortcuts );
5353

5454
# JS-only config value. Setting default here, can be reset with
5555
# the Data callback below.

share/static/js/keyboard-shortcuts.js

+106-100
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
jQuery(function() {
2+
if (RT.Config.KeyBoardShortcuts) {
23
var goBack = function() {
34
window.history.back();
45
};
@@ -68,110 +69,115 @@ jQuery(function() {
6869
Mousetrap.bind('g h', goHome);
6970
Mousetrap.bind('/', simpleSearch);
7071
Mousetrap.bind('?', openHelp);
72+
}
7173
});
7274

7375
jQuery(function() {
74-
// Only load these shortcuts if there is a ticket list on the page
75-
var hasTicketList = jQuery('table.ticket-list').length;
76-
if (!hasTicketList) return;
77-
78-
var currentRow;
79-
80-
var nextTicket = function() {
81-
var nextRow;
82-
var searchResultsTable = jQuery('.ticket-list.collection-as-table');
83-
if (!currentRow || !(nextRow = currentRow.next('tbody.list-item')).length) {
84-
nextRow = searchResultsTable.find('tbody.list-item').first();
85-
}
86-
setNewRow(nextRow);
87-
};
88-
89-
var setNewRow = function(newRow) {
90-
if (currentRow) currentRow.removeClass('selected-row');
91-
currentRow = newRow;
92-
currentRow.addClass('selected-row');
93-
scrollToJQueryObject(currentRow);
94-
};
95-
96-
var prevTicket = function() {
97-
var prevRow, searchResultsTable = jQuery('.ticket-list.collection-as-table');
98-
if (!currentRow || !(prevRow = currentRow.prev('tbody.list-item')).length) {
99-
prevRow = searchResultsTable.find('tbody.list-item').last();
100-
}
101-
setNewRow(prevRow);
102-
};
103-
104-
var generateTicketLink = function(ticketId) {
105-
if (!ticketId) return '';
106-
return RT.Config.WebHomePath + '/Ticket/Display.html?id=' + ticketId;
107-
};
108-
109-
var generateUpdateLink = function(ticketId, action) {
110-
if (!ticketId) return '';
111-
return RT.Config.WebHomePath + '/Ticket/Update.html?Action=' + action + '&id=' + ticketId;
112-
};
113-
114-
var navigateToCurrentTicket = function() {
115-
if (!currentRow) return;
116-
117-
var ticketId = currentRow.closest('tbody').data('recordId');
118-
var ticketLink = generateTicketLink(ticketId);
119-
if (!ticketLink) return;
120-
121-
window.location.href = ticketLink;
122-
};
123-
124-
var toggleTicketCheckbox = function() {
125-
if (!currentRow) return;
126-
var ticketCheckBox = currentRow.find('input[type=checkbox]');
127-
if (!ticketCheckBox.length) return;
128-
ticketCheckBox.prop("checked", !ticketCheckBox.prop("checked"));
129-
};
130-
131-
var replyToTicket = function() {
132-
if (!currentRow) return;
133-
134-
var ticketId = currentRow.closest('tbody').data('recordId');
135-
var replyLink = generateUpdateLink(ticketId, 'Respond');
136-
if (!replyLink) return;
137-
138-
window.location.href = replyLink;
139-
};
140-
141-
var commentOnTicket = function() {
142-
if (!currentRow) return;
143-
144-
var ticketId = currentRow.closest('tbody').data('recordId');
145-
var commentLink = generateUpdateLink(ticketId, 'Comment');
146-
if (!commentLink) return;
147-
148-
window.location.href = commentLink;
149-
};
150-
151-
Mousetrap.bind('j', nextTicket);
152-
Mousetrap.bind('k', prevTicket);
153-
Mousetrap.bind(['enter','o'], navigateToCurrentTicket);
154-
Mousetrap.bind('r', replyToTicket);
155-
Mousetrap.bind('c', commentOnTicket);
156-
Mousetrap.bind('x', toggleTicketCheckbox);
76+
if (RT.Config.KeyBoardShortcuts) {
77+
// Only load these shortcuts if there is a ticket list on the page
78+
var hasTicketList = jQuery('table.ticket-list').length;
79+
if (!hasTicketList) return;
80+
81+
var currentRow;
82+
83+
var nextTicket = function() {
84+
var nextRow;
85+
var searchResultsTable = jQuery('.ticket-list.collection-as-table');
86+
if (!currentRow || !(nextRow = currentRow.next('tbody.list-item')).length) {
87+
nextRow = searchResultsTable.find('tbody.list-item').first();
88+
}
89+
setNewRow(nextRow);
90+
};
91+
92+
var setNewRow = function(newRow) {
93+
if (currentRow) currentRow.removeClass('selected-row');
94+
currentRow = newRow;
95+
currentRow.addClass('selected-row');
96+
scrollToJQueryObject(currentRow);
97+
};
98+
99+
var prevTicket = function() {
100+
var prevRow, searchResultsTable = jQuery('.ticket-list.collection-as-table');
101+
if (!currentRow || !(prevRow = currentRow.prev('tbody.list-item')).length) {
102+
prevRow = searchResultsTable.find('tbody.list-item').last();
103+
}
104+
setNewRow(prevRow);
105+
};
106+
107+
var generateTicketLink = function(ticketId) {
108+
if (!ticketId) return '';
109+
return RT.Config.WebHomePath + '/Ticket/Display.html?id=' + ticketId;
110+
};
111+
112+
var generateUpdateLink = function(ticketId, action) {
113+
if (!ticketId) return '';
114+
return RT.Config.WebHomePath + '/Ticket/Update.html?Action=' + action + '&id=' + ticketId;
115+
};
116+
117+
var navigateToCurrentTicket = function() {
118+
if (!currentRow) return;
119+
120+
var ticketId = currentRow.closest('tbody').data('recordId');
121+
var ticketLink = generateTicketLink(ticketId);
122+
if (!ticketLink) return;
123+
124+
window.location.href = ticketLink;
125+
};
126+
127+
var toggleTicketCheckbox = function() {
128+
if (!currentRow) return;
129+
var ticketCheckBox = currentRow.find('input[type=checkbox]');
130+
if (!ticketCheckBox.length) return;
131+
ticketCheckBox.prop("checked", !ticketCheckBox.prop("checked"));
132+
};
133+
134+
var replyToTicket = function() {
135+
if (!currentRow) return;
136+
137+
var ticketId = currentRow.closest('tbody').data('recordId');
138+
var replyLink = generateUpdateLink(ticketId, 'Respond');
139+
if (!replyLink) return;
140+
141+
window.location.href = replyLink;
142+
};
143+
144+
var commentOnTicket = function() {
145+
if (!currentRow) return;
146+
147+
var ticketId = currentRow.closest('tbody').data('recordId');
148+
var commentLink = generateUpdateLink(ticketId, 'Comment');
149+
if (!commentLink) return;
150+
151+
window.location.href = commentLink;
152+
};
153+
154+
Mousetrap.bind('j', nextTicket);
155+
Mousetrap.bind('k', prevTicket);
156+
Mousetrap.bind(['enter','o'], navigateToCurrentTicket);
157+
Mousetrap.bind('r', replyToTicket);
158+
Mousetrap.bind('c', commentOnTicket);
159+
Mousetrap.bind('x', toggleTicketCheckbox);
160+
}
157161
});
158162

159163
jQuery(function() {
160-
// Only load these shortcuts if reply or comment action is on page
161-
var ticket_reply = jQuery('a#page-actions-reply');
162-
var ticket_comment = jQuery('a#page-actions-comment');
163-
if (!ticket_reply.length && !ticket_comment.length) return;
164-
165-
var replyToTicket = function() {
166-
if (!ticket_reply.length) return;
167-
window.location.href = ticket_reply.attr('href');
168-
};
169-
170-
var commentOnTicket = function() {
171-
if (!ticket_comment.length) return;
172-
window.location.href = ticket_comment.attr('href');
173-
};
174-
175-
Mousetrap.bind('r', replyToTicket);
176-
Mousetrap.bind('c', commentOnTicket);
164+
if (RT.Config.KeyBoardShortcuts) {
165+
// Only load these shortcuts if reply or comment action is on page
166+
var ticket_reply = jQuery('a#page-actions-reply');
167+
var ticket_comment = jQuery('a#page-actions-comment');
168+
if (!ticket_reply.length && !ticket_comment.length) return;
169+
170+
var replyToTicket = function() {
171+
if (!ticket_reply.length) return;
172+
window.location.href = ticket_reply.attr('href');
173+
};
174+
175+
var commentOnTicket = function() {
176+
if (!ticket_comment.length) return;
177+
window.location.href = ticket_comment.attr('href');
178+
};
179+
180+
Mousetrap.bind('r', replyToTicket);
181+
Mousetrap.bind('c', commentOnTicket);
182+
}
177183
});

0 commit comments

Comments
 (0)