From 5f858a9746c3210dacc7a3546409ef619379e854 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Wed, 6 Mar 2019 08:58:03 +0100 Subject: [PATCH] Bug 16251: Fix value of material select for Rancor 008 widget The material type is selected in accordance with the leader (06-07) Test plan: 1. Create a new record using the advanced editor 2. Set the leader 6th position to 'c' 3. Save the record and reload the page 4. 'Music' should be automatically selected for 008 5. Try other values for the leader 6th and 7th positions See comment 0 of this bug for the complete mapping Signed-off-by: Michal Denar Signed-off-by: Josef Moravec Signed-off-by: Nick Clemens (cherry picked from commit 926d7c4ba11ad6cd768c884ec4b2dc71d864b64c) Signed-off-by: Martin Renvoize (cherry picked from commit d7988f672f68e0cc875eedce6bad0b634df8941c) Signed-off-by: Lucas Gass --- .../lib/koha/cateditor/widget.js | 7 +++++ .../en/includes/cateditor-widgets-marc21.inc | 26 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js index bfb1ea1697..be0623699c 100644 --- a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js +++ b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js @@ -121,6 +121,13 @@ define( [ 'resources' ], function( Resources ) { materialInfo[ $(this).attr('id') ] = this; } ); + if (widget.getMaterial) { + const material = widget.getMaterial(); + if (material) { + $matSelect.val(material); + } + } + $matSelect.change( function() { widget.loadXMLMaterial( materialInfo[ $matSelect.val() ] ); widget.nodeChanged(); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc index ba049d5239..d01c885f76 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc @@ -85,7 +85,7 @@ * single subfield, '@'. */ -require( [ 'widget' ], function( Widget ) { +require( [ 'koha-backend', 'widget', 'text-marc' ], function( KohaBackend, Widget, TextMarc ) { Widget.Register( '000@', { makeTemplate: function() { return ' nam a22 7a 4500'; @@ -178,6 +178,30 @@ require( [ 'widget' ], function( Widget ) { return $result[0]; }, + materialTypeMapping: { + a: { + a: 'BKS', c: 'BKS', d: 'BKS', m: 'BKS', + b: 'CR', i: 'CR', s: 'CR', + }, + t: 'BKS', + c: 'MU', d: 'MU', i: 'MU', j: 'MU', + e: 'MP', f: 'MP', + g: 'VM', k: 'VM', o: 'VM', r: 'VM', + m: 'CF', + p: 'MX', + }, + getMaterial: function () { + const record = TextMarc.TextToRecord(this.editor.cm.getValue()); + const leader = record.leader(); + const leader6 = leader.substring(6, 7); + let materialType = this.materialTypeMapping[leader6]; + if (typeof materialType === 'object') { + const leader7 = leader.substring(7, 8); + materialType = materialType[leader7]; + } + + return materialType; + }, postCreate: function( node, mark ) { this.createFromXML( 'marc21/xml/008' ); } -- 2.39.5