From 8b7342a823582462798bf2115d2f2e9897485184 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 4 Mar 2019 11:23:31 -0500 Subject: [PATCH] Bug 21411: Advanced cataloging editor - rancor - Allow configuration of Keyboard This patch allows for redfining the keyboard shortcuts used in rancor. For now these are set globally (per instance) Ctrl-S is a codemirror setting and cannot be altered To test: 1 - Apply patches 2 - update database 3 - Load the advanced cataloging editor 4 - Click the "Keyboard shortcuts" button 5 - Ensure the list looks correct 6 - Note that 'Ctrl-S' note sit cannot be remapped 7 - Note the 'Redefine shortcuts' link at the top of the menu 8 - Confirm all the listed shortcuts work as expected 9 - Click the 'Redefine' link 10 - Ensure current mappings load correctly 11 - Read explanation and verify it makes sense 12 - Remap some functions 13 - Return to the cataloging editor 14 - Confirm your mappings work Signed-off-by: Liz Rea Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens --- Koha/KeyboardShortcut.pm | 44 +++++++++++ Koha/KeyboardShortcuts.pm | 50 ++++++++++++ cataloguing/editor.pl | 8 ++ .../atomicupdate/add_keyboard_shortcuts.perl | 30 +++++++ .../mysql/en/mandatory/keyboard_shortcuts.sql | 35 ++++++++ .../mysql/en/mandatory/keyboard_shortcuts.txt | 1 + installer/data/mysql/kohastructure.sql | 12 +++ .../lib/koha/cateditor/marc-editor.js | 48 ++++++----- .../prog/en/includes/cateditor-ui.inc | 3 + .../prog/en/modules/cataloguing/editor.tt | 53 ++----------- .../en/modules/tools/adveditorshortcuts.tt | 68 ++++++++++++++++ tools/adveditorshortcuts.pl | 79 +++++++++++++++++++ 12 files changed, 361 insertions(+), 70 deletions(-) create mode 100644 Koha/KeyboardShortcut.pm create mode 100644 Koha/KeyboardShortcuts.pm create mode 100644 installer/data/mysql/atomicupdate/add_keyboard_shortcuts.perl create mode 100644 installer/data/mysql/en/mandatory/keyboard_shortcuts.sql create mode 100644 installer/data/mysql/en/mandatory/keyboard_shortcuts.txt create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/tools/adveditorshortcuts.tt create mode 100755 tools/adveditorshortcuts.pl diff --git a/Koha/KeyboardShortcut.pm b/Koha/KeyboardShortcut.pm new file mode 100644 index 0000000000..4a45f4453f --- /dev/null +++ b/Koha/KeyboardShortcut.pm @@ -0,0 +1,44 @@ +package Koha::KeyboardShortcut; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::KeyboardShortcut - Koha KeyboardShortcut Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'KeyboardShortcut'; +} + +1; diff --git a/Koha/KeyboardShortcuts.pm b/Koha/KeyboardShortcuts.pm new file mode 100644 index 0000000000..af26745527 --- /dev/null +++ b/Koha/KeyboardShortcuts.pm @@ -0,0 +1,50 @@ +package Koha::KeyboardShortcuts; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::KeyboardShortcut; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::KeyboardShortcuts - Koha KeyboardShortcut Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'KeyboardShortcut'; +} + +sub object_class { + return 'Koha::KeyboardShortcut'; +} + +1; diff --git a/cataloguing/editor.pl b/cataloguing/editor.pl index a0e6c83c5c..7fb34cfe1e 100755 --- a/cataloguing/editor.pl +++ b/cataloguing/editor.pl @@ -31,6 +31,7 @@ use DBIx::Class::ResultClass::HashRefInflator; use Koha::Database; use Koha::MarcSubfieldStructures; use Koha::BiblioFrameworks; +use Koha::KeyboardShortcuts; my $input = CGI->new; @@ -51,6 +52,13 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( my $schema = Koha::Database->new->schema; +my @keyboard_shortcuts = Koha::KeyboardShortcuts->search(); + +# Keyboard shortcuts +$template->param( + shortcuts => \@keyboard_shortcuts, +); + # Available import batches $template->{VARS}->{editable_batches} = [ $schema->resultset('ImportBatch')->search( { diff --git a/installer/data/mysql/atomicupdate/add_keyboard_shortcuts.perl b/installer/data/mysql/atomicupdate/add_keyboard_shortcuts.perl new file mode 100644 index 0000000000..a90d5a8aa7 --- /dev/null +++ b/installer/data/mysql/atomicupdate/add_keyboard_shortcuts.perl @@ -0,0 +1,30 @@ +$DBversion = 'XXX'; +if( CheckVersion( $DBversion ) ) { + unless ( TableExists( 'keyboard_shortcuts' ) ) { + $dbh->do(q| + CREATE TABLE keyboard_shortcuts ( + shortcut_name varchar(80) NOT NULL, + shortcut_keys varchar(80) NOT NULL, + shortcut_desc varchar(200) NOT NULL, + PRIMARY KEY (shortcut_name) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;| + ); + } + $dbh->do(q| + INSERT IGNORE INTO keyboard_shortcuts (shortcut_name, shortcut_keys, shortcut_desc) VALUES + ("insert_copyright","Alt-C","Insert copyright symbol (©)"), + ("insert_copyright_sound","Alt-P","Insert copyright symbol (℗) (sound recordings)"), + ("insert_delimiter","Ctrl-D","Insert delimiter (‡)"), + ("subfield_help","Ctrl-H","Get help on current subfield"), + ("link_authorities","Shift-Ctrl-L","Link field to authorities"), + ("delete_field","Ctrl-X","Delete current field"), + ("delete_subfield","Shift-Ctrl-X","Delete current subfield"), + ("new_line","Enter","New field on next line"), + ("line_break","Shift-Enter","Insert line break"), + ("next_position","Tab","Move to next position"), + ("prev_position","Shift-Tab","Move to previous position") + ;| + ); + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug XXXXX - Add keyboard_shortcuts table)\n"; +} diff --git a/installer/data/mysql/en/mandatory/keyboard_shortcuts.sql b/installer/data/mysql/en/mandatory/keyboard_shortcuts.sql new file mode 100644 index 0000000000..b7e30d3b73 --- /dev/null +++ b/installer/data/mysql/en/mandatory/keyboard_shortcuts.sql @@ -0,0 +1,35 @@ +-- +-- Default keyboard shortcuts +-- for Koha. +-- +-- Copyright (C) 2007 LiblimeA +-- Copyright 2018 Koha Development Team +-- +-- This file is part of Koha. +-- +-- Koha is free software; you can redistribute it and/or modify it under the +-- terms of the GNU General Public License as published by the Free Software +-- Foundation; either version 2 of the License, or (at your option) any later +-- version. +-- +-- Koha is distributed in the hope that it will be useful, but WITHOUT ANY +-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +-- A PARTICULAR PURPOSE. See the GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License along +-- with Koha; if not, write to the Free Software Foundation, Inc., +-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +-- keyboard shortcuts +INSERT INTO keyboard_shortcuts (shortcut_name, shortcut_keys, shortcut_desc) VALUES + ("insert_copyright","Alt-C","Insert copyright symbol (©)"), + ("insert_copyright_sound","Alt-P","Insert copyright symbol (℗) (sound recordings)"), + ("insert_delimiter","Ctrl-D","Insert delimiter (‡)"), + ("subfield_help","Ctrl-H","Get help on current subfield"), + ("link_authorities","Shift-Ctrl-L","Link field to authorities"), + ("delete_field","Ctrl-X","Delete current field"), + ("delete_subfield","Shift-Ctrl-X","Delete current subfield"), + ("new_line","Enter","New field on next line"), + ("line_break","Shift-Enter","Insert line break"), + ("next_position","Tab","Move to next position"), + ("prev_position","Shift-Tab","Move to previous position"); diff --git a/installer/data/mysql/en/mandatory/keyboard_shortcuts.txt b/installer/data/mysql/en/mandatory/keyboard_shortcuts.txt new file mode 100644 index 0000000000..64e5e94989 --- /dev/null +++ b/installer/data/mysql/en/mandatory/keyboard_shortcuts.txt @@ -0,0 +1 @@ +Default keyboard shorcuts diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index f82fc52357..f4c9b25f94 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -4324,6 +4324,18 @@ CREATE TABLE stockrotationitems ( ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +-- +-- Table structure for table `keyboardshortcuts` +-- + +DROP TABLE IF EXISTS `keyboard_shortcuts`; +CREATE TABLE keyboard_shortcuts ( +shortcut_name varchar(80) NOT NULL, +shortcut_keys varchar(80) NOT NULL, +shortcut_desc varchar(200) NOT NULL, +PRIMARY KEY (shortcut_name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; diff --git a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-editor.js b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-editor.js index 7fe7062edf..af20307ca2 100644 --- a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-editor.js +++ b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-editor.js @@ -135,36 +135,36 @@ define( [ 'marc-record', 'koha-backend', 'preferences', 'text-marc', 'widget' ], return []; } } + var _editorKeys = {}; - var _editorKeys = { - 'Alt-C': function( cm ) { + _editorKeys[insert_copyright] = function( cm ) { cm.replaceRange( '©', cm.getCursor() ); - }, + } - 'Alt-P': function( cm ) { + _editorKeys[insert_copyright_sound] = function( cm ) { cm.replaceRange( '℗', cm.getCursor() ); - }, + } - Enter: function( cm ) { + _editorKeys[new_line] = function( cm ) { var cursor = cm.getCursor(); cm.replaceRange( '\n', { line: cursor.line }, null, 'marcAware' ); cm.setCursor( { line: cursor.line + 1, ch: 0 } ); - }, + } - 'Shift-Enter': function( cm ) { + _editorKeys[line_break] = function( cm ) { var cur = cm.getCursor(); cm.replaceRange( "\n", cur, null ); - }, + } - 'Ctrl-X': function( cm ) { + _editorKeys[delete_field] = function( cm ) { // Delete line (or cut) if ( cm.somethingSelected() ) return true; cm.execCommand('deleteLine'); - }, + } - 'Shift-Ctrl-L': function( cm ) { + _editorKeys[link_authorities] = function( cm ) { // Launch the auth search popup var field = cm.marceditor.getCurrentField(); @@ -186,18 +186,18 @@ define( [ 'marc-record', 'koha-backend', 'preferences', 'text-marc', 'widget' ], } newin=window.open("../authorities/auth_finder.pl?source=biblio&authtypecode="+authtype+"&index="+index+"&value_mainstr="+encodeURI(mainmainstring)+"&value_main="+encodeURI(mainstring), "_blank",'width=700,height=550,toolbar=false,scrollbars=yes'); - }, + } - 'Shift-Ctrl-X': function( cm ) { + _editorKeys[delete_subfield] = function( cm ) { // Delete subfield var field = cm.marceditor.getCurrentField(); if ( !field ) return; var subfield = field.getSubfieldAt( cm.getCursor().ch ); if ( subfield ) subfield.delete(); - }, + } - Tab: function( cm ) { + _editorKeys[next_position] = function( cm ) { // Move through parts of tag/fixed fields var positions = getTabPositions( cm.marceditor ); var cur = cm.getCursor(); @@ -210,9 +210,9 @@ define( [ 'marc-record', 'koha-backend', 'preferences', 'text-marc', 'widget' ], } cm.setCursor( { line: cur.line + 1, ch: 0 } ); - }, + } - 'Shift-Tab': function( cm ) { + _editorKeys[prev_position] = function( cm ) { // Move backwards through parts of tag/fixed fields var positions = getTabPositions( cm.marceditor ); var cur = cm.getCursor(); @@ -233,15 +233,13 @@ define( [ 'marc-record', 'koha-backend', 'preferences', 'text-marc', 'widget' ], } else { cm.setCursor( { line: cur.line - 1, ch: 0 } ); } - }, + } - 'Ctrl-D': function( cm ) { - // Insert subfield delimiter - var cur = cm.getCursor(); + _editorKeys[insert_delimiter] = function(cm){ + var cur = cm.getCursor(); - cm.replaceRange( "‡", cur, null ); - }, - }; + cm.replaceRange( "‡", cur, null ); + } // The objects below are part of a field/subfield manipulation API, accessed through the base // editor object. diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc index db6dc6629d..a5734ff619 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc @@ -5,6 +5,9 @@ [% Asset.js("lib/koha/cateditor/marc-mode.js") | $raw %] [% Asset.js("lib/require.js") | $raw %]