Bug 21049: Set 007/00 when selecting material type (Rancor)
authorJulian Maurice <julian.maurice@biblibre.com>
Fri, 8 Mar 2019 09:12:50 +0000 (10:12 +0100)
committerLucas Gass <lucas@bywatersolutions.com>
Mon, 1 Apr 2019 16:44:54 +0000 (16:44 +0000)
There is a 1-1 relationship between the material type values and the
position 00 of 007 field. Selecting a material type should set this
position's value.

Signed-off-by: Liz Rea <wizzyrea@gmail.com>

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

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 856425db1e156ee4faf1aae70b0a78845711ba43)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 16e250542de43eadf62bc9354329912be84c3420)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>

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

index be06236..2f60856 100644 (file)
@@ -109,7 +109,7 @@ define( [ 'resources' ], function( Resources ) {
             createFromXML: function( resourceId ) {
                 var widget = this;
 
-                Resources[resourceId].done( function( xml ) {
+                return Resources[resourceId].done( function( xml ) {
                     $(widget.node).find('.widget-loading').remove();
                     var $matSelect = $('<select class="material-select"></select>').appendTo(widget.node);
                     var $contents = $('<span class="material-contents"/>').appendTo(widget.node);
index fa7de56..48a476e 100644 (file)
@@ -184,7 +184,18 @@ require( [ 'koha-backend', 'widget', 'text-marc' ], function( KohaBackend, Widge
             return this.materialTypeMapping[this.text.substring(0, 1)];
         },
         postCreate: function( node, mark ) {
-            this.createFromXML( 'marc21/xml/007' );
+            this.createFromXML( 'marc21/xml/007' ).then(() => {
+                $(this.node).find('.material-select').on('change', (e) => {
+                    const keys = Object.keys(this.materialTypeMapping);
+                    const k = keys.filter(k => this.materialTypeMapping[k] === $(e.target).val());
+                    this.setFixed(0, 1, k, '+input');
+
+                    // FIXME There must be a better way to update display
+                    const n = $(this.node).find('[name="f00"]');
+                    n.triggerHandler('focus');
+                    n.triggerHandler('blur');
+                });
+            });
         }
     } );