Koha/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/blinddetail-biblio-search.tt
Nick Clemens 297529c251 Bug 18904: Advanced editor - Rancor - Add authority support
This patchset adds the ability to use the authorities search to select
or clear fields in the advanced editor

To test:
 1 - Open a record in the advanced cataloging editor
 2 - Press 'Ctrl+L' while in a field that shuold not be linked to
authorities (300 for instance)
 3 - Nothing should happen
 4 - Try it in a field that should be linked
 5 - You should get the authorities pop-up
 6 - Values in pop-up should be populated from values in record (as
        appropriate for authority type)
 7 - Correct authority type should be selected ( PERSO_NAME for 100,
        TOPIC_TERM for 650, etc.)
 8 - Press 'Clear', field should be blanked
 9 - Search again and select an authority
10 - Field should be correctly populated

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2018-04-12 10:50:36 -03:00

156 lines
6.4 KiB
Text

[% SET footerjs = 1 %]
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha &rsaquo; Authority details</title>
[% INCLUDE 'doc-head-close.inc' %]
</head>
<body id="auth_blinddetail-biblio-search" class="auth">
<div class="main container-fluid">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div id="loading"> <img src="[% interface %]/[% theme %]/img/spinner-small.gif" alt="" /> Loading </div>
</div>
</div>
[% MACRO jsinclude BLOCK %]
<script type="text/javascript">
$(document).ready(function(){
[% IF tag_number == 'rancor' %]
function RancorReplaceField( new_text ){
var cur_field = opener.opener.jQuery(".CodeMirror")[0].CodeMirror.marceditor.getCurrentField();
cur_field.setText(new_text);
return true;
}
[% IF ( clear ) %]
var new_line = "";
[% ELSE %]
var new_line = "
[%- FOREACH SUBFIELD_LOO IN SUBFIELD_LOOP -%]‡
[%- SUBFIELD_LOO.marc_subfield |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r ') -%]
[%- FOREACH marc_value IN SUBFIELD_LOO.marc_values -%]
[%- marc_value |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') -%]
[%- END -%]
[%- END -%]‡9[% authid %]";
[% END %]
RancorReplaceField( new_line );
[% ELSE %]
var index_start = "[% index %]";
var whichfield;
try {
whichfield = opener.opener.document.getElementById(index_start);
} catch(e) {
return;
}
var field_start = whichfield.parentNode.parentNode;
// Sets the good number of form fields for the specified subfield
// Returns false if the cloning failed
function SetSubfieldNumber(subfield_name, nb) {
// Nothing to do if we only have one value
if(nb <= 1) {
return true;
}
// Find the subfield we want to clone
var re = new RegExp('^subfield' + subfield_name,'g');
var subfields = $(field_start).children('div').filter( function() {
return this.id.match(re);
});
// Try to add as many clones as needed
try {
for(var i=0; i<nb-subfields.length; i++) {
window.opener.opener.CloneSubfield(subfields[0].getAttribute('id'),'[% advancedMARCEditor %]');
}
}
catch(err) {
return false;
}
return true;
}
// Fills the subfield with the values entered in argument
function SetSubfieldValues() {
// Get the arguments
var subfield_name = arguments[0];
var values = new Array();
for(var i=1; i<arguments.length; i++) {
values.push(arguments[i]);
}
// Create the correct number of form fields for all values
// If the field cloning failed, only the first value will be added to the form.
SetSubfieldNumber(subfield_name, values.length);
// Find the subfields where we will add the new values
var re = new RegExp('^subfield' + subfield_name,'g');
var subfields = $(field_start).children('div').filter( function() {
return this.id.match(re);
});
// Add the new values to those subfields, empty the additional fields
var i=0;
subfields.each(function() {
if(i in values) {
this.getElementsByTagName('input')[1].value = values[i];
}
else {
this.getElementsByTagName('input')[1].value = "";
}
i++;
});
}
[% UNLESS ( clear ) %]
[% FOREACH SUBFIELD_LOO IN SUBFIELD_LOOP %]
SetSubfieldValues(
"[% tag_number |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %][% SUBFIELD_LOO.marc_subfield |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]"
[% FOREACH marc_value IN SUBFIELD_LOO.marc_values %]
,"[% marc_value |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]"
[% END %]
);
[% END %]
[% END %]
var indicators = field_start.getElementsByClassName('indicator flat');
[% IF update_ind1 %]
indicators[0].value="[% indicator1 %]";
[% END %]
[% IF update_ind2 %]
indicators[1].value="[% indicator2 %]";
[% END %]
[% END %]
// browse all its subfields (clear and $9)
var subfields = field_start.getElementsByTagName('input');
var re = /^tag_\d*_code_/;
for(var i=0, len = subfields.length ; i< len ; i++) { // browse all subfields
if(subfields[i].hasAttribute('name') == 0 ) {continue; } // div elements specific to Select2
if(subfields[i].getAttribute('name').match(re)){ // it s a subfield
var code = subfields[i]; // code is the first input
var subfield = subfields[i+1]; // subfield the second
[% IF ( clear ) %]
if (subfield){subfield.value="" ;}
[% ELSE %]
if(code.value=='9'){
subfield.value = "[% authid |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]";
break;
}
[% END %]
}
}
[% END %]
opener.close();
window.close();
return false;
});
</script>
[% END %]
[% INCLUDE 'intranet-bottom.inc' popup_window = 1 %]