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)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 12 Mar 2019 08:39:04 +0000 (08:39 +0000)
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>

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 f1cb70c..4b56885 100644 (file)
@@ -85,7 +85,7 @@
  * single subfield, '@'.
  */
 
-require( [ 'koha-backend', 'widget' ], function( KohaBackend, Widget ) {
+require( [ 'koha-backend', 'widget', 'text-marc' ], function( KohaBackend, Widget, TextMarc ) {
     Widget.Register( '000@', {
         makeTemplate: function() {
             return '     nam a22     7a 4500';
@@ -237,6 +237,30 @@ require( [ 'koha-backend', 'widget' ], function( KohaBackend, 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' );
         }