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
<input id="adv_editor_fixedfield_buffer"> 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 <https://www.mainlib.org/>
Signed-off-by: Jeanne Mauriello <jeanne.mauriello@mainlib.org>
Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 995bfe2083)
Signed-off-by: Jacob O'Mara <Jacob.omara@openfifth.co.uk>
This commit is contained in:
parent
a12b71e93c
commit
95cddee07b
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -32,5 +32,7 @@
|
|||
<span>Paste selection from 'clipboard'</span>
|
||||
[%- CASE 'insert_line' -%]
|
||||
<span>Copy current field on next line</span>
|
||||
[%- CASE 'open_helper_plugin' -%]
|
||||
<span>Open fixed-length field helper (Leader, 006, 007, 008)</span>
|
||||
[%- END -%]
|
||||
[%- END -%]
|
||||
|
|
|
|||
|
|
@ -283,6 +283,11 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Hidden buffer used by the fixed-length field helper popups (Leader/006/007/008).
|
||||
The value_builder plugin templates write their result here via opener.document; the
|
||||
advanced editor watches for the change and splices the new value back into CodeMirror. -->
|
||||
<input type="hidden" id="adv_editor_fixedfield_buffer" />
|
||||
|
||||
<div id="macro-ui" class="modal" tabindex="-1" role="dialog" aria-labelledby="macro-title" aria-hidden="true">
|
||||
<div class="modal-dialog modal-xl">
|
||||
<div class="modal-content">
|
||||
|
|
|
|||
Loading…
Reference in New Issue