Bug 34571: Remove use of "onclick" for ExpandField in cataloguing editors
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / cataloguing / addbiblio.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE HtmlTags %]
5 [% INCLUDE 'doc-head-open.inc' %]
6 <title>[% IF ( biblionumber ) %]Editing [% title | html %] (Record number [% biblionumber | html %])[% ELSE %]Add MARC record[% END %] &rsaquo; Cataloging &rsaquo; Koha</title>
7 [% INCLUDE 'doc-head-close.inc' %]
8 [% INCLUDE 'calendar.inc' %]
9 [% Asset.js("lib/hc-sticky.js") | $raw %]
10 [% INCLUDE 'select2.inc' %]
11 <script>
12     [% IF Koha.Preference('CreateAVFromCataloguing') && CAN_user_parameters_manage_auth_values %]
13         var auth_values_creation = 1;
14     [% ELSE %]
15         var auth_values_creation = 0;
16     [% END %]
17     $.fn.select2.defaults.set("width", "100%" );
18 </script>
19 [% Asset.js("js/cataloging.js") | $raw %]
20 [% Asset.js("js/browser.js") | $raw %]
21 <script>
22     var browser = KOHA.browser('[% searchid | html %]', parseInt('[% biblionumber | html %]', 10));
23     browser.show();
24
25     $(window).load(function(){
26         $("#loading").hide();
27     });
28     var Sticky;
29     $(document).ready(function() {
30
31         [% IF bib_doesnt_exist %]
32             $("#addbibliotabs").hide();
33             $("#toolbar").hide();
34         [% END %]
35
36         $("a[data-toggle='tab']").on("shown.bs.tab", function (e) {
37             $( e.target.hash + " .input_marceditor:visible:eq(0)").focus();
38         });
39
40         /* On page load, check for location.hash in the page URL */
41         /* If present the location hash will be used to activate the correct tab */
42         var hash = location.hash;
43         var hashPieces = hash.split('?');
44         if( hashPieces[0] !== "" ){
45             selectTab( hashPieces[0] );
46             window.scrollTo( 0, 0 );
47         } else {
48             selectTab( "#tab0XX_panel" );
49         }
50
51         $( "ul.sortable_field", "#addbibliotabs" ).sortable({
52             axis: "y",
53             containment: $("#addbibliotabs")
54         });
55         $( "ul.sortable_subfield", "#addbibliotabs" ).sortable({
56             axis: "y",
57             containment: "parent"
58         });
59
60         [% IF tab %]
61             hash = "#[% tab | html %]";
62             selectTab( hash );
63         [% END %]
64
65         Sticky = $("#toolbar");
66         Sticky.hcSticky({
67             stickTo: "#f",
68             stickyClass: "floating"
69         });
70
71         /* check cookie to hide/show marcdocs*/
72         if( Cookies.get("marcdocs_[% borrowernumber | html %]") == 'hide'){
73             toggleMARCdocLinks(false);
74         } else {
75             toggleMARCdocLinks(true);
76         }
77
78         $("#marcDocsSelect").click(function(){
79             if( Cookies.get("marcdocs_[% borrowernumber | html %]") == 'hide'){
80                 toggleMARCdocLinks(true);
81             } else {
82                 toggleMARCdocLinks(false);
83             }
84         });
85
86         /* check cookie to hide/show marc tags*/
87         var marctags_cookie = Cookies.get("marctags_[% borrowernumber | html %]");
88         if( marctags_cookie == 'hide'){
89             toggleMARCTagLinks(false);
90         } else if( marctags_cookie == 'show'){
91             toggleMARCTagLinks(true)
92         } else {
93             [% UNLESS Koha.Preference("hide_marc") %]
94                 toggleMARCTagLinks(true)
95             [% ELSE %]
96                 toggleMARCTagLinks(false);
97             [% END %]
98         }
99
100         $("#marcTagsSelect").click(function(){
101             if( Cookies.get("marctags_[% borrowernumber | html %]") == 'hide'){
102                 toggleMARCTagLinks(true)
103             } else {
104                 toggleMARCTagLinks(false);
105             }
106         });
107
108         $("#z3950search").click(function(){
109             PopupZ3950();
110         });
111
112         $("#linkerbutton").click(function(){
113             AutomaticLinker();
114         });
115
116         $("#saverecord").click(function(){
117             $(".btn-group").removeClass("open");
118             onOption();
119             return false;
120         });
121
122         $("#saveandview").click(function(){
123             $(".btn-group").removeClass("open");
124             redirect("view");
125             return false;
126         });
127
128         $("#saveanditems").click(function(){
129             $(".btn-group").removeClass("open");
130             redirect("items");
131             return false;
132         });
133         $("#saveandcontinue").click(function(){
134             $(".btn-group").removeClass("open");
135             var tab = $("#addbibliotabs div.active:first").attr('id');
136             $("#current_tab").val(tab);
137             redirect("just_save", tab);
138             return false;
139         });
140
141         $( '#switcheditor' ).click( function() {
142             var breedingid = [% breedingid || "null" | html %];
143
144             if ( !confirm( breedingid ? _("This record cannot be transferred to the advanced editor. Continue?") : _("Any changes will not be saved. Continue?") ) ) return false;
145
146             Cookies.set( 'catalogue_editor_[% logged_in_user.borrowernumber | html %]', 'advanced', { expires: 365, path: '/', sameSite: 'Lax'  } );
147
148             var biblionumber = [% biblionumber || "null" | html %];
149
150             if ( biblionumber ) {
151                 window.location = '/cgi-bin/koha/cataloguing/editor.pl#catalog/' + biblionumber;
152             } else {
153                 window.location = '/cgi-bin/koha/cataloguing/editor.pl';
154             }
155
156             return false;
157         } );
158         $(".change-framework").on("click", function(){
159             var frameworkcode = $(this).data("frameworkcode");
160             $("#frameworkcode").val( frameworkcode );
161             Changefwk();
162         });
163
164         $(".toolbar-tabs-container .nav-tabs a").on("click",function(e){
165             e.preventDefault();
166             selectTab( this.hash );
167         });
168
169         $(".tag_anchor").on("click", function(e){
170             e.preventDefault();
171             $(".tag_anchor").removeClass("selected");
172             $(this).addClass("selected");
173             var link = this.href;
174             var linkid = link.substring( link.indexOf("#") + 1 );
175             window.scrollTo( 0, getScrollto( linkid, "toolbar" ) );
176         });
177
178         $("body").on("click", ".linkfield", function(e){
179             e.preventDefault();
180             var tab = $(this).data("tab");
181             var field = $(this).data("field");
182             var tablink = $("a[data-tabname='tab" + tab + "XX']" ).get(0).hash;
183             selectTab( tablink );
184             window.scrollTo( 0, getScrollto( field, "toolbar" ) );
185         });
186
187         $("body").on("click", ".show-errors", function(e){
188             document.getElementById("form-errors").scrollIntoView();
189         });
190
191     });
192
193     function selectTab( tablink ){
194         /* return if no tabs displayed (fast add framework) */
195         if ($(".toolbar-tabs-container .nav-tabs li").length === 0){
196           return;
197         }
198         let a = $("a[href='" + tablink + "']");
199         $(".toolbar-tabs-container .nav-tabs li").removeClass("selected");
200         a.tab("show").parent().addClass("selected");
201         /* Get number from string like "tab9XX" */
202         var tabid = a.data("tabname").substring(3, 4);
203         $(".tag_anchors").removeClass("tab_selected").hide();
204         $(".tag_anchors_" + tabid ).addClass("tab_selected").show();
205     }
206
207     /**
208     * Returns a roughly ideal position to scroll an element into view
209     * @param {string} target - The HTML id of the element to scroll into view
210     * @param {string} elemid - The HTML id of the element which might obscure
211     *                          the view of the target element e.g. a floating toolbar
212     * @return {number} - The y-coordinate to pass to window.scrollTo()
213     */
214     function getScrollto( target, elemid ){
215         var dest = $("#" + target );
216         var yoffset = dest.offset();
217
218         if( elemid != "" ){
219             var element = $("#" + elemid );
220             var elem_height = element.outerHeight();
221         } else {
222             elem_height = 0;
223         }
224         return yoffset.top - elem_height - 20;
225     }
226
227     function redirect(dest){
228         $("#redirect").attr("value",dest);
229         return Check();
230     }
231
232     [% IF ( CAN_user_editcatalogue_edit_items ) %]
233         var onOption = function () {
234             return Check();
235         }
236     [% END %]
237
238 /**
239 * this function append button for create new authority if not found
240 */
241
242 function addCreateAuthorityButton(tag_subfield_line, heading, tag_index) {
243     var title = _("Create authority");
244     var elem = $('<a href="#" title="' + title + '"><i class="fa fa-plus-circle"></i></a>');
245     tag_subfield_line.append(elem);
246     var tag_subfield_line_a = $('.subfield_line[id^=subfield' + heading.tag + 'a]').eq(tag_index);
247     var subfield_a = tag_subfield_line_a.find('.input_marceditor').eq(0);
248     var index = subfield_a.attr('id');
249     elem.click(function() {
250         var popup = window.open("", "new_auth_popup",'fullscreen,toolbar=false,scrollbars=yes');
251         if(popup !== null) {
252             // Create a new form that will be POSTed in the new window
253             var form = $('<form>').attr({
254             method: 'post',
255             action: "/cgi-bin/koha/authorities/authorities.pl",
256             target: "new_auth_popup"
257             });
258             //add the authtypecode
259             form.append($('<input>').attr({
260                 type: 'hidden',
261                 name: 'authtypecode',
262                 value: heading.auth_type
263             }));
264             form.append($('<input>').attr({
265                 type: 'hidden',
266                 name: 'tagreport',
267                 value: heading.tag_to_report
268             }));
269             form.append($('<input>').attr({
270                 type: 'hidden',
271                 name: 'tagbiblio',
272                 value: heading.tag
273             }));
274             form.append($('<input>').attr({
275                 type: 'hidden',
276                 name: 'index',
277                 value: index
278             }));
279             $('.tag[id^=tag_' + heading.tag + '_]').eq(tag_index).find(':input').each(function(){
280                 form.append($('<input>').attr({
281                     type: 'hidden',
282                     name: this.name.split('_',4).join(''),
283                     value: $(this).val()
284                 }));
285             });
286             $('body').append(form);
287             form.submit();
288             form.remove();
289         }
290         return false;
291     });
292
293 }
294
295 /**
296  * Updates the authid for every heading field
297  * Adds visual feedback for the changes made on the form.
298  */
299 function updateHeadingLinks(links) {
300     var current_tag = '';
301     var tag_index = 0;
302
303     // Delete the old message dialog and create a new one
304     $('#autolinker_dialog').remove();
305     var message_dialog = $('<div id="autolinker_dialog" class="dialog message"><strong>' + _("Automatic authority link results:") + '</strong><ul></ul></div>');
306     var message_dialog_ul = message_dialog.find('ul');
307
308     $.each(links, function(index, heading) {
309         if(current_tag == heading.tag) {
310             tag_index++;
311         }
312         else {
313             current_tag = heading.tag;
314             tag_index = 0;
315         }
316
317         // Find the $9 field to update
318         var tag_subfield_line = $('.subfield_line[id^=subfield' + heading.tag + '9]').eq(tag_index);
319         if( tag_subfield_line.length < 1 ){ return; }
320
321         var subfield = tag_subfield_line.find('.input_marceditor').eq(0);
322         subfield.removeClass("matching_authority_field no_matching_authority_field");
323
324         // Delete the old status if one exists
325         tag_subfield_line.children('.subfield_status').remove();
326
327         // If the field wasn't modified. Skip it.
328         if(heading.status == 'UNCHANGED') {
329             return;
330         }
331
332
333         // Make the subfield line visible and update its value
334         tag_subfield_line.show();
335         subfield.val(heading.authid);
336
337         // Add the new status
338         var image = '<i class="fa fa-close subfield_status no_matching_authority" </i> ';
339         var message = '';
340         var field_class = 'no_matching_authority_field';
341         switch(heading.status) {
342             case 'LOCAL_FOUND':
343                 image = '<i class="fa fa-check subfield_status matching_authority"</i> ';
344                 message = _("A matching authority was found in the local database.");
345                 field_class = 'matching_authority_field';
346                 break;
347             case 'CREATED':
348                 image = '<i class="fa fa-check subfield_status matching_authority"></i> ';
349                 message = _("No matching authority found. A new authority was created automatically.");
350                 field_class = 'matching_authority_field';
351                 break;
352             case 'MULTIPLE_MATCH':
353                 message = _("More than one local match found. Possibly a duplicate authority!");
354                 break;
355             case 'NONE_FOUND':
356                 message = _("No matching authority found.");
357                 break;
358             default:
359                 message = heading.status;
360                 break;
361         }
362
363         subfield[0].classList.add(field_class);
364         tag_subfield_line.find('i').each(function() {
365             this.remove();
366         });
367         tag_subfield_line.append(image);
368
369         // Add the message to the dialog
370         message_dialog_ul.append('<li><strong>' + heading.tag + '</strong> - ' + message + '</li>');
371
372         // Add a link to create a new authority if none was found
373         if(heading.status == 'NONE_FOUND' && tag_subfield_line.find('i').length == 1) {
374             addCreateAuthorityButton(tag_subfield_line, heading , tag_index);
375         }
376     });
377
378     if(message_dialog.find('li').length == 0) {
379         message_dialog_ul.append("<li>" + _("No authority link was changed.") + "</li>");
380     }
381     $('#addbibliotabs').before(message_dialog);
382 }
383
384 /**
385  * Use an ajax request to automatically find authority links for the current record
386  */
387 function AutomaticLinker() {
388     // Show the Loading overlay
389     $("#loading").show();
390
391     // Remove fields that are completely empty
392     $('#f').find('.tag').each(function() {
393         var empty = true;
394         $(this).find('.input_marceditor').each(function() {
395             if($(this).val() != '') {
396                 empty = false;
397                 return false;
398             }
399         });
400         if(empty) {
401             UnCloneField($(this).attr('id'));
402         }
403     });
404
405     // Get all the form values to post via AJAX
406     var form_data = {};
407     $('#f').find(':input').each(function(){
408         form_data[this.name] = $(this).val();
409     });
410     delete form_data[''];
411
412     // Send the data to automatic_linker.pl
413     $.ajax({
414         url:'/cgi-bin/koha/svc/cataloguing/automatic_linker.pl',
415         type:'post',
416         data: form_data,
417         dataType: 'json',
418         error: function(xhr) {
419             alert("Error : \n" + xhr.responseText);
420         },
421         success: function(json) {
422             switch(json.status) {
423                 case 'UNAUTHORIZED':
424                     alert(_("Error : You do not have the permissions necessary to use this functionality."));
425                     break;
426                 case 'OK':
427                     updateHeadingLinks(json.links);
428                     break;
429             }
430         },
431         complete: function() {
432             $("#loading").hide();
433         }
434     });
435 }
436
437
438 function PopupMARCFieldDoc() {
439     let field = this.dataset.tag;
440     [% IF Koha.Preference('marcfielddocurl') %]
441         var docurl = "[% Koha.Preference('marcfielddocurl').replace('"','&quot;') | html %]";
442         docurl = docurl.replace("{MARC}", "[% marcflavour | html %]");
443         docurl = docurl.replace("{FIELD}", ""+field);
444         docurl = docurl.replace("{LANG}", "[% lang | html %]");
445         window.open(docurl);
446     [% ELSIF ( marcflavour == 'MARC21' ) %]
447         _MARC21FieldDoc(field);
448     [% ELSIF ( marcflavour == 'UNIMARC' ) %]
449         _UNIMARCFieldDoc(field);
450     [% END %]
451     return false;
452 }
453 [%# Attach to body, so that cloned nodes will still have the event listener %]
454 $(document).ready(function(){
455     $('body').on('click','.marcdocs',PopupMARCFieldDoc);
456 });
457
458     function confirmnotdup(redirect){
459         $("#confirm_not_duplicate").attr("value","1");
460         $("#redirect").attr("value",redirect);
461         Check();
462     }
463
464     function Dopop(link,i) {
465         defaultvalue = document.getElementById(i).value;
466         window.open(link+"&result="+defaultvalue,"valuebuilder",'width=700,height=550,toolbar=false,scrollbars=yes');
467     }
468
469     /**
470      * this function open a popup to search on z3950 server.
471      */
472     function PopupZ3950() {
473         var strQuery = GetZ3950Terms();
474         if(strQuery){
475             window.open("/cgi-bin/koha/cataloguing/z3950_search.pl?biblionumber=[% biblionumber | html %]"+strQuery,"z3950search",'width=800,height=550,location=yes,toolbar=no,scrollbars=yes,resize=yes');
476         }
477     }
478
479     function _MARC21FieldDoc(field) {
480         if(field == 0) {
481             window.open("http://www.loc.gov/marc/bibliographic/bdleader.html");
482         } else if (field >= 90 && field <= 99 ){
483             window.open("http://www.loc.gov/marc/bibliographic/bd09x.html");
484         } else if (field >= 590 && field <= 599 ){
485             window.open("http://www.loc.gov/marc/bibliographic/bd59x.html");
486         } else if (field >= 690 && field <= 699 ){
487             window.open("http://www.loc.gov/marc/bibliographic/bd69x.html");
488         } else if (field < 900) {
489             window.open("http://www.loc.gov/marc/bibliographic/bd" + ("000"+field).slice(-3) + ".html");
490         } else {
491             window.open("http://www.loc.gov/marc/bibliographic/bd9xx.html");
492         }
493     }
494
495     function _UNIMARCFieldDoc(field) {
496         /* http://archive.ifla.org/VI/3/p1996-1/ is an outdated version of UNIMARC, but
497            seems to be the only version available that can be linked to per tag.  More recent
498            versions of the UNIMARC standard are available on the IFLA website only as
499            PDFs!
500         */
501         var url;
502         if (field == 0) {
503             url = "http://archive.ifla.org/VI/3/p1996-1/uni.htm";
504         } else {
505             var first = field.substring(0,1);
506             url = "http://archive.ifla.org/VI/3/p1996-1/uni" + first + ".htm#";
507             if (first == 0) url = url + "b";
508             url = first == 9
509                   ? "http://archive.ifla.org/VI/3/p1996-1/uni9.htm"
510                   : url + field;
511         }
512         window.open(url);
513     }
514
515     /*
516      * Functions to hide/show marc docs and tags links
517      */
518
519     function toggleMARCdocLinks(flag){
520         if( flag === true ){
521             $(".marcdocs").show();
522             Cookies.set("marcdocs_[% borrowernumber | html %]",'show', { path: "/", expires: 365, sameSite: 'Lax'  });
523             $("#marcDocsSelect i").addClass('fa-check-square-o').removeClass('fa-square-o');
524         } else {
525             $(".marcdocs").hide();
526             Cookies.set("marcdocs_[% borrowernumber | html %]",'hide', { path: "/", expires: 365, sameSite: 'Lax'  });
527             $("#marcDocsSelect i").removeClass('fa-check-square-o').addClass('fa-square-o');
528         }
529     }
530
531     function toggleMARCTagLinks(flag){
532         if( flag === true ){
533             $(".tagnum").show();
534             $(".subfieldcode").show();
535             Cookies.set("marctags_[% borrowernumber | html %]",'show', { path: "/", expires: 365, sameSite: 'Lax'  });
536             $("#marcTagsSelect i").addClass('fa-check-square-o').removeClass('fa-square-o');
537         } else {
538             $(".tagnum").hide();
539             $(".subfieldcode").hide();
540             Cookies.set("marctags_[% borrowernumber | html %]",'hide', { path: "/", expires: 365, sameSite: 'Lax'  });
541             $("#marcTagsSelect i").removeClass('fa-check-square-o').addClass('fa-square-o');
542         }
543     }
544
545     /**
546      * check if mandatory/important subfields are written
547      * @param mandatory true to check for mandatories, false for importants
548      */
549     function AreFieldsNotOk (mandatory = true) {
550         var fields = new Array();
551         var subfields = new Array();
552         var tab = new Array();
553         var label = new Array();
554         var flag = false;
555         var tabflag= new Array();
556         var StrAlert = "<div id='form-errors' class='dialog alert list'>";
557         var notFilledClass = "subfield_not_filled";
558
559         if (mandatory) {
560             [% FOREACH BIG_LOO IN BIG_LOOP %]
561                 [% FOREACH innerloo IN BIG_LOO.innerloop %]
562                     [% IF ( innerloo.mandatory ) %]
563                         fields.push(new Array("[% innerloo.tag | html %]","[% innerloo.index | html %][% innerloo.random | html %]","[% innerloo.index | html %]", "[% BIG_LOO.number | html %]"));
564                     [% END %]
565                     [% FOREACH subfield_loo IN innerloo.subfield_loop %]
566                         [% IF ( subfield_loo.mandatory ) %]subfields.push("[% subfield_loo.id | html %]");
567                             tab.push("[% BIG_LOO.number | html %]");
568                             label.push("[% subfield_loo.marc_lib | $raw %]");
569                         [% END %]
570                     [% END %]
571                 [% END %]
572             [% END %]
573             StrAlert += "<h4>" + _("The following mandatory subfields aren't filled:") + "</h4>";
574         } else {
575             [% FOREACH BIG_LOO IN BIG_LOOP %]
576                 [% FOREACH innerloo IN BIG_LOO.innerloop %]
577                     [% IF ( innerloo.important ) %]
578                         fields.push(new Array("[% innerloo.tag | html %]","[% innerloo.index | html %][% innerloo.random | html %]","[% innerloo.index | html %]", "[% BIG_LOO.number | html %]"));
579                     [% END %]
580                     [% FOREACH subfield_loo IN innerloo.subfield_loop %]
581                         [% IF ( subfield_loo.important ) %]subfields.push("[% subfield_loo.id | html %]");
582                             tab.push("[% BIG_LOO.number | html %]");
583                             label.push("[% subfield_loo.marc_lib | $raw %]");
584                         [% END %]
585                     [% END %]
586                 [% END %]
587             [% END %]
588             StrAlert += "<h4>" + _("The following important subfields aren’t filled:") + "</h4>";
589             notFilledClass = "important_subfield_not_filled";
590         }
591         StrAlert += "<ul>";
592         for(var i=0,len=subfields.length; i<len ; i++){
593             var tag=subfields[i].substr(4,3);
594             var subfield=subfields[i].substr(17,1);
595             var tagnumber=subfields[i].substr(19,subfields[i].lastIndexOf("_")-19);
596             if (tabflag[tag+subfield+tagnumber] ==  null) {
597                 tabflag[tag+subfield+tagnumber]=new Array();
598                 tabflag[tag+subfield+tagnumber][0]=0;
599             }
600             if( tabflag[tag+subfield+tagnumber][0] != 1 && (document.getElementById(subfields[i]) != null && ! document.getElementById(subfields[i]).value || document.getElementById(subfields[i]) == null)){
601                 tabflag[tag+subfield+tagnumber][0] = 0 + tabflag[tag+subfield+tagnumber] ;
602
603                 var elt = document.getElementById(subfields[i]);
604                 if ( elt.nodeName == 'SELECT' ) {
605                     $(elt).siblings('.select2').find("span[role='combobox']").addClass(notFilledClass);
606                 } else {
607                     elt.setAttribute('class','input_marceditor noEnterSubmit ' + notFilledClass);
608                 }
609                 $('#' + subfields[i]).focus();
610                 tabflag[tag+subfield+tagnumber][1]=label[i];
611                 tabflag[tag+subfield+tagnumber][2]=tab[i];
612             } else {
613                 tabflag[tag+subfield+tagnumber][0] = 1;
614             }
615             tabflag[tag+subfield+tagnumber][3] = subfields[i];
616         }
617
618         for (var tagsubfieldid in tabflag){
619             if (tabflag[tagsubfieldid][0]==0){
620                 var tag=tagsubfieldid.substr(0,3);
621                 var subfield=tagsubfieldid.substr(3,1);
622                 StrAlert += "<li>"+_("Tag %s subfield %s %s in tab %s").format(tag, subfield, formatFieldName( tabflag[tagsubfieldid][1] ), tabflag[tagsubfieldid][2]) + ' <a class="linkfield btn btn-link" href="#" data-tab="' + tabflag[tagsubfieldid][2] + '" data-field="' + tabflag[tagsubfieldid][3] + '"><i class="fa fa-arrow-right" aria-hidden="true"></i> ' + _("Go to field") + '</a></li>';
623                 flag = true;
624             }
625         }
626         StrAlert += "</ul>";
627         /* Check for mandatories/importants field(not subfields) */
628         /* Loop over array of fields identified as mandatory or
629            important to see if at least one subfield is filled */
630         mandatoryFields = new Object();
631
632         for(var i=0,len=fields.length; i<len; i++){
633             isempty  = true;
634             arr      = fields[i];
635             divid    = "tag_" + arr[0] + "_" + arr[1];
636             varegexp = new RegExp("^tag_" + arr[0] + "_code_");
637
638             if(parseInt(arr[0]) >= 10){
639                 elem = document.getElementById(divid);
640                 eleminputs = elem.getElementsByTagName('input');
641
642                 for(var j=0,len2=eleminputs.length; j<len2; j++){
643
644                     if(eleminputs[j].name.match(varegexp) && eleminputs[j].value){
645                         inputregexp = new RegExp("^tag_" + arr[0] + "_subfield_" + eleminputs[j].value + "_" + arr[2]);
646
647                         for( var k=0; k<len2; k++){
648                             if( eleminputs[k].id.match(inputregexp) ){
649                                 if( eleminputs[k].value ){
650                                     isempty = false
651                                 }
652                             }
653                         }
654
655                         elemselect = elem.getElementsByTagName('select');
656                         for( var k=0; k<elemselect.length; k++){
657                             if(elemselect[k].id.match(inputregexp) && elemselect[k].value){
658                                 isempty = false
659                             }
660                         }
661                     }
662                 }
663
664                 elemtextareas = elem.getElementsByTagName('textarea');
665                 for(var j=0,len2=elemtextareas.length; j<len2; j++){
666                     // this bit assumes that the only textareas in this context would be for subfields
667                     if (elemtextareas[j].value) {
668                         isempty = false;
669                     }
670                 }
671
672             } else {
673                 isempty = false;
674             }
675
676             if(isempty){
677                 flag = true;
678                 if (mandatory) {
679                     mandatoryFields[ arr[0] ] = {
680                         importance: "mandatory",
681                         elemid: "div_indicator_" + divid,
682                         tab: arr[3]
683                     }
684                 } else {
685                     mandatoryFields[ arr[0] ] = {
686                         importance: "important",
687                         elemid: "div_indicator_" + divid,
688                         tab: arr[3]
689                     }
690                 }
691             }
692
693         }
694
695         if( Object.entries(mandatoryFields).length > 0 ){
696             StrAlert += "<h4>" + _("The following fields aren't filled:") + "</h4>";
697             StrAlert += "<ul>";
698             for( var prop in mandatoryFields ){
699                 if( mandatoryFields[prop]["importance"] == "mandatory" ){
700                     StrAlert += "<li>" + _("Field %s is mandatory, at least one of its subfields must be filled.").format( prop ) + ' <a class="linkfield btn btn-link" href="#" data-tab="' + mandatoryFields[prop]["tab"] + '" data-field="' + mandatoryFields[prop]["elemid"] + '"><i class="fa fa-arrow-right" aria-hidden="true"></i> ' + _("Go to field") + '</a></li>';
701                 } else {
702                     StrAlert += "<li>" + _("Field %s is important, at least one of its subfields must be filled.").format(prop) + ' <a class="linkfield btn btn-link" href="#" data-tab="' + mandatoryFields[prop]["tab"] + '" data-field="' + mandatoryFields[prop]["elemid"] + '"><i class="fa fa-arrow-right" aria-hidden="true"></i> ' + _("Go to field") + '</a></li>';
703                 }
704             }
705             StrAlert += "</ul>";
706         }
707         StrAlert += "</div>";
708         if ( flag ) {
709             $("#show-errors").html('<button type="button" class="btn btn-danger show-errors"><i class="fa fa-warning"></i> ' + _("Errors") + '</span>');
710             return StrAlert;
711         } else {
712             return flag;
713         }
714     }
715
716     /**
717      * Run checks for mandatory and important fields
718      * Output errors if necessary, or submit the form
719      */
720     function Check(){
721         var StrAlert = AreFieldsNotOk();
722         var StrWarning = AreFieldsNotOk( false );
723         if( !StrAlert && StrWarning ){
724             // Check important fields
725             $("#check_errors").html( StrWarning );
726             $('html, body').animate({ scrollTop: 0 }, 'fast');
727
728             var r=confirm( _("Important fields(s) are not filled. Are you sure you want to save?" ) );
729             if (! r){
730                 return false;
731             } else {
732                 document.f.submit();
733                 return true;
734             }
735         } else if( StrAlert ){
736             var strAll = StrAlert;
737             if( StrWarning ){
738                 strAll += StrWarning;
739             }
740             $("#check_errors").html( strAll );
741             $('html, body').animate({ scrollTop: 0 }, 'fast');
742             Sticky.hcSticky('refresh');
743             return false;
744         } else if( !StrAlert && !StrWarning ){
745             document.f.submit();
746             return true;
747         }
748     }
749
750     /**
751      * check if z3950 mandatories are set or not
752      */
753     function GetZ3950Terms(){
754         var frameworkcode = document.getElementById("frameworkcode").value;
755         var strQuery = "&frameworkcode=" + encodeURIComponent(frameworkcode);
756         var mandatories = new Array();
757         var mandatories_label = new Array();
758         [% FOREACH BIG_LOO IN BIG_LOOP %]
759             [% FOREACH innerloo IN BIG_LOO.innerloop %]
760                 [% FOREACH subfield_loo IN innerloo.subfield_loop %]
761                     [% IF ( subfield_loo.z3950_mandatory ) %]
762                         mandatories.push("[% subfield_loo.id | html %]");
763                         mandatories_label.push("[% subfield_loo.z3950_mandatory | html %]");
764                     [% END %]
765                 [% END %]
766             [% END %]
767         [% END %]
768
769         for(var i=0,len=mandatories.length; i<len ; i++){
770             var field_value = document.getElementById(mandatories[i]).value;
771             if( field_value ){
772                 strQuery += "&"+encodeURIComponent(mandatories_label[i])+"="+encodeURIComponent(field_value);
773             }
774         }
775         return strQuery;
776     }
777
778     function Changefwk() {
779         var f = document.f;
780         f.op.value = "[% op | html %]";
781         f.biblionumber.value = "[% biblionumberdata | html %]";
782         f.changed_framework.value = "changed";
783         f.submit();
784     }
785
786     /* Wrap a value in HTML without putting HTML in translatable string */
787     function formatFieldName( string ){
788         return "<strong><em>" + string + "</em></strong>";
789     }
790
791     $(document).ready(function(){
792         $('body').on('click','.expandfield',ExpandField);
793     });
794
795 </script>
796 [% Asset.css("css/addbiblio.css") | $raw %]
797 </head>
798 <body id="cat_addbiblio" class="cat">
799
800    <div id="loading">
801        <div>Loading, please wait...</div>
802    </div>
803
804     [% WRAPPER 'header.inc' %]
805         [% INCLUDE 'cataloging-search.inc' %]
806     [% END %]
807 [% WRAPPER 'sub-header.inc' %]
808     [% WRAPPER breadcrumbs %]
809         [% WRAPPER breadcrumb_item %]
810             <a href="/cgi-bin/koha/cataloguing/cataloging-home.pl">Cataloging</a>
811         [% END %]
812         [% WRAPPER breadcrumb_item bc_active= 1 %]
813             [% IF ( biblionumber ) %]
814                 <span>[% tp('Editing MARC record titled:', "Editing") | html %] [% title | html %] (Record number [% biblionumber | html %])</span>
815             [% ELSE %]
816                 [% IF ( circborrowernumber ) %]
817                     <span>Add MARC record (fast cataloging)</span>
818                 [% ELSE %]
819                     <span>Add MARC record</span>
820                 [% END %]
821             [% END %]
822         [% END %]
823     [% END #/ WRAPPER breadcrumbs %]
824 [% END #/ WRAPPER sub-header.inc %]
825
826     <div class="main container-fluid">
827         <div class="row">
828             <div class="col-md-10 col-md-offset-1">
829
830                 <div id="check_errors"></div>
831
832                 <h1>
833                     [% IF ( biblionumber ) %]
834                         Editing [% title | $HtmlTags tag="em" %] (Record number [% biblionumber | html %])
835                     [% ELSE %]
836                         [% IF (circborrowernumber) %]
837                             <span>Add MARC record (fast cataloging)</span>
838                         [% ELSE %]
839                             <span>Add MARC record</span>
840                         [% END %]
841                     [% END %]
842                 </h1>
843
844                 [% UNLESS ( number ) %]
845                     <!-- show duplicate warning on tab 0 only -->
846                     [% IF ( duplicatebiblionumber ) %]
847                         <div class="dialog alert">
848                             <h3>Duplicate record suspected</h3>
849                             <p>Is this a duplicate of <a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=[% duplicatebiblionumber | uri %]" onclick="openWindow('/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=[% duplicatebiblionumber | uri %]&amp;popup=1', 'DuplicateBiblio','800','600'); return false;">[% duplicatetitle | html %] <i class="fa fa-window-restore"></i></a> ?</p>
850                             [% IF ( CAN_user_editcatalogue_edit_items ) %]
851                                 <form action="/cgi-bin/koha/cataloguing/additem.pl" method="get">
852                                     <input type="hidden" name="biblionumber" value="[% duplicatebiblionumber | html %]" />
853                                     <button type="submit" class="new"><i class="fa fa-fw fa-pencil"></i> Yes, edit existing items</button>
854                                 </form>
855                             [% ELSE %]
856                                 <form action="/cgi-bin/koha/catalogue/detail.pl" method="get">
857                                     <input type="hidden" name="biblionumber" value="[% duplicatebiblionumber | html %]" />
858                                     <input type="submit" value="Yes: View existing items" />
859                                 </form>
860                             [% END %]
861                             <form action="/cgi-bin/koha/cataloguing/addbiblio.pl" method="get">
862                                 [% IF ( CAN_user_editcatalogue_edit_items ) %]
863                                     <button type="submit" class="new" onclick="confirmnotdup('items'); return false;"><i class="fa fa-fw fa-save"></i> No, save as new record</button>
864                                 [% ELSE %]
865                                     <button type="submit" class="new" onclick="confirmnotdup('view'); return false;"><i class="fa fa-fw fa-save"></i> No, save as new record</button>
866                                 [% END %]
867                             </form>
868                         </div> <!-- /.dialog.alert -->
869                     [% END # /IF duplicatebiblionumber %]
870                 [% END # /UNLESS number %]
871
872                 [% IF ( done ) %]
873                     <script>
874                         opener.document.forms['f'].biblionumber.value=[% biblionumber | html %];
875                         opener.document.forms['f'].title.value='[% title | html %]';
876                         window.close();
877                     </script>
878                 [% ELSE %]
879                     <form method="post" name="f" id="f" action="/cgi-bin/koha/cataloguing/addbiblio.pl" onsubmit="return Check();">
880                         <input type="hidden" value="[% IF ( biblionumber ) %]view[% ELSE %]items[% END %]" id="redirect" name="redirect" />
881                         <input type="hidden" value="" id="current_tab" name="current_tab" />
882                         <input type="hidden" value="0" id="confirm_not_duplicate" name="confirm_not_duplicate" />
883                 [% END %]
884
885                 <div id="toolbar" class="btn-toolbar">
886                     [% IF CAN_user_editcatalogue_edit_items or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) %]
887                         [% IF (circborrowernumber) %][%# fast cataloging must lead to items %]
888                             <!-- Action is under fast cataloging - Save button redirecting to items -->
889                             <div class="btn-group"><a href="#" id="saveanditems" class="btn btn-primary"><i class="fa fa-save"></i> Save</a></div>
890                         [% ELSE %]
891                             <!-- Not using fast cataloging - Display split menu -->
892                             <div class="btn-group">
893                                 <button class="btn btn-primary" id="saverecord"><i class="fa fa-save"></i> Save</button>
894                                 <button class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
895                                 <span class="caret"></span>
896                                 </button>
897                                 <ul class="dropdown-menu">
898                                     <li><a id="saveandview" href="#">Save and view record</a></li>
899                                     <li><a id="saveanditems" href="#">Save and edit items</a></li>
900                                     <li><a id="saveandcontinue" href="#">Save and continue editing</a></li>
901                                 </ul>
902                             </div>
903                         [% END %]
904                     [% ELSE %]
905                         <!-- User cannot edit items - single button redirecting to view -->
906                         <div class="btn-group"><a href="#" id="saveandview" class="btn btn-default"><i class="fa fa-save"></i> Save</a></div>
907                     [% END # /IF CAN_user_editcatalogue_edit_items %]
908
909                     [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
910                         [% IF biblionumber %]
911                             <div class="btn-group"><a class="btn btn-default" href="#" id="z3950search"><i class="fa fa-search"></i> Replace record via Z39.50/SRU search</a></div>
912                         [% ELSE %]
913                             <div class="btn-group"><a class="btn btn-default" href="#" id="z3950search"><i class="fa fa-search"></i> Z39.50/SRU search</a></div>
914                         [% END %]
915                         [% IF ( CAN_user_editauthorities ) %]
916                             <div class="btn-group"><a class="btn btn-default" href="#" id="linkerbutton"><i class="fa fa-refresh"></i> Link authorities automatically</a></div>
917                         [% END %]
918                     [% END %]
919
920                     <div class="btn-group">
921                         <button class="btn btn-default dropdown-toggle" data-toggle="dropdown"><i class="fa fa-cog"></i> Settings <span class="caret"></span></button>
922                         <ul id="settings-menu" class="dropdown-menu">
923                             [% IF Koha.Preference( 'EnableAdvancedCatalogingEditor' ) == 1 && CAN_user_editcatalogue_advanced_editor %]
924                                 <li><a href="#" id="switcheditor">Switch to advanced editor</a></li>
925                             [% END %]
926                             [% UNLESS advancedMARCEditor %]
927                                 <li>
928                                     <a href="#" id="marcDocsSelect"><i class="fa fa-check-square-o"></i> Show MARC tag documentation links</a>
929                                 <li>
930                                     <a href="#" id="marcTagsSelect"><i class="fa fa-check-square-o"></i> Show tags</a>
931                                 </li>
932                             [% END %]
933                             <li class="dropdown-header">Change framework</li>
934                             <li>
935                                 <a href="#" class="change-framework" data-frameworkcode="">
936                                     [% IF ( frameworkcode ) %]
937                                        <i class="fa fa-fw">&nbsp;</i>
938                                     [% ELSE %]
939                                         <i class="fa fa-fw fa-check"></i>
940                                     [% END %]
941                                     Default
942                                 </a>
943                             </li>
944                             [% FOREACH framework IN frameworks%]
945                                 <li>
946                                     <a href="#" class="change-framework" data-frameworkcode="[% framework.frameworkcode | html %]">
947                                         [% IF framework.frameworkcode == frameworkcode %]
948                                             <i class="fa fa-fw fa-check"></i>
949                                         [% ELSE %]
950                                             <i class="fa fa-fw">&nbsp;</i>
951                                         [% END %]
952                                         [% framework.frameworktext | html %]
953                                     </a>
954                                 </li>
955                             [% END %]
956                         </ul> <!-- /#settings-menu -->
957                     </div> <!-- /.btn-group -->
958                     [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
959                         [% IF (biblionumber) %]
960                             <div class="btn-group">
961                                 <a href="[% PROCESS biblio_a_href biblionumber => biblionumber %]" class="btn btn-link" id="cancel">Cancel</a>
962                             </div>
963                         [% ELSE %]
964                             <div class="btn-group">
965                                 <a class="btn btn-link" id="cancel" href="/cgi-bin/koha/cataloguing/cataloging-home.pl">Cancel</a>
966                             </div>
967                         [% END %]
968                         <div id="show-errors" class="btn-group"></div>
969                     [% END # /UNLESS circborrowernumber %]
970                     <div class="toolbar-tabs-container">
971                         [% IF ( BIG_LOOP && BIG_LOOP.size > 1 ) %]
972                             [% WRAPPER tabs_nav %]
973                                 [%- FOREACH BIG_LOO IN BIG_LOOP -%]
974                                     [% IF loop.first %]
975                                         [% SET bt_active = 1 %]
976                                     [% ELSE %]
977                                         [% SET bt_active = 0 %]
978                                     [% END %]
979                                     [% WRAPPER tab_item tabname= "tab${BIG_LOO.number}XX" bt_active= bt_active %]
980                                         <span>[% BIG_LOO.number | html %]</span>
981                                     [% END %]
982                                 [%- END -%]
983                             [% END # /WRAPPER tabs_nav %]
984                         [% END %]
985                         <ul class="tag_anchors_list">
986                             [% FOREACH BIG_LOO IN BIG_LOOP %]
987                                 [% IF loop.first %][% SET tab_selected = "tab_selected" %][% ELSE %][% SET tab_selected = "" %][% END %]
988                                 [% FOREACH innerloo IN BIG_LOO.innerloop %]
989                                     [% IF ( innerloo.tag ) %]
990                                         <li class="tag_anchors tag_anchors_[% BIG_LOO.number | html %] [% tab_selected | html %]">
991                                             <a class="tag_anchor" id="tag_anchor_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]" title="tag_anchor_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]" href="#div_indicator_tag_[% innerloo.tag | uri %]_[% innerloo.index | uri %][% innerloo.random | uri %]">[% innerloo.tag | uri %]</a>
992                                         </li>
993                                     [% END %]
994                                 [% END %]
995                             [% END %]
996                         </ul>
997                     </div>
998                 </div> <!-- /#toolbar.btn-toolbar -->
999
1000                 [% IF bib_doesnt_exist %]
1001                     <div class="dialog alert">
1002                         The record you are trying to edit doesn't exist.<br>
1003                         <a href="/cgi-bin/koha/cataloguing/addbiblio.pl?frameworkcode=">Add a new record</a> or <a href="/cgi-bin/koha/catalogue/search.pl">do a catalog search</a>.
1004                     </div>
1005                 [% END %]
1006
1007                 [% IF ( popup ) %]
1008                         <input type="hidden" name="mode" value="popup" />
1009                 [% END %]
1010                 <input type="hidden" name="op" value="addbiblio" />
1011                 <input type="hidden" id="frameworkcode" name="frameworkcode" value="[% frameworkcode | html %]" />
1012                 <input type="hidden" name="z3950" value="[% z3950 | html %]" />
1013                 <input type="hidden" name="biblionumber" value="[% biblionumber | html %]" />
1014                 <input type="hidden" name="breedingid" value="[% breedingid | html %]" />
1015                 <input type="hidden" name="changed_framework" value="" />
1016
1017                 [% WRAPPER tabs id= "addbibliotabs" %]
1018                     [% WRAPPER tab_panels %]
1019                         [% FOREACH BIG_LOO IN BIG_LOOP %]
1020                             [% IF loop.first %]
1021                                 [% SET bt_active = 1 %]
1022                             [% ELSE %]
1023                                 [% SET bt_active = 0 %]
1024                             [% END %]
1025                             [% WRAPPER tab_panel tabname="tab${BIG_LOO.number}XX" bt_active= bt_active %]
1026
1027                                 [% IF ( BIG_LOOP.size > 1 ) %]
1028                                     <h3>Section [% BIG_LOO.number | html %]</h3>
1029                                 [% END %]
1030                                 [% previous = "" %]
1031                                 [% FOREACH innerloo IN BIG_LOO.innerloop %]
1032                                     [% IF ( innerloo.tag ) %]
1033                                     [% IF innerloo.tag != previous %]
1034                                         [% IF previous != "" %]
1035                                             </ul>
1036                                         [% END %]
1037                                         [% previous = innerloo.tag %]
1038                                         [% IF ( innerloo.repeatable ) %]
1039                                             <ul class="sortable_field">
1040                                         [% ELSE %]
1041                                             <ul>
1042                                         [% END %]
1043                                     [% END %]
1044                                         [% IF ( innerloo.repeatable ) %]
1045                                             <li class="tag sortable_tag clearfix" id="tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]">
1046                                         [% ELSE %]
1047                                             <li class="tag clearfix" id="tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]">
1048                                         [% END %]
1049                                             <div class="tag_title" id="div_indicator_tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]">
1050                                                 [% IF advancedMARCEditor %]
1051                                                     <a href="#" tabindex="1" class="tagnum" title="[% innerloo.tag_lib | html %] - Click to expand this tag" data-field_id="tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]">[% innerloo.tag | html %]</a>
1052                                                 [% ELSE %]
1053                                                     <span class="tagnum" title="[% innerloo.tag_lib | html %]">[% innerloo.tag | html %]</span>
1054                                                     <a href="#" class="marcdocs" data-tag="[% innerloo.tag | html %]">&nbsp;?</a>
1055                                                 [% END %]
1056
1057                                                 [% IF ( innerloo.fixedfield ) %]
1058                                                     <input type="text"
1059                                                         tabindex="1"
1060                                                         class="indicator flat"
1061                                                         style="display:none;"
1062                                                         name="tag_[% innerloo.tag | html %]_indicator1_[% innerloo.index | html %][% innerloo.random | html %]"
1063                                                         size="1"
1064                                                         maxlength="1"
1065                                                         value="[% innerloo.indicator1 | html %]" />
1066                                                     <input type="text"
1067                                                         tabindex="1"
1068                                                         class="indicator flat"
1069                                                         style="display:none;"
1070                                                         name="tag_[% innerloo.tag | html %]_indicator2_[% innerloo.index | html %][% innerloo.random | html %]"
1071                                                         size="1"
1072                                                         maxlength="1"
1073                                                         value="[% innerloo.indicator2 | html %]" />
1074                                                 [% ELSE %]
1075                                                     <input type="text"
1076                                                         tabindex="1"
1077                                                         class="indicator flat"
1078                                                         name="tag_[% innerloo.tag | html %]_indicator1_[% innerloo.index | html %][% innerloo.random | html %]"
1079                                                         size="1"
1080                                                         maxlength="1"
1081                                                         value="[% innerloo.indicator1 | html %]" />
1082                                                     <input type="text"
1083                                                         tabindex="1"
1084                                                         class="indicator flat"
1085                                                         name="tag_[% innerloo.tag | html %]_indicator2_[% innerloo.index | html %][% innerloo.random | html %]"
1086                                                         size="1"
1087                                                         maxlength="1"
1088                                                         value="[% innerloo.indicator2 | html %]" />
1089                                                 [% END # /IF innerloo.fixedfield %] -
1090
1091                                                 [% UNLESS advancedMARCEditor %]
1092                                                     <a href="#" tabindex="1" class="expandfield" data-field_id="tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]" title="Click to expand this tag">[% innerloo.tag_lib | html %]</a>
1093                                                 [% END %]
1094
1095                                                 <span class="field_controls">
1096                                                     [% IF ( innerloo.repeatable ) %]
1097                                                         <a href="#" tabindex="1" class="buttonPlus" onclick="CloneField('tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]','0','[% advancedMARCEditor | html %]'); return false;" title="Repeat this tag">
1098                                                             <img src="[% interface | html %]/[% theme | html %]/img/repeat-tag.png" alt="Repeat this tag" />
1099                                                         </a>
1100                                                     [% END %]
1101                                                     <a href="#" tabindex="1" class="buttonMinus" onclick="UnCloneField('tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]'); return false;" title="Delete this tag">
1102                                                         <img src="[% interface | html %]/[% theme | html %]/img/delete-tag.png" alt="Delete this tag" />
1103                                                     </a>
1104                                                 </span> <!-- /.field_controls -->
1105                                             </div> <!-- /div.tag_title -->
1106
1107                                             <ul class="sortable_subfield">
1108                                             [% FOREACH subfield_loo IN innerloo.subfield_loop %]
1109                                                 <!--  One line on the marc editor -->
1110                                                 <li class="subfield_line" style="[% subfield_loo.visibility | html %]" id="subfield[% subfield_loo.tag | html %][% subfield_loo.subfield | html %][% subfield_loo.random | html %]">
1111                                                     <div class="subfieldcode">
1112                                                         <input type="text"
1113                                                                 title="[% subfield_loo.marc_lib | $raw %]"
1114                                                                 style=" [% IF ( subfield_loo.fixedfield ) %]display:none; [% END %]border:0;"
1115                                                                 name="tag_[% subfield_loo.tag | html %]_code_[% subfield_loo.subfield | html %]_[% subfield_loo.index | html %]_[% subfield_loo.index_subfield | html %]"
1116                                                                 value="[% subfield_loo.subfield | html %]"
1117                                                                 size="1"
1118                                                                 maxlength="1"
1119                                                                 class="flat"
1120                                                                 tabindex="0" />
1121                                                     </div>
1122                                                     [% UNLESS advancedMARCEditor %]
1123                                                         [% IF ( subfield_loo.mandatory ) %]
1124                                                             <div class="subfield subfield_mandatory">
1125                                                         [% ELSIF ( subfield_loo.important ) %]
1126                                                             <div class="subfield subfield_important">
1127                                                         [% ELSE %]
1128                                                             <div class="subfield">
1129                                                         [% END %]
1130                                                             [% IF ( subfield_loo.fixedfield ) %]
1131                                                                 <label for="tag_[% subfield_loo.tag | html %]_subfield_[% subfield_loo.subfield | html %]_[% subfield_loo.index | html %]_[% subfield_loo.index_subfield | html %]" style="display:none;" class="labelsubfield">
1132                                                             [% ELSE %]
1133                                                                 <label for="tag_[% subfield_loo.tag | html %]_subfield_[% subfield_loo.subfield | html %]_[% subfield_loo.index | html %]_[% subfield_loo.index_subfield | html %]" class="labelsubfield">
1134                                                             [% END %]
1135                                                             [% subfield_loo.marc_lib | $raw %]
1136                                                             </label>
1137                                                         </div>
1138                                                     [% END %]
1139
1140                                                     [% SET mv = subfield_loo.marc_value %]
1141                                                     <div id="field_marceditor[% subfield_loo.tag | html %][% subfield_loo.subfield | html %][% subfield_loo.random | html %]" class="field_marceditor">
1142                                                         [% IF ( mv.type == 'text' ) %]
1143                                                             [% IF ( mv.readonly == 1 ) %]
1144                                                                 <input type="text" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" value="[%- mv.value | html -%]" class="input_marceditor readonly" tabindex="1" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" readonly="readonly" />
1145                                                             [% ELSE %]
1146                                                                 <input type="text" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" value="[%- mv.value | html -%]" class="input_marceditor" tabindex="1" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" />
1147                                                             [% END %]
1148
1149                                                         [% ELSIF ( mv.type == 'text_complex' ) %]
1150                                                             <input type="text" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" value="[%- mv.value | html -%]" class="input_marceditor framework_plugin" tabindex="1" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" />
1151                                                             [% mv.javascript | $raw %]
1152                                                         [% ELSIF ( mv.type == 'hidden' ) %]
1153                                                             <input tabindex="1" type="hidden" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
1154                                                         [% ELSIF ( mv.type == 'textarea' ) %]
1155                                                             <textarea cols="70" rows="4" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" class="input_marceditor" tabindex="1">[%- mv.value | html -%]</textarea>
1156                                                         [% ELSIF ( mv.type == 'select' ) %]
1157                                                         [% IF mv.category AND CAN_user_parameters_manage_auth_values %]
1158                                                             <select name="[%- mv.name | html -%]" tabindex="1" class="input_marceditor" id="[%- mv.id | html -%]" data-category="[% mv.category | html %]">
1159                                                         [% ELSE %]
1160                                                             <select name="[%- mv.name | html -%]" tabindex="1" class="input_marceditor select2" id="[%- mv.id | html -%]">
1161                                                         [% END %]
1162                                                             [% SET matched = 0 %]
1163                                                             [% FOREACH aval IN mv.values %]
1164                                                                 [% IF aval == mv.default %]
1165                                                                     [% SET matched = 1 %]
1166                                                                 <option value="[%- aval | html -%]" selected="selected">[%- mv.labels.$aval | html -%]</option>
1167                                                                 [% ELSE %]
1168                                                                 <option value="[%- aval | html -%]">[%- mv.labels.$aval | html -%]</option>
1169                                                                 [% END %]
1170
1171                                                             [% END %]
1172                                                             [% UNLESS matched # If the current value is not in the authorised value list %]
1173                                                                 <option value="[%- mv.default | html -%]" selected="selected">[%- mv.default | html -%] (Not an authorised value)</option>
1174                                                             </select>
1175                                                             <span style="float:right;" title="The current value [% mv.default | html %] is not configured for the authorised value category controlling this subfield"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></span>
1176                                                             [% ELSE %]
1177                                                             </select>
1178                                                             [% END %]
1179                                                     [% UNLESS matched # If the current value is not in the authorised list %]
1180                                                     [% END %]
1181                                                         [% END  # /IF (mv.type...) %]
1182                                                     </div>
1183                                                     [% IF ( subfield_loo.mandatory ) %]
1184                                                         <div class="subfield_loop_mandatory">
1185                                                             <span class="required">Required</span>
1186                                                         </div>
1187                                                     [% ELSIF ( subfield_loo.important ) %]
1188                                                         <div class="subfield_loop_mandatory">
1189                                                             <span class="important">Important</span>
1190                                                         </div>
1191                                                     [% END %]
1192                                                     <div class="subfield_controls">
1193                                                         [% IF ( mv.type == 'text' ) %]
1194                                                             [% IF ( mv.authtype ) %]
1195                                                                 <a href="#" class="buttonDot tag_editor" onclick="openAuth(this.parentNode.parentNode.getElementsByTagName('input')[1].id,'[%- mv.authtype | html -%]','biblio'); return false;" tabindex="1" title="Tag editor">Tag editor</a>
1196                                                             [% END %]
1197                                                         [% ELSIF ( mv.type == 'text_complex' ) %]
1198                                                                 [% IF mv.noclick %]
1199                                                                     <span class="buttonDot tag_editor disabled" tabindex="-1" title="Field autofilled by plugin"></span>
1200                                                                 [% ELSE %]
1201                                                                     [% IF mv.plugin == "upload.pl" %]
1202                                                                         <a href="#" id="buttonDot_[% mv.id | html %]" class="tag_editor upload framework_plugin" tabindex="1"><i class="fa fa-upload" aria-hidden="true"></i> Upload</a>
1203                                                                     [% ELSE %]
1204                                                                         <a href="#" id="buttonDot_[% mv.id | html %]" class="buttonDot tag_editor framework_plugin" tabindex="1" title="Tag editor">Tag editor</a>
1205                                                                     [% END %]
1206                                                                 [% END %]
1207                                                             </span>
1208                                                         [% END %]
1209                                                         [% IF ( subfield_loo.repeatable ) %]
1210                                                             <a href="#" class="buttonPlus" tabindex="1" onclick="CloneSubfield('subfield[% subfield_loo.tag | html %][% subfield_loo.subfield | html %][% subfield_loo.random | html %]','[% advancedMARCEditor | html %]'); return false;">
1211                                                                 <img src="[% interface | html %]/[% theme | html %]/img/clone-subfield.png" alt="Clone" title="Clone this subfield" />
1212                                                             </a>
1213                                                             <a href="#" class="buttonMinus" tabindex="1" onclick="UnCloneField('subfield[% subfield_loo.tag | html %][% subfield_loo.subfield | html %][% subfield_loo.random | html %]'); return false;">
1214                                                                 <img src="[% interface | html %]/[% theme | html %]/img/delete-subfield.png" alt="Delete" title="Delete this subfield" />
1215                                                             </a>
1216                                                         [% END %]
1217                                                     </div>
1218                                                 </li> <!-- /.subfield_line -->
1219                                                 <!-- End of the line -->
1220                                             [% END # /FOREACH subfield_loop %]
1221                                             </ul> <!--  /.sortable_subfield -->
1222                                         </li> <!-- /.tag.clearfix -->
1223                                     [% END %]<!-- if innerloo.tag -->
1224                                 [% END # /FOREACH BIG_LOO.innerloop %]
1225                                 </ul> <!--  /.sortable_field -->
1226                             [% END # /tab_panel#tabXXX %]
1227                         [% END # /FOREACH BIG_LOOP %]
1228                     [% END # /WRAPPER tab_panels %]
1229                 [% END # /WRAPPER tabs %]
1230
1231                 [%# Fields for fast cataloging %]
1232                 <input type="hidden" name="barcode" value="[% barcode | html %]" />
1233                 <input type="hidden" name="branch" value="[% branch | html %]" />
1234                 <input type="hidden" name="circborrowernumber" value="[% circborrowernumber | html %]" />
1235                 <input type="hidden" name="stickyduedate" value="[% stickyduedate | html %]" />
1236                 <input type="hidden" name="duedatespec" value="[% duedatespec | html %]" />
1237                 [%# End of fields for fast cataloging %]
1238             </form> <!-- /name=f -->
1239
1240             [% INCLUDE 'modals/cataloguing_create_av.inc' %]
1241
1242         </div> <!-- /.col-md-10.col-md-offset-1 -->
1243     </div> <!-- /.row -->
1244
1245 [% INCLUDE 'intranet-bottom.inc' %]