Bug 16251: Fix value of material select for Rancor 008 widget
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / includes / cateditor-widgets-marc21.inc
1 <div id="editor-widget-templates" style="display:none">
2     <div id="widget-leader">
3         Leader:&nbsp;<span title="Record length (autogenerated)">#####</span>
4         <select name="f5" title="Record status">
5             <option value="a">a - Increase in encoding level</option>
6             <option value="c">c - Corrected or revised</option>
7             <option value="d">d - Deleted</option>
8             <option value="n">n - New</option>
9             <option value="p">p - Increase in encoding level from prepublication</option>
10         </select>
11         <select name="f6" title="Type of record">
12             <option value="a">a - Language material</option>
13             <option value="c">c - Notated music</option>
14             <option value="d">d - Manuscript notated music</option>
15             <option value="e">e - Cartographic material</option>
16             <option value="f">f - Manuscript cartographic material</option>
17             <option value="g">g - Projected medium</option>
18             <option value="i">i - Nonmusical sound recording</option>
19             <option value="j">j - Musical sound recording</option>
20             <option value="k">k - Two-dimensional nonprojectable graphic</option>
21             <option value="m">m - Computer file</option>
22             <option value="o">o - Kit</option>
23             <option value="p">p - Mixed materials</option>
24             <option value="r">r - Three-dimensional artifact or naturally occurring object</option>
25             <option value="t">t - Manuscript language material</option>
26         </select>
27         <select name="f7" title="Bibliographic level">
28             <option value="a">a - Monographic component part</option>
29             <option value="b">b - Serial component part</option>
30             <option value="c">c - Collection</option>
31             <option value="d">d - Subunit</option>
32             <option value="i">i - Integrating resource</option>
33             <option value="m">m - Monograph/item</option>
34             <option value="s">s - Serial</option>
35         </select>
36         <select name="f8" title="Type of control">
37                 <option value=" ">_ - No specific type</option>
38                 <option value="a">a - Archival</option>
39         </select>
40         <span title="Encoding (forced Unicode)">a</span>
41         <span title="Indicator/subfield lengths">22</span>
42         <span title="Data base address (autogenerated)">#####</span>
43         <select name="f17" title="Encoding level">
44             <option value=" ">_ - Full level</option>
45             <option value="1">1 - Full level, material not examined</option>
46             <option value="2">2 - Less-than-full level, material not examined</option>
47             <option value="3">3 - Abbreviated level</option>
48             <option value="4">4 - Core level</option>
49             <option value="5">5 - Partial (preliminary) level</option>
50             <option value="7">7 - Minimal level</option>
51             <option value="8">8 - Prepublication level</option>
52             <option value="u">u - Unknown</option>
53             <option value="z">z - Not applicable</option>
54         </select>
55         <select name="f18" title="Descriptive cataloging form">
56             <option value=" ">_ - Non-ISBD</option>
57             <option value="a">a - AACR 2</option>
58             <option value="c">c - ISBD punctuation omitted</option>
59             <option value="i">i - ISBD punctuation included</option>
60             <option value="n">n - Non-ISBD punctuation omitted</option>
61             <option value="u">u - Unknown</option>
62         </select>
63         <select name="f19" title="Multipart record resource level">
64             <option value=" ">_ - Not specified or not applicable</option>
65             <option value="a">a - Set</option>
66             <option value="b">b - Part with independent title</option>
67             <option value="c">c - Part with dependent title</option>
68         </select>
69         <span title="Length of directory elements">4500</span>
70     </div>
71 </div>
72
73 <script>
74
75 /**
76  * Each widget should provide one to three methods:
77  *   init( text ): Returns the DOM node for this widget.
78  *   postCreate( node, mark ): Optional, called once the mark has been created
79  *                             and the node shown. Bind event handlers here.
80  *   makeTemplate(): Optional, should return some sane default contents for a
81  *                   newly created field/subfield. '<empty>' will be used if this
82  *                   method is unset.
83  *
84  * Following the Koha convention, control fields are defined as tags with a
85  * single subfield, '@'.
86  */
87
88 require( [ 'koha-backend', 'widget', 'text-marc' ], function( KohaBackend, Widget, TextMarc ) {
89     Widget.Register( '000@', {
90         makeTemplate: function() {
91             return '     nam a22     7a 4500';
92         },
93         init: function() {
94             var $result = $( '<span class="subfield-widget fixed-widget"></span>' );
95
96             return $result[0];
97         },
98         postCreate: function() {
99             // Clear the length and directory start fields; these are unnecessary for MARCXML and will be filled in upon USMARC export
100             this.setFixed( 0, 5, '     ' );
101             this.setFixed( 9, 17, 'a22     ' );
102             this.setFixed( 20, 24, '4500' );
103
104             this.insertTemplate( '#widget-leader' );
105
106             this.bindFixed( '[name=f5]', 5, 6 );
107             this.bindFixed( '[name=f6]', 6, 7 );
108             this.bindFixed( '[name=f7]', 7, 8 );
109             this.bindFixed( '[name=f8]', 8, 9 );
110             this.bindFixed( '[name=f17]', 17, 18 );
111             this.bindFixed( '[name=f18]', 18, 19 );
112             this.bindFixed( '[name=f19]', 19, 20 );
113         },
114     } );
115
116     /* Check to see if there are any Control Number entries
117      *  in the authorised values table.
118      * If not, let's not show the widget
119      */
120     var reg001 = KohaBackend.GetAuthorisedValues( 'CONTROL_NUM_SEQUENCE');
121     if(reg001) {
122
123         Widget.Register( '001@', {
124             init: function() {
125                 var $result = $(
126                     '<span class="subfield-widget">'
127                     + _("Control number: ")
128                     + '<span class="control-number-widget-contents"></span>'
129                     + '<button class="control-number-widget-assign">' + _("Assign next") + '</button>'
130                     + '<select class="control-number-widget-sequence"></select>'
131                     + '<button class="control-number-widget-override">' + _("Override") + '</button>'
132                     + '</span>'
133                 );
134
135                 return $result[0];
136             },
137             setControlNumber: function( text ) {
138                 if ( text ) this.setText( text );
139                 $( this.node ).find('.control-number-widget-contents')
140                     .html( text == '<empty>' ? ( '<span class="hint">' + _("unset") + '</span>' ) : text );
141                 this.mark.changed();
142             },
143             postCreate: function( node, mark ) {
144                 var widget = this;
145                 this.setControlNumber( this.text );
146                 $( this.node )
147                     .find('.control-number-widget-assign').click( function() {
148                         var sequence = $( widget.node ).find('.control-number-widget-sequence').val();
149                         $.post(
150                             '/cgi-bin/koha/svc/cataloguing/control_num_sequences/' + sequence
151                         ).done( function( result ) {
152                             if ( result.next_value ) widget.setControlNumber( result.next_value );
153                         } );
154                     } ).end()
155                     .find('.control-number-widget-override').click( function() {
156                         var result = prompt( _("Enter new control number") );
157
158                         if ( result ) widget.setControlNumber( result );
159                     } ).end();
160
161                 var sequence_list = $.map( reg001 , function( authval ) {
162                     return authval.lib;
163                 } );
164                 sequence_list.sort();
165
166                 $.each( sequence_list, function( undef, sequence ) {
167                     $( widget.node ).find('.control-number-widget-sequence').append( '<option>' + sequence + '</option>' );
168                 } );
169
170                 // TODO: Make Enter on select click "Assign"
171             }
172         } );
173         };
174
175     Widget.Register( '005@', {
176         init: function() {
177             var $result = $( '<span class="subfield-widget fixed-widget">' + _("Updated: ") + '</span>' );
178
179             return $result[0];
180         },
181         postCreate: function( node, mark ) {
182             var parts = this.text.match( /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})\.(\d)/ );
183
184             if ( parts ) {
185                 var dateVal = new Date(
186                     parseInt( parts[1] ), // Year
187                     parseInt( parts[2] ) - 1, // Month (0-11)
188                     parseInt( parts[3] ), // Day
189                     parseInt( parts[4] ), // Hour
190                     parseInt( parts[5] ), // Minute
191                     parseInt( parts[6] ), // Second
192                     parseInt( parts[7] ) * 100 // Millisecond
193                 );
194
195                 $( this.node ).append( dateVal.toLocaleString() );
196             } else {
197                 $( this.node ).append( '<span class="hint">' + _("unset") + '</span>' );
198             }
199         }
200     } );
201
202     Widget.Register( '006@', {
203         makeTemplate: function() {
204             return "a                 ";
205         },
206         init: function() {
207             var $result = $( '<span class="subfield-widget fixed-widget">' + _("Fixed data:") + '<span class="hint widget-loading">' + _("Loading...") + '</span></span>' );
208
209             return $result[0];
210         },
211         postCreate: function( node, mark ) {
212             this.createFromXML( 'marc21/xml/006' );
213         }
214     } );
215
216     Widget.Register( '007@', {
217         makeTemplate: function() {
218             return "a       ";
219         },
220         init: function() {
221             var $result = $( '<span class="subfield-widget fixed-widget">' + _("Fixed data:") + '<span class="hint widget-loading">' + _("Loading...") + '</span></span>' );
222
223             return $result[0];
224         },
225         postCreate: function( node, mark ) {
226             this.createFromXML( 'marc21/xml/007' );
227         }
228     } );
229
230     Widget.Register( '008@', {
231         makeTemplate: function() {
232             var now = new Date();
233             return Widget.PadNum( now.getYear() % 100, 2 ) + Widget.PadNum( now.getMonth() + 1, 2 ) + Widget.PadNum( now.getDate(), 2 ) + "b        xxu||||| |||| 00| 0 [% DefaultLanguageField008 | html %] d";
234         },
235         init: function() {
236             var $result = $( '<span class="subfield-widget fixed-widget">' + _("Fixed data:") + '<span class="hint widget-loading">' + _("Loading...") + '</span></span>' );
237
238             return $result[0];
239         },
240         materialTypeMapping: {
241             a: {
242                 a: 'BKS', c: 'BKS', d: 'BKS', m: 'BKS',
243                 b: 'CR', i: 'CR', s: 'CR',
244             },
245             t: 'BKS',
246             c: 'MU', d: 'MU', i: 'MU', j: 'MU',
247             e: 'MP', f: 'MP',
248             g: 'VM', k: 'VM', o: 'VM', r: 'VM',
249             m: 'CF',
250             p: 'MX',
251         },
252         getMaterial: function () {
253             const record = TextMarc.TextToRecord(this.editor.cm.getValue());
254             const leader = record.leader();
255             const leader6 = leader.substring(6, 7);
256             let materialType = this.materialTypeMapping[leader6];
257             if (typeof materialType === 'object') {
258                 const leader7 = leader.substring(7, 8);
259                 materialType = materialType[leader7];
260             }
261
262             return materialType;
263         },
264         postCreate: function( node, mark ) {
265             this.createFromXML( 'marc21/xml/008' );
266         }
267     } );
268 } );
269
270 </script>