Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user config option to disable keyboard shortcuts #390

Open
wants to merge 2 commits into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions etc/RT_Config.pm.in
Original file line number Diff line number Diff line change
Expand Up @@ -2286,6 +2286,14 @@ Set this to 0 to disable URL shortener.

Set($EnableURLShortener, 1);

=item C<$KeyBoardShortcuts>

Set this to 0 to disable keyboard shortcuts.

=cut

Set($KeyBoardShortcuts, 1);

=back


Expand Down
9 changes: 9 additions & 0 deletions lib/RT/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,15 @@ our %META;
Description => 'Enable URL shortener', #loc
},
},
KeyBoardShortcuts => {
Section => 'General', #loc
Overridable => 1,
SortOrder => 13,
Widget => '/Widgets/Form/Boolean',
WidgetArguments => {
Description => 'Enable keyboards shortcuts', #loc
},
},

# User overridable options for RT at a glance
HomePageRefreshInterval => {
Expand Down
2 changes: 1 addition & 1 deletion share/html/Elements/JavascriptConfig
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
my $Config = {};
$Config->{$_} = RT->Config->Get( $_, $session{CurrentUser} )
for qw(rtname WebPath MessageBoxRichText MessageBoxRichTextHeight
MaxAttachmentSize WebDefaultStylesheet QuoteSelectedText );
MaxAttachmentSize WebDefaultStylesheet QuoteSelectedText KeyBoardShortcuts );

# JS-only config value. Setting default here, can be reset with
# the Data callback below.
Expand Down
206 changes: 106 additions & 100 deletions share/static/js/keyboard-shortcuts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
jQuery(function() {
if (RT.Config.KeyBoardShortcuts) {
var goBack = function() {
window.history.back();
};
Expand Down Expand Up @@ -68,110 +69,115 @@ jQuery(function() {
Mousetrap.bind('g h', goHome);
Mousetrap.bind('/', simpleSearch);
Mousetrap.bind('?', openHelp);
}
});

jQuery(function() {
// Only load these shortcuts if there is a ticket list on the page
var hasTicketList = jQuery('table.ticket-list').length;
if (!hasTicketList) return;

var currentRow;

var nextTicket = function() {
var nextRow;
var searchResultsTable = jQuery('.ticket-list.collection-as-table');
if (!currentRow || !(nextRow = currentRow.next('tbody.list-item')).length) {
nextRow = searchResultsTable.find('tbody.list-item').first();
}
setNewRow(nextRow);
};

var setNewRow = function(newRow) {
if (currentRow) currentRow.removeClass('selected-row');
currentRow = newRow;
currentRow.addClass('selected-row');
scrollToJQueryObject(currentRow);
};

var prevTicket = function() {
var prevRow, searchResultsTable = jQuery('.ticket-list.collection-as-table');
if (!currentRow || !(prevRow = currentRow.prev('tbody.list-item')).length) {
prevRow = searchResultsTable.find('tbody.list-item').last();
}
setNewRow(prevRow);
};

var generateTicketLink = function(ticketId) {
if (!ticketId) return '';
return RT.Config.WebHomePath + '/Ticket/Display.html?id=' + ticketId;
};

var generateUpdateLink = function(ticketId, action) {
if (!ticketId) return '';
return RT.Config.WebHomePath + '/Ticket/Update.html?Action=' + action + '&id=' + ticketId;
};

var navigateToCurrentTicket = function() {
if (!currentRow) return;

var ticketId = currentRow.closest('tbody').data('recordId');
var ticketLink = generateTicketLink(ticketId);
if (!ticketLink) return;

window.location.href = ticketLink;
};

var toggleTicketCheckbox = function() {
if (!currentRow) return;
var ticketCheckBox = currentRow.find('input[type=checkbox]');
if (!ticketCheckBox.length) return;
ticketCheckBox.prop("checked", !ticketCheckBox.prop("checked"));
};

var replyToTicket = function() {
if (!currentRow) return;

var ticketId = currentRow.closest('tbody').data('recordId');
var replyLink = generateUpdateLink(ticketId, 'Respond');
if (!replyLink) return;

window.location.href = replyLink;
};

var commentOnTicket = function() {
if (!currentRow) return;

var ticketId = currentRow.closest('tbody').data('recordId');
var commentLink = generateUpdateLink(ticketId, 'Comment');
if (!commentLink) return;

window.location.href = commentLink;
};

Mousetrap.bind('j', nextTicket);
Mousetrap.bind('k', prevTicket);
Mousetrap.bind(['enter','o'], navigateToCurrentTicket);
Mousetrap.bind('r', replyToTicket);
Mousetrap.bind('c', commentOnTicket);
Mousetrap.bind('x', toggleTicketCheckbox);
if (RT.Config.KeyBoardShortcuts) {
// Only load these shortcuts if there is a ticket list on the page
var hasTicketList = jQuery('table.ticket-list').length;
if (!hasTicketList) return;

var currentRow;

var nextTicket = function() {
var nextRow;
var searchResultsTable = jQuery('.ticket-list.collection-as-table');
if (!currentRow || !(nextRow = currentRow.next('tbody.list-item')).length) {
nextRow = searchResultsTable.find('tbody.list-item').first();
}
setNewRow(nextRow);
};

var setNewRow = function(newRow) {
if (currentRow) currentRow.removeClass('selected-row');
currentRow = newRow;
currentRow.addClass('selected-row');
scrollToJQueryObject(currentRow);
};

var prevTicket = function() {
var prevRow, searchResultsTable = jQuery('.ticket-list.collection-as-table');
if (!currentRow || !(prevRow = currentRow.prev('tbody.list-item')).length) {
prevRow = searchResultsTable.find('tbody.list-item').last();
}
setNewRow(prevRow);
};

var generateTicketLink = function(ticketId) {
if (!ticketId) return '';
return RT.Config.WebHomePath + '/Ticket/Display.html?id=' + ticketId;
};

var generateUpdateLink = function(ticketId, action) {
if (!ticketId) return '';
return RT.Config.WebHomePath + '/Ticket/Update.html?Action=' + action + '&id=' + ticketId;
};

var navigateToCurrentTicket = function() {
if (!currentRow) return;

var ticketId = currentRow.closest('tbody').data('recordId');
var ticketLink = generateTicketLink(ticketId);
if (!ticketLink) return;

window.location.href = ticketLink;
};

var toggleTicketCheckbox = function() {
if (!currentRow) return;
var ticketCheckBox = currentRow.find('input[type=checkbox]');
if (!ticketCheckBox.length) return;
ticketCheckBox.prop("checked", !ticketCheckBox.prop("checked"));
};

var replyToTicket = function() {
if (!currentRow) return;

var ticketId = currentRow.closest('tbody').data('recordId');
var replyLink = generateUpdateLink(ticketId, 'Respond');
if (!replyLink) return;

window.location.href = replyLink;
};

var commentOnTicket = function() {
if (!currentRow) return;

var ticketId = currentRow.closest('tbody').data('recordId');
var commentLink = generateUpdateLink(ticketId, 'Comment');
if (!commentLink) return;

window.location.href = commentLink;
};

Mousetrap.bind('j', nextTicket);
Mousetrap.bind('k', prevTicket);
Mousetrap.bind(['enter','o'], navigateToCurrentTicket);
Mousetrap.bind('r', replyToTicket);
Mousetrap.bind('c', commentOnTicket);
Mousetrap.bind('x', toggleTicketCheckbox);
}
});

jQuery(function() {
// Only load these shortcuts if reply or comment action is on page
var ticket_reply = jQuery('a#page-actions-reply');
var ticket_comment = jQuery('a#page-actions-comment');
if (!ticket_reply.length && !ticket_comment.length) return;

var replyToTicket = function() {
if (!ticket_reply.length) return;
window.location.href = ticket_reply.attr('href');
};

var commentOnTicket = function() {
if (!ticket_comment.length) return;
window.location.href = ticket_comment.attr('href');
};

Mousetrap.bind('r', replyToTicket);
Mousetrap.bind('c', commentOnTicket);
if (RT.Config.KeyBoardShortcuts) {
// Only load these shortcuts if reply or comment action is on page
var ticket_reply = jQuery('a#page-actions-reply');
var ticket_comment = jQuery('a#page-actions-comment');
if (!ticket_reply.length && !ticket_comment.length) return;

var replyToTicket = function() {
if (!ticket_reply.length) return;
window.location.href = ticket_reply.attr('href');
};

var commentOnTicket = function() {
if (!ticket_comment.length) return;
window.location.href = ticket_comment.attr('href');
};

Mousetrap.bind('r', replyToTicket);
Mousetrap.bind('c', commentOnTicket);
}
});