From 95cddee07be426198be01f58549219c7679ce77b Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 13 Apr 2026 12:46:01 +0100 Subject: [PATCH] Bug 40633: Open fixed-length field helpers from the advanced editor The advanced cataloging editor lets users hand-edit MARC records as text but offers no equivalent of the basic editor's value_builder popups for the fixed-length fields (Leader, 006, 007 and 008). Catalogers have to type those byte strings by hand, which is error prone. This patch wires the 'open_helper_plugin' shortcut (added in the preceding atomic update) to a new handler in the advanced editor which: - inspects the line under the cursor; - if it is a Leader, 006, 007 or 008 control field, opens the corresponding marc21_*.pl plugin from cataloguing/value_builder/ in a popup window, pre-populated with the current value; - splices the plugin's returned value back into the CodeMirror buffer when the popup closes. The plugin templates are reused unchanged: a hidden on the editor page satisfies the existing report() callback contract, and the editor polls window.closed to detect submission. The 008 plugin is given the current Leader value via &leader= so its material-type byte map matches the record being edited. The shortcut description is added to keyboard_shortcuts.inc so it appears with a meaningful label in the in-editor "show shortcuts" popover and in Administration > Keyboard shortcuts. Test plan: 1. Apply this patch on top of the preceding atomic update. 2. Visit Administration > Keyboard shortcuts and confirm 'open_helper_plugin' is listed with description "Open fixed-length field helper (Leader, 006, 007, 008)" and that the key combination can be edited. 3. Open the advanced cataloging editor on any record: a. Place the cursor on the 000 (Leader) line and press Shift-Ctrl-H. The marc21_leader popup should open with the current Leader value. Make a change, click OK, and confirm the Leader line updates in the editor and is marked modified in the gutter. b. Repeat for 006, 007 and 008. For 008, change the Leader's material-type byte first and confirm the 008 popup form adapts. c. Place the cursor on a 245 (or any non-fixed-length field) line and press Shift-Ctrl-H. Nothing should happen. d. Open a popup, then close it without saving. The editor line should remain unchanged. 4. Save the record and confirm the new fixed-field values round-trip correctly when the record is reloaded. 5. Confirm the basic editor's value_builder popups still work unchanged on Leader / 006 / 007 / 008. Sponsored-by: Main Library Alliance Signed-off-by: Jeanne Mauriello Signed-off-by: Andrew Fuerste Henry Signed-off-by: Lucas Gass (cherry picked from commit 995bfe20835d4c337437d4a94882cf6884965023) Signed-off-by: Jacob O'Mara --- .../lib/koha/cateditor/marc-editor.js | 67 ++++++++++++++++++- .../prog/en/includes/keyboard_shortcuts.inc | 2 + .../prog/en/modules/cataloguing/editor.tt | 5 ++ 3 files changed, 73 insertions(+), 1 deletion(-) 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 46490cd5c5..379bee8b9b 100644 --- a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-editor.js +++ b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-editor.js @@ -289,6 +289,71 @@ define( [ 'marc-record', 'koha-backend', 'preferences', 'text-marc', 'widget' ], cm.replaceRange( "‡", cur, null ); } + _editorKeys[open_helper_plugin] = function( cm ) { + // Launch the appropriate fixed-length field value_builder popup + // when the cursor is on Leader/006/007/008. + var field = cm.marceditor.getCurrentField(); + if ( !field || !field.isControlField ) return; + + var pluginMap = { + '000': 'marc21_leader.pl', + '006': 'marc21_field_006.pl', + '007': 'marc21_field_007.pl', + '008': 'marc21_field_008.pl', + }; + var plugin = pluginMap[ field.tag ]; + if ( !plugin ) return; + + // Control-field content begins at column 4 (3-char tag + 1 space). + var lineText = cm.getLine( field.line ); + var currentValue = lineText.substr( 4 ); + + var indexId = 'adv_editor_fixedfield_buffer'; + var $buf = $( '#' + indexId ); + $buf.val( currentValue ); + + // The 008 plugin needs the Leader value to pick the material-type byte map. + var extra = ''; + if ( field.tag === '008' ) { + var leaderField = cm.marceditor.getFields( '000' )[0]; + if ( leaderField ) { + var leaderValue = cm.getLine( leaderField.line ).substr( 4 ); + extra = '&leader=' + encodeURIComponent( leaderValue ); + } + } + + // The plugin's report() callback writes + // opener.document.getElementById(index).value = newValue + // but does not fire a change event, so poll the buffer when the popup closes. + var fieldLine = field.line; + var capturedLen = lineText.length; + var helperWindow = window.open( + '../cataloguing/plugin_launcher.pl' + + '?plugin_name=' + plugin + + '&index=' + indexId + + '&result=' + encodeURIComponent( currentValue ) + + extra, + 'fixed_field_helper', + 'width=1000,height=600,toolbar=false,scrollbars=yes' + ); + if ( !helperWindow ) return; + + var pollTimer = setInterval( function() { + if ( !helperWindow.closed ) return; + clearInterval( pollTimer ); + + var newValue = $buf.val(); + if ( newValue === currentValue ) return; + + cm.replaceRange( + newValue, + { line: fieldLine, ch: 4 }, + { line: fieldLine, ch: capturedLen }, + 'marcAware' + ); + }, 300 ); + } + _editorKeys[toggle_keyboard] = function( cm ) { let keyboard = $(cm.getInputField()).getkeyboard(); keyboard.isVisible()?keyboard.close():keyboard.reveal(); @@ -302,7 +367,7 @@ define( [ 'marc-record', 'koha-backend', 'preferences', 'text-marc', 'widget' ], // be temporary, and should only be reused with great care. The macro code does this only // because it is careful to dispose of the object after any other updates. // - // Note, however, tha you can continue to use a field object after changing subfields. It's just + // Note, however, that you can continue to use a field object after changing subfields. It's just // the subfield objects that become invalid. // This is an exception raised by the EditorSubfield and EditorField when an invalid change is diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/keyboard_shortcuts.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/keyboard_shortcuts.inc index 010966be02..51f307c468 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/keyboard_shortcuts.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/keyboard_shortcuts.inc @@ -32,5 +32,7 @@ Paste selection from 'clipboard' [%- CASE 'insert_line' -%] Copy current field on next line + [%- CASE 'open_helper_plugin' -%] + Open fixed-length field helper (Leader, 006, 007, 008) [%- END -%] [%- END -%] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt index dd9c3e17d8..ca01b7158f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt @@ -283,6 +283,11 @@ + + +