From ccbfd25ef82147a2f838a8785d823dce12f93193 Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Fri, 15 May 2020 14:40:16 -0400
Subject: [PATCH] Bug 24857: Copy the volume to the item's enumchron

---
 cataloguing/additem.pl                        |  2 ++
 .../prog/en/modules/cataloguing/additem.tt    | 26 ++++++++++---------
 .../prog/js/cataloging_additem.js             |  7 +++++
 3 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl
index 29fae5676b..b216ef4216 100755
--- a/cataloguing/additem.pl
+++ b/cataloguing/additem.pl
@@ -158,6 +158,8 @@ sub generate_subfield_form {
         $subfield_data{important}  = $subfieldlib->{important};
         $subfield_data{repeatable} = $subfieldlib->{repeatable};
         $subfield_data{maxlength}  = $subfieldlib->{maxlength};
+        $subfield_data{kohafield}  = $subfieldlib->{kohafield} || 'unlinked';
+        $subfield_data{kohafield} =~ s/\./-/g;
         
         if ( ! defined( $value ) || $value eq '')  {
             $value = $subfieldlib->{defaultvalue};
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt
index 699bcfb68d..aeb5eb57b5 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt
@@ -148,12 +148,12 @@
 
                 [% SET mv = ite.marc_value %]
                 [% IF ( mv.type == 'hidden' ) %]
-                    <input type="hidden" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]">
+                    <input type="hidden" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor [% ite.kohafield | html %]" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]">
                 [% ELSIF ( mv.type == 'select' ) %]
                     [% IF ( mv.readonly ) %]
-                        <select name="field_value" id="[%- mv.id | html -%]" size="1" class="input_marceditor" readonly="readonly" disabled="disabled">
+                        <select name="field_value" id="[%- mv.id | html -%]" size="1" class="input_marceditor [% ite.kohafield | html %]" readonly="readonly" disabled="disabled">
                     [% ELSE %]
-                        <select name="field_value" id="[%- mv.id | html -%]" size="1" class="input_marceditor">
+                        <select name="field_value" id="[%- mv.id | html -%]" size="1" class="input_marceditor [% ite.kohafield | html %]">
                     [% END %]
                     [% FOREACH aval IN mv.values %]
                         [% IF aval == mv.default %]
@@ -165,17 +165,17 @@
                     </select>
                 [% ELSIF ( mv.type == 'text_auth' ) %]
                     [% IF mv.readonly %]
-                        <input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" readonly="readonly" />
+                        <input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor [% ite.kohafield | html %]" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" readonly="readonly" />
                     [% ELSE %]
-                        <input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
+                        <input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor [% ite.kohafield | html %]" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
                         [% SET dopop = "Dopop('/cgi-bin/koha/authorities/auth_finder.pl?authtypecode=\"${mv.authtypecode}\"&index=${mv.id}','${mv.id}')" %]
                         <a href="#" class="buttonDot"  onclick="[%- dopop | html -%]; return false;" title="Tag editor">...</a>
                     [% END %]
                 [% ELSIF ( mv.type == 'text_plugin' ) %]
                     [% IF mv.readonly %]
-                        <input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" readonly="readonly" />
+                        <input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor [% ite.kohafield | html %]" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" readonly="readonly" />
                     [% ELSE %]
-                        <input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
+                        <input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor [% ite.kohafield | html %]" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
                         [% IF ( mv.nopopup ) %]
                             <a href="#" id="buttonDot_[%- mv.id | html -%]" class="[%- mv.class | html -%]" title="No popup">...</a>
                         [% ELSE  %]
@@ -185,15 +185,15 @@
                     [% END %]
                 [% ELSIF ( mv.type == 'text' ) %]
                     [% IF mv.readonly %]
-                        <input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" readonly="readonly" />
+                        <input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor [% ite.kohafield | html %]" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" readonly="readonly" />
                     [% ELSE %]
-                        <input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
+                        <input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor [% ite.kohafield | html %]" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
                     [% END %]
                 [% ELSIF ( mv.type == 'textarea' ) %]
                     [% IF mv.readonly %]
-                        <textarea id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" rows="5" cols="64" readonly="readonly" >[% mv.value | html %]</textarea>
+                        <textarea id="[%- mv.id | html -%]" name="field_value" class="input_marceditor [% ite.kohafield | html %]" rows="5" cols="64" readonly="readonly" >[% mv.value | html %]</textarea>
                     [% ELSE %]
-                        <textarea id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" rows="5" cols="64" >[% mv.value | html %]</textarea>
+                        <textarea id="[%- mv.id | html -%]" name="field_value" class="input_marceditor [% ite.kohafield | html %]" rows="5" cols="64" >[% mv.value | html %]</textarea>
                     [% END %]
                 [% END %]
 
@@ -220,7 +220,9 @@
 [% IF volumes.count && op != 'saveitem' %]
     <fieldset class="rows">
         <legend><i class="fa fa-plus"></i> Add to volume</legend>
-
+        [% FOREACH v IN volumes %]
+            <input type="hidden" id="volume-[% v.id | html %]" value="[% v.description | html %]" />
+        [% END %]
         <p>
             <label for="select_volume">Options: </label>
             <select name="volume" id="volume-add-or-create-form-select">
diff --git a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js b/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js
index 64fd9e26a4..b058a7f96c 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js
@@ -94,6 +94,13 @@ $(document).ready(function(){
         });
     }
 
+    $('#volume-add-or-create-form-select').on('change', function() {
+        if ( ! $('input.items-enumchron').val() ) {
+            let volume_selector = '#volume-' + $(this).val();
+            let enumchron = $(volume_selector).val();
+            $('input.items-enumchron').val( enumchron );
+        }
+    });
 });
 
 function Check(f) {
-- 
2.24.2 (Apple Git-127)