8635be9de057715a356b66e83703a18167b6c07d
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / authorities / blinddetail-biblio-search.tt
1 [% SET footerjs = 1 %]
2 [% INCLUDE 'doc-head-open.inc' %]
3 <title>Koha &rsaquo; Authority details</title>
4 [% INCLUDE 'doc-head-close.inc' %]
5 </head>
6
7 <body id="auth_blinddetail-biblio-search" class="auth">
8
9     <div class="main container-fluid">
10         <div class="row">
11             <div class="col-md-8 col-md-offset-2">
12
13         <div id="loading"> <img src="[% interface %]/[% theme %]/img/spinner-small.gif" alt="" /> Loading </div>
14
15             </div>
16         </div>
17
18
19 [% MACRO jsinclude BLOCK %]
20     <script type="text/javascript">
21         $(document).ready(function(){
22             [% IF tag_number == 'rancor' %]
23             function RancorReplaceField( new_text ){
24                 var cur_field = opener.opener.jQuery(".CodeMirror")[0].CodeMirror.marceditor.getCurrentField();
25                 cur_field.setText(new_text);
26                 return true;
27             }
28                 [% IF ( clear ) %]
29                 var new_line = "";
30                 [% ELSE %]
31                 var new_line = "
32                 [%- FOREACH SUBFIELD_LOO IN SUBFIELD_LOOP -%]‡
33                     [%- SUBFIELD_LOO.marc_subfield |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r    ') -%]
34                     [%- FOREACH marc_value IN SUBFIELD_LOO.marc_values -%]
35                         [%- marc_value |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') -%]
36                     [%- END -%]
37                 [%- END -%]‡9[% authid %]";
38                 [% END %]
39                 RancorReplaceField( new_line );
40             [% ELSE %]
41             var index_start = "[% index %]";
42             var whichfield;
43             try {
44                 whichfield = opener.opener.document.getElementById(index_start);
45             } catch(e) {
46                 return;
47             }
48
49             var field_start = whichfield.parentNode.parentNode;
50
51             // Sets the good number of form fields for the specified subfield
52             // Returns false if the cloning failed
53             function SetSubfieldNumber(subfield_name, nb) {
54                 // Nothing to do if we only have one value
55                 if(nb <= 1) {
56                     return true;
57                 }
58
59                 // Find the subfield we want to clone
60                 var re = new RegExp('^subfield' + subfield_name,'g');
61                 var subfields = $(field_start).children('div').filter( function() {
62                     return this.id.match(re);
63                 });
64
65                 // Try to add as many clones as needed
66                 try {
67                     for(var i=0; i<nb-subfields.length; i++) {
68                         window.opener.opener.CloneSubfield(subfields[0].getAttribute('id'),'[% advancedMARCEditor %]');
69                     }
70                 }
71                 catch(err) {
72                     return false;
73                 }
74                 return true;
75             }
76
77             // Fills the subfield with the values entered in argument
78             function SetSubfieldValues() {
79                 // Get the arguments
80                 var subfield_name = arguments[0];
81                 var values = new Array();
82                 for(var i=1; i<arguments.length; i++) {
83                     values.push(arguments[i]);
84                 }
85
86                 // Create the correct number of form fields for all values
87                 // If the field cloning failed, only the first value will be added to the form.
88                 SetSubfieldNumber(subfield_name, values.length);
89
90                 // Find the subfields where we will add the new values
91                 var re = new RegExp('^subfield' + subfield_name,'g');
92                 var subfields = $(field_start).children('div').filter( function() {
93                     return this.id.match(re);
94                 });
95
96                 // Add the new values to those subfields, empty the additional fields
97                 var i=0;
98                 subfields.each(function() {
99                     if(i in values) {
100                         this.getElementsByTagName('input')[1].value = values[i];
101                     }
102                     else {
103                         this.getElementsByTagName('input')[1].value = "";
104                     }
105                     i++;
106                 });
107             }
108
109             [% UNLESS ( clear ) %]
110                 [% FOREACH SUBFIELD_LOO IN SUBFIELD_LOOP %]
111                     SetSubfieldValues(
112                         "[% tag_number |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %][% SUBFIELD_LOO.marc_subfield |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]"
113                     [% FOREACH marc_value IN SUBFIELD_LOO.marc_values %]
114                         ,"[% marc_value |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]"
115                     [% END %]
116                     );
117                 [% END %]
118             [% END %]
119                 var indicators = field_start.getElementsByClassName('indicator flat');
120                 [% IF update_ind1 %]
121                     indicators[0].value="[% indicator1 %]";
122                 [% END %]
123                 [% IF update_ind2 %]
124                     indicators[1].value="[% indicator2 %]";
125                 [% END %]
126             [% END %]
127
128             // browse all its subfields (clear and $9)
129             var subfields = field_start.getElementsByTagName('input');
130             var re = /^tag_\d*_code_/;
131             for(var i=0, len = subfields.length ; i< len ; i++) { // browse all subfields
132                 if(subfields[i].hasAttribute('name') == 0 ) {continue; }  // div elements specific to Select2
133                 if(subfields[i].getAttribute('name').match(re)){ // it s a subfield
134                     var code     = subfields[i];   // code is the first input
135                     var subfield = subfields[i+1]; // subfield the second
136
137                 [% IF ( clear ) %]
138                     if (subfield){subfield.value="" ;}
139                 [% ELSE %]
140                     if(code.value=='9'){
141                         subfield.value = "[% authid |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]";
142                         break;
143                     }
144                 [% END %]
145                 }
146             }
147             [% END %]
148
149             opener.close();
150             window.close();
151             return false;
152         });
153     </script>
154 [% END %]
155
156 [% INCLUDE 'intranet-bottom.inc' popup_window = 1 %]