+ // Make the subfield line visible and update its value
+ tag_subfield_line.show();
+ subfield.val(heading.authid);
+
+ // Add the new status
+ var image = '<i class="fa fa-close no_matching_authority" </i> ';
+ var message = '';
+ var field_class = 'no_matching_authority_field';
+ switch(heading.status) {
+ case 'LOCAL_FOUND':
+ image = '<i class="fa fa-check matching_authority"</i> ';
+ message = _("A matching authority was found in the local database.");
+ field_class = 'matching_authority_field';
+ break;
+ case 'CREATED':
+ image = '<i class="fa fa-check matching_authority"></i> ';
+ message = _("No matching authority found. A new authority was created automatically.");
+ field_class = 'matching_authority_field';
+ break;
+ case 'MULTIPLE_MATCH':
+ message = _("More than one local match found. Possibly a duplicate authority!");
+ break;
+ case 'NONE_FOUND':
+ message = _("No matching authority found.");
+ break;
+ default:
+ message = heading.status;
+ break;
+ }
+
+ subfield[0].classList.add(field_class);
+ tag_subfield_line.find('i').each(function() {
+ this.remove();
+ });
+ tag_subfield_line.append(image);
+
+ // Add the message to the dialog
+ message_dialog_ul.append('<li><strong>' + heading.tag + '</strong> - ' + message + '</li>');
+
+ // Add a link to create a new authority if none was found
+ if(heading.status == 'NONE_FOUND' && tag_subfield_line.find('i').length == 1) {
+ addCreateAuthorityButton(tag_subfield_line, heading , tag_index);
+ }
+ });
+
+ if(message_dialog.find('li').length == 0) {
+ message_dialog_ul.append("<li>" + _("No authority link was changed.") + "</li>");
+ }
+ $('#addbibliotabs').before(message_dialog);
+}
+
+/**
+ * Use an ajax request to automatically find authority links for the current record
+ */
+function AutomaticLinker() {
+ // Show the Loading overlay
+ $("#loading").show();
+
+ // Remove fields that are completely empty
+ $('#f').find('.tag').each(function() {
+ var empty = true;
+ $(this).find('.input_marceditor').each(function() {
+ if($(this).val() != '') {
+ empty = false;
+ return false;
+ }
+ });
+ if(empty) {
+ UnCloneField($(this).attr('id'));
+ }
+ });
+
+ // Get all the form values to post via AJAX
+ var form_data = {};
+ $('#f').find(':input').each(function(){
+ form_data[this.name] = $(this).val();
+ });
+ delete form_data[''];
+
+ // Send the data to automatic_linker.pl
+ $.ajax({
+ url:'/cgi-bin/koha/svc/cataloguing/automatic_linker.pl',
+ type:'post',
+ data: form_data,
+ dataType: 'json',
+ error: function(xhr) {
+ alert("Error : \n" + xhr.responseText);
+ },
+ success: function(json) {
+ switch(json.status) {
+ case 'UNAUTHORIZED':
+ alert(_("Error : You do not have the permissions necessary to use this functionality."));
+ break;
+ case 'OK':
+ updateHeadingLinks(json.links);
+ break;
+ }
+ },
+ complete: function() {
+ $("#loading").hide();
+ }
+ });
+}
+
+
+function PopupMARCFieldDoc(field) {
+ [% IF Koha.Preference('marcfielddocurl') %]
+ var docurl = "[% Koha.Preference('marcfielddocurl').replace('"','"') | html %]";
+ docurl = docurl.replace("{MARC}", "[% marcflavour | html %]");
+ docurl = docurl.replace("{FIELD}", ""+field);
+ docurl = docurl.replace("{LANG}", "[% lang | html %]");
+ window.open(docurl);
+ [% ELSIF ( marcflavour == 'MARC21' ) %]
+ _MARC21FieldDoc(field);
+ [% ELSIF ( marcflavour == 'UNIMARC' ) %]
+ _UNIMARCFieldDoc(field);
+ [% END %]
+}