Bug 16251: Fix value of material select for Rancor 008 widget
authorJulian Maurice <julian.maurice@biblibre.com>
Wed, 6 Mar 2019 07:58:03 +0000 (08:58 +0100)
committerFridolin Somers <fridolin.somers@biblibre.com>
Tue, 26 Mar 2019 06:23:18 +0000 (07:23 +0100)
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 <black23@gmail.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 926d7c4ba11ad6cd768c884ec4b2dc71d864b64c)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit d7988f672f68e0cc875eedce6bad0b634df8941c)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 5f858a9746c3210dacc7a3546409ef619379e854)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js
koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc

index bfb1ea1..be06236 100644 (file)
@@ -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();
index ba049d5..d01c885 100644 (file)
@@ -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' );
         }