Bug 26368: Add OCLC options to marc21_leader.tt
[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. Controls default type of 008 field.">
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             [% IF Koha.Preference('UseOCLCEncodingLevels') %]
53                 <option value="I">I- Full-level input by OCLC participants</option>
54                 <option value="J">J- Deleted record</option>
55                 <option value="K">K- Less-than-full input by OCLC participants</option>
56                 <option value="M">M- Added from a batch process</option>
57             [% END %]
58             <option value="u">u - Unknown</option>
59             <option value="z">z - Not applicable</option>
60         </select>
61         <select name="f18" title="Descriptive cataloging form">
62             <option value=" ">_ - Non-ISBD</option>
63             <option value="a">a - AACR 2</option>
64             <option value="c">c - ISBD punctuation omitted</option>
65             <option value="i">i - ISBD punctuation included</option>
66             <option value="n">n - Non-ISBD punctuation omitted</option>
67             <option value="u">u - Unknown</option>
68         </select>
69         <select name="f19" title="Multipart record resource level">
70             <option value=" ">_ - Not specified or not applicable</option>
71             <option value="a">a - Set</option>
72             <option value="b">b - Part with independent title</option>
73             <option value="c">c - Part with dependent title</option>
74         </select>
75         <span title="Length of directory elements">4500</span>
76     </div>
77 </div>
78 <!-- cateditor-widgets-marc21.inc -->
79 <script>
80
81 /**
82  * Each widget should provide one to three methods:
83  *   init( text ): Returns the DOM node for this widget.
84  *   postCreate( node, mark ): Optional, called once the mark has been created
85  *                             and the node shown. Bind event handlers here.
86  *   makeTemplate(): Optional, should return some sane default contents for a
87  *                   newly created field/subfield. '<empty>' will be used if this
88  *                   method is unset.
89  *
90  * Following the Koha convention, control fields are defined as tags with a
91  * single subfield, '@'.
92  */
93
94 require( [ 'koha-backend', 'widget', 'text-marc' ], function( KohaBackend, Widget, TextMarc ) {
95     Widget.Register( '000@', {
96         makeTemplate: function() {
97             return '     nam a22     7a 4500';
98         },
99         init: function() {
100             var $result = $( '<span class="subfield-widget fixed-widget"></span>' );
101
102             return $result[0];
103         },
104         postCreate: function() {
105             // Clear the length and directory start fields; these are unnecessary for MARCXML and will be filled in upon USMARC export
106             this.setFixed( 0, 5, '     ' );
107             this.setFixed( 9, 17, 'a22     ' );
108             this.setFixed( 20, 24, '4500' );
109
110             this.insertTemplate( '#widget-leader' );
111
112             this.bindFixed( '[name=f5]', 5, 6 );
113             this.bindFixed( '[name=f6]', 6, 7 );
114             this.bindFixed( '[name=f7]', 7, 8 );
115             this.bindFixed( '[name=f8]', 8, 9 );
116             this.bindFixed( '[name=f17]', 17, 18 );
117             this.bindFixed( '[name=f18]', 18, 19 );
118             this.bindFixed( '[name=f19]', 19, 20 );
119         },
120     } );
121
122     /* Check to see if there are any Control Number entries
123      *  in the authorised values table.
124      * If not, let's not show the widget
125      */
126     var reg001 = KohaBackend.GetAuthorisedValues( 'CONTROL_NUM_SEQUENCE');
127     if(reg001) {
128
129         Widget.Register( '001@', {
130             init: function() {
131                 var $result = $(
132                     '<span class="subfield-widget">'
133                     + _("Control number: ")
134                     + '<span class="control-number-widget-contents"></span>'
135                     + '<button class="control-number-widget-assign">' + _("Assign next") + '</button>'
136                     + '<select class="control-number-widget-sequence"></select>'
137                     + '<button class="control-number-widget-override">' + _("Override") + '</button>'
138                     + '</span>'
139                 );
140
141                 return $result[0];
142             },
143             setControlNumber: function( text ) {
144                 if ( text ) this.setText( text );
145                 $( this.node ).find('.control-number-widget-contents')
146                     .html( text == '<empty>' ? ( '<span class="hint">' + _("unset") + '</span>' ) : text );
147                 this.mark.changed();
148             },
149             postCreate: function( node, mark ) {
150                 var widget = this;
151                 this.setControlNumber( this.text );
152                 $( this.node )
153                     .find('.control-number-widget-assign').click( function() {
154                         var sequence = $( widget.node ).find('.control-number-widget-sequence').val();
155                         $.post(
156                             '/cgi-bin/koha/svc/cataloguing/control_num_sequences/' + sequence
157                         ).done( function( result ) {
158                             if ( result.next_value ) widget.setControlNumber( result.next_value );
159                         } );
160                     } ).end()
161                     .find('.control-number-widget-override').click( function() {
162                         var result = prompt( _("Enter new control number") );
163
164                         if ( result ) widget.setControlNumber( result );
165                     } ).end();
166
167                 var sequence_list = $.map( reg001 , function( authval ) {
168                     return authval.lib;
169                 } );
170                 sequence_list.sort();
171
172                 $.each( sequence_list, function( undef, sequence ) {
173                     $( widget.node ).find('.control-number-widget-sequence').append( '<option>' + sequence + '</option>' );
174                 } );
175
176                 // TODO: Make Enter on select click "Assign"
177             }
178         } );
179         };
180
181     Widget.Register( '005@', {
182         init: function() {
183             var $result = $( '<span class="subfield-widget fixed-widget">' + _("Updated: ") + '</span>' );
184
185             return $result[0];
186         },
187         postCreate: function( node, mark ) {
188             var parts = this.text.match( /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})\.(\d)/ );
189
190             if ( parts ) {
191                 var dateVal = new Date(
192                     parseInt( parts[1] ), // Year
193                     parseInt( parts[2] ) - 1, // Month (0-11)
194                     parseInt( parts[3] ), // Day
195                     parseInt( parts[4] ), // Hour
196                     parseInt( parts[5] ), // Minute
197                     parseInt( parts[6] ), // Second
198                     parseInt( parts[7] ) * 100 // Millisecond
199                 );
200
201                 $( this.node ).append( dateVal.toLocaleString() );
202             } else {
203                 $( this.node ).append( '<span class="hint">' + _("unset") + '</span>' );
204             }
205         }
206     } );
207
208     Widget.Register( '006@', {
209         makeTemplate: function() {
210             return "a                 ";
211         },
212         init: function() {
213             var $result = $( '<span class="subfield-widget fixed-widget">' + _("Fixed data:") + '<span class="hint widget-loading">' + _("Loading...") + '</span></span>' );
214
215             return $result[0];
216         },
217         postCreate: function( node, mark ) {
218             this.createFromXML( 'marc21/xml/006' );
219         }
220     } );
221
222     Widget.Register( '007@', {
223         makeTemplate: function() {
224             return "a       ";
225         },
226         init: function() {
227             var $result = $( '<span class="subfield-widget fixed-widget">' + _("Fixed data:") + '<span class="hint widget-loading">' + _("Loading...") + '</span></span>' );
228
229             return $result[0];
230         },
231         materialTypeMapping: {
232             a: 'MPS',
233             c: 'ER',
234             d: 'GL',
235             f: 'TM',
236             g: 'PG',
237             h: 'MF',
238             k: 'NG',
239             m: 'MP',
240             o: 'KT',
241             q: 'NM',
242             r: 'RI',
243             s: 'SR',
244             t: 'TC',
245             v: 'VR',
246             z: 'UN'
247         },
248         getMaterial: function () {
249             return this.materialTypeMapping[this.text.substring(0, 1)];
250         },
251         postCreate: function( node, mark ) {
252             this.createFromXML( 'marc21/xml/007' ).then(() => {
253                 $(this.node).find('.material-select').on('change', (e) => {
254                     const keys = Object.keys(this.materialTypeMapping);
255                     const k = keys.filter(k => this.materialTypeMapping[k] === $(e.target).val());
256                     this.setFixed(0, 1, k, '+input');
257
258                     // FIXME There must be a better way to update display
259                     const n = $(this.node).find('[name="f00"]');
260                     n.triggerHandler('focus');
261                     n.triggerHandler('blur');
262                 });
263             });
264         }
265     } );
266
267     Widget.Register( '008@', {
268         makeTemplate: function() {
269             var now = new Date();
270             return Widget.PadNum( now.getYear() % 100, 2 ) + Widget.PadNum( now.getMonth() + 1, 2 ) + Widget.PadNum( now.getDate(), 2 ) + "b        [% DefaultCountryField008 | html %]||||| |||| 00| 0 [% DefaultLanguageField008 | html %] d";
271         },
272         init: function() {
273             var $result = $( '<span class="subfield-widget fixed-widget">' + _("Fixed data:") + '<span class="hint widget-loading">' + _("Loading...") + '</span></span>' );
274
275             return $result[0];
276         },
277         materialTypeMapping: {
278             a: {
279                 a: 'BKS', c: 'BKS', d: 'BKS', m: 'BKS',
280                 b: 'CR', i: 'CR', s: 'CR',
281             },
282             t: 'BKS',
283             c: 'MU', d: 'MU', i: 'MU', j: 'MU',
284             e: 'MP', f: 'MP',
285             g: 'VM', k: 'VM', o: 'VM', r: 'VM',
286             m: 'CF',
287             p: 'MX',
288         },
289         getMaterial: function () {
290             const record = TextMarc.TextToRecord(this.editor.cm.getValue());
291
292             const leader = record.leader();
293             const leader6 = leader.substring(6, 7);
294             let materialType = this.materialTypeMapping[leader6];
295             if (typeof materialType === 'object') {
296                 const leader7 = leader.substring(7, 8);
297                 materialType = materialType[leader7];
298             }
299
300             return materialType;
301         },
302         postCreate: function( node, mark ) {
303             this.createFromXML( 'marc21/xml/008' );
304         }
305     } );
306 } );
307
308 </script>
309 <!-- / cateditor-widgets-marc21.inc -->